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 () 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 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; 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