From 01f0891cfb22265b984b028f5674f05176f1fb0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Bl=C3=A4ul?= Date: Sun, 21 Jan 2018 22:08:39 +0100 Subject: [PATCH] Test some conditions --- tests/methods/ConditionsTest.php | 74 ++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/methods/ConditionsTest.php diff --git a/tests/methods/ConditionsTest.php b/tests/methods/ConditionsTest.php new file mode 100644 index 0000000..245721f --- /dev/null +++ b/tests/methods/ConditionsTest.php @@ -0,0 +1,74 @@ +csv = new parseCSV(); + } + + 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)', + ]); + } + + 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, $actual); + } +}