Merge remote-tracking branch 'origin/Tests-for-sort-and-cond' into pull-test

# Conflicts:
#	tests/Bootstrap.php
#	tests/methods/ParseTest.php
#	tests/properties/worthless_test.php
This commit is contained in:
Christian Bläul
2018-02-21 18:41:45 +01:00
4 changed files with 141 additions and 5 deletions

View File

@@ -0,0 +1,31 @@
<?php
class BaseClass extends PHPUnit\Framework\TestCase {
/**
* CSV
* The parseCSV object
*
* @access protected
* @var parseCSV
*/
protected $csv;
/**
* Setup
* Setup our test environment objects
*
* @access public
*/
public function setUp() {
$this->csv = new parseCSV();
}
protected function _compareWithExpected($expected) {
$this->csv->auto(__DIR__ . '/../../examples/_books.csv');
$actual = array_map(function ($row) {
return $row['title'];
}, $this->csv->data);
$this->assertEquals($expected, array_values($actual));
}
}

View File

@@ -0,0 +1,47 @@
<?php
class ConditionsTest extends BaseClass {
public function testNotDanBrown() {
$this->csv->conditions = 'author does not contain dan brown';
$this->_compareWithExpected([
'The Killing Kind',
'The Third Secret',
'The Last Templar',
'The Traveller',
'Crisis Four',
'Prey',
'The Broker (Paperback)',
'Without Blood (Paperback)',
'State of Fear (Paperback)',
'The Rule of Four (Paperback)',
]);
}
public function testRating() {
$this->csv->conditions = 'rating < 3';
$this->_compareWithExpected([
'The Killing Kind',
'The Third Secret',
]);
$this->csv->conditions = 'rating >= 5';
$this->_compareWithExpected([
'The Traveller',
'Prey',
'State of Fear (Paperback)',
'Digital Fortress : A Thriller (Mass Market Paperback)',
'Angels & Demons (Mass Market Paperback)',
]);
}
public function testTitleContainsSecretOrCode() {
$this->csv->conditions = 'title contains code OR title contains SECRET';
$this->_compareWithExpected([
'The Third Secret',
'The Da Vinci Code (Hardcover)',
]);
}
}

View File

@@ -0,0 +1,58 @@
<?php
class SortByTest extends BaseClass {
public function testSortByRating() {
$this->csv->sort_by = 'rating';
$this->csv->conditions = 'title does not contain Blood';
$this->_compareWithExpected([
// Rating 0
'The Killing Kind',
'The Third Secret',
// Rating 3
'The Last Templar',
'The Broker (Paperback)',
// Rating 4
'Deception Point (Paperback)',
'The Rule of Four (Paperback)',
'The Da Vinci Code (Hardcover)',
// Rating 5
'State of Fear (Paperback)',
'Prey',
'Digital Fortress : A Thriller (Mass Market Paperback)',
'Angels & Demons (Mass Market Paperback)',
]);
}
public function testReverseSortByRating() {
$this->csv->sort_by = 'rating';
$this->csv->conditions =
'title does not contain Prey AND ' .
'title does not contain Fortress AND ' .
'title does not contain Blood AND ' .
'title does not contain Fear';
$this->csv->sort_reverse = true;
$this->_compareWithExpected([
// Rating 5
'Angels & Demons (Mass Market Paperback)',
'The Traveller',
// Rating 4
'The Da Vinci Code (Hardcover)',
'The Rule of Four (Paperback)',
'Deception Point (Paperback)',
// Rating 3
'The Broker (Paperback)',
'The Last Templar',
// Rating 0
'The Third Secret',
'The Killing Kind',
]);
}
}