From 75f13fe3de1415d0f9ed4572901559bdcfc39758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Tue, 15 Oct 2013 08:15:10 +0200 Subject: [PATCH 1/4] Add new tests. re #96 --HG-- extra : rebase_source : 2b11d4badf9e567c7f29500c75b7ccc7c0cf07a7 --- test/pageTest.php | 135 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/test/pageTest.php b/test/pageTest.php index 5fd7ddf..6854fe0 100644 --- a/test/pageTest.php +++ b/test/pageTest.php @@ -212,5 +212,140 @@ class PageTest extends PHPUnit_Framework_TestCase $this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [0]->title); $this->assertTrue ($currentPage->ContainsBook ()); } + + public function testPageAllTags () + { + global $config; + $page = Base::PAGE_ALL_TAGS; + $query = NULL; + $search = NULL; + $qid = NULL; + $n = "1"; + $database = NULL; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Tags", $currentPage->title); + $this->assertCount (10, $currentPage->entryArray); + $this->assertEquals ("Action & Adventure", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + } + + public function testPageTagDetail () + { + global $config; + $page = Base::PAGE_TAG_DETAIL; + $query = NULL; + $search = NULL; + $qid = "1"; + $n = "1"; + $database = NULL; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Fiction", $currentPage->title); + $this->assertCount (14, $currentPage->entryArray); + $this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + } + + public function testPageAllLanguages () + { + global $config; + $page = Base::PAGE_ALL_LANGUAGES; + $query = NULL; + $search = NULL; + $qid = NULL; + $n = "1"; + $database = NULL; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Languages", $currentPage->title); + $this->assertCount (1, $currentPage->entryArray); + $this->assertEquals ("English", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + } + + public function testPageLanguageDetail () + { + global $config; + $page = Base::PAGE_LANGUAGE_DETAIL; + $query = NULL; + $search = NULL; + $qid = "1"; + $n = "1"; + $database = NULL; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("English", $currentPage->title); + $this->assertCount (14, $currentPage->entryArray); + $this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + } + + public function testPageRecent () + { + global $config; + $page = Base::PAGE_ALL_RECENT_BOOKS; + $query = NULL; + $search = NULL; + $qid = NULL; + $n = "1"; + $database = NULL; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Recent additions", $currentPage->title); + $this->assertCount (14, $currentPage->entryArray); + $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + + // Test facets + + $_GET["tag"] = "Historical"; + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Recent additions", $currentPage->title); + $this->assertCount (2, $currentPage->entryArray); + $this->assertEquals ("Twenty Years After", $currentPage->entryArray [0]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + + $_GET["tag"] = "!Romance"; + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Recent additions", $currentPage->title); + $this->assertCount (12, $currentPage->entryArray); + $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + + $_GET["tag"] = NULL; + } + + public function testPageBookDetail () + { + global $config; + $page = Base::PAGE_BOOK_DETAIL; + $query = NULL; + $search = NULL; + $qid = "2"; + $n = "1"; + $database = NULL; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("The Return of Sherlock Holmes", $currentPage->title); + $this->assertCount (0, $currentPage->entryArray); + $this->assertFalse ($currentPage->ContainsBook ()); + } } \ No newline at end of file From 9b592b863d005c3e76360ef9a465be75f776e6c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Tue, 15 Oct 2013 08:20:01 +0200 Subject: [PATCH 2/4] Add a coverage checked in PHP. re #96 --HG-- extra : rebase_source : a02ab0e4de3b813f3f81c1af799a293497019954 --- test/coverage-checker.php | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/coverage-checker.php diff --git a/test/coverage-checker.php b/test/coverage-checker.php new file mode 100644 index 0000000..2ac147f --- /dev/null +++ b/test/coverage-checker.php @@ -0,0 +1,42 @@ + +* +* @author Marco Pivetta +* @see http://ocramius.github.io/blog/automated-code-coverage-check-for-github-pull-requests-with-travis/ +*/ + +$inputFile = $argv[1]; +$percentage = min(100, max(0, (int) $argv[2])); + +if (!file_exists($inputFile)) { + throw new InvalidArgumentException('Invalid input file provided'); +} + +if (!$percentage) { + throw new InvalidArgumentException('An integer checked percentage must be given as second parameter'); +} + +$xml = new SimpleXMLElement(file_get_contents($inputFile)); +$metrics = $xml->xpath('//metrics'); +$totalElements = 0; +$checkedElements = 0; + +foreach ($metrics as $metric) { + $totalElements += (int) $metric['elements']; + $checkedElements += (int) $metric['coveredelements']; +} + +$coverage = ($checkedElements / $totalElements) * 100; + +if ($coverage < $percentage) { + echo 'Code coverage is ' . $coverage . '%, which is below the accepted ' . $percentage . '%' . PHP_EOL; + exit(1); +} + +echo 'Code coverage is ' . $coverage . '% - OK!' . PHP_EOL; From 504b717fb8f73753a49294385a67d9da1cc2f04e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Tue, 15 Oct 2013 08:31:12 +0200 Subject: [PATCH 3/4] Add a case where the translation string is not found. re #96 --- test/baseTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/baseTest.php b/test/baseTest.php index 7b37b48..ca6480f 100644 --- a/test/baseTest.php +++ b/test/baseTest.php @@ -15,6 +15,8 @@ class BaseTest extends PHPUnit_Framework_TestCase public function testLocalize () { $this->assertEquals ("Authors", localize ("authors.title")); + + $this->assertEquals ("unknow.key", localize ("unknow.key")); } public function testLocalizeFr () From fc80875d342359739bb40e60ca4fb55f8abee59b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Tue, 15 Oct 2013 08:31:26 +0200 Subject: [PATCH 4/4] Test typeahead search. re #96 --- test/bookTest.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/bookTest.php b/test/bookTest.php index 7dff03d..45986ad 100644 --- a/test/bookTest.php +++ b/test/bookTest.php @@ -128,4 +128,42 @@ class BookTest extends PHPUnit_Framework_TestCase $this->assertEquals ("", $book->getRating ()); } + public function testTypeaheadSearch () + { + $_GET["query"] = "fic"; + $_GET["search"] = "1"; + + $array = getJson (); + + $this->assertCount (3, $array); + $this->assertEquals ("2 tags", $array[0]["title"]); + $this->assertEquals ("Fiction", $array[1]["title"]); + $this->assertEquals ("Science Fiction", $array[2]["title"]); + + $_GET["query"] = "car"; + $_GET["search"] = "1"; + + $array = getJson (); + + $this->assertCount (4, $array); + $this->assertEquals ("1 book", $array[0]["title"]); + $this->assertEquals ("A Study in Scarlet", $array[1]["title"]); + $this->assertEquals ("1 author", $array[2]["title"]); + $this->assertEquals ("Carroll, Lewis", $array[3]["title"]); + + $_GET["query"] = "art"; + $_GET["search"] = "1"; + + $array = getJson (); + + $this->assertCount (4, $array); + $this->assertEquals ("1 author", $array[0]["title"]); + $this->assertEquals ("Doyle, Arthur Conan", $array[1]["title"]); + $this->assertEquals ("1 series", $array[2]["title"]); + $this->assertEquals ("D'Artagnan Romances", $array[3]["title"]); + + $_GET["query"] = NULL; + $_GET["search"] = NULL; + } + } \ No newline at end of file