From 3be4fce3a51226808b631ff7094dcaf4c2ea57ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Fri, 4 Oct 2013 12:19:34 +0200 Subject: [PATCH 1/6] Add some new tests. re #96 --- test/bookTest.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/bookTest.php b/test/bookTest.php index c439563..562780d 100644 --- a/test/bookTest.php +++ b/test/bookTest.php @@ -83,6 +83,13 @@ class StackTest extends PHPUnit_Framework_TestCase $this->assertEquals (14, count($entryArray)); $this->assertEquals (-1, $totalNumber); } + + public function testGetAllBooks () + { + // All books by first letter + $entryArray = Book::getAllBooks (1, -1); + $this->assertCount (9, $entryArray); + } public function testGetBookById () { @@ -94,7 +101,8 @@ class StackTest extends PHPUnit_Framework_TestCase $this->assertEquals ("Doyle, Arthur Conan", $book->getAuthorsName ()); $this->assertEquals ("Fiction, Mystery & Detective, Short Stories", $book->getTagsName ()); $this->assertEquals ('

The Return of Sherlock Holmes is a collection of 13 Sherlock Holmes stories, originally published in 1903-1904, by Arthur Conan Doyle.
The book was first published on March 7, 1905 by Georges Newnes, Ltd and in a Colonial edition by Longmans. 30,000 copies were made of the initial print run. The US edition by McClure, Phillips & Co. added another 28,000 to the run.
This was the first Holmes collection since 1893, when Holmes had "died" in "The Adventure of the Final Problem". Having published The Hound of the Baskervilles in 1901–1902 (although setting it before Holmes\' death) Doyle came under intense pressure to revive his famous character.

', $book->getComment (false)); - + $this->assertEquals ("English", $book->getLanguages ()); + $this->assertEquals ("", $book->getRating ()); } } \ No newline at end of file From 9c09b8797c0c579273e50690b67ba5d2d7c5032c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Fri, 4 Oct 2013 12:20:34 +0200 Subject: [PATCH 2/6] Add a test for the localize function. re #96 --- base.php | 5 ++++- test/baseTest.php | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/base.php b/base.php index eecd77e..0ec7b2a 100644 --- a/base.php +++ b/base.php @@ -139,7 +139,7 @@ function str_format($format) { * This method is based on this page * http://www.mind-it.info/2010/02/22/a-simple-approach-to-localization-in-php/ */ -function localize($phrase, $count=-1) { +function localize($phrase, $count=-1, $reset=false) { if ($count == 0) $phrase .= ".none"; if ($count == 1) @@ -149,6 +149,9 @@ function localize($phrase, $count=-1) { /* Static keyword is used to ensure the file is loaded only once */ static $translations = NULL; + if ($reset) { + $translations = NULL; + } /* If no instance of $translations has occured load the language file */ if (is_null($translations)) { $lang = "en"; diff --git a/test/baseTest.php b/test/baseTest.php index 2e60c99..7b37b48 100644 --- a/test/baseTest.php +++ b/test/baseTest.php @@ -11,4 +11,27 @@ class BaseTest extends PHPUnit_Framework_TestCase $this->assertEquals ("?key=value&db=0", addURLParameter ("?key=value", "db", "0")); $this->assertEquals ("?key=value&otherKey=&db=0", addURLParameter ("?key=value&otherKey", "db", "0")); } + + public function testLocalize () + { + $this->assertEquals ("Authors", localize ("authors.title")); + } + + public function testLocalizeFr () + { + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3"; + $this->assertEquals ("Auteurs", localize ("authors.title", -1, true)); + + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en"; + localize ("authors.title", -1, true); + } + + public function testLocalizeUnknown () + { + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "aa"; + $this->assertEquals ("Authors", localize ("authors.title", -1, true)); + + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en"; + localize ("authors.title", -1, true); + } } \ No newline at end of file From c0920895ede58cf22c0b22828ddd6210e7154a79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Fri, 4 Oct 2013 12:30:11 +0200 Subject: [PATCH 3/6] Again new tests. re #96 --- test/bookTest.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/bookTest.php b/test/bookTest.php index 562780d..c076ef2 100644 --- a/test/bookTest.php +++ b/test/bookTest.php @@ -87,9 +87,32 @@ class StackTest extends PHPUnit_Framework_TestCase public function testGetAllBooks () { // All books by first letter - $entryArray = Book::getAllBooks (1, -1); + $entryArray = Book::getAllBooks (); $this->assertCount (9, $entryArray); } + + public function testGetBooksByStartingLetter () + { + // All books by first letter + list ($entryArray, $totalNumber) = Book::getBooksByStartingLetter ("T", -1); + $this->assertCount (3, $entryArray); + } + + public function testGetAllRecentBooks () + { + // All recent books + global $config; + + $config['cops_recentbooks_limit'] = 2; + + $entryArray = Book::getAllRecentBooks (); + $this->assertCount (2, $entryArray); + + $config['cops_recentbooks_limit'] = 50; + + $entryArray = Book::getAllRecentBooks (); + $this->assertCount (14, $entryArray); + } public function testGetBookById () { From 0f0fa58c312d93480db21384cc8f912de9d30346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Sat, 12 Oct 2013 07:13:41 +0200 Subject: [PATCH 4/6] Rename the class name. re #96 --- test/bookTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bookTest.php b/test/bookTest.php index c076ef2..7dff03d 100644 --- a/test/bookTest.php +++ b/test/bookTest.php @@ -3,7 +3,7 @@ require_once (dirname(__FILE__) . "/config_test.php"); require_once (dirname(__FILE__) . "/../book.php"); -class StackTest extends PHPUnit_Framework_TestCase +class BookTest extends PHPUnit_Framework_TestCase { public function testGetBookCount () { From 72406214f94fdd8946b9d30a69247ffa95634f20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Sat, 12 Oct 2013 07:56:17 +0200 Subject: [PATCH 5/6] A another test class. re #96 --- test/pageTest.php | 178 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 test/pageTest.php diff --git a/test/pageTest.php b/test/pageTest.php new file mode 100644 index 0000000..8756bb9 --- /dev/null +++ b/test/pageTest.php @@ -0,0 +1,178 @@ +InitializeContent (); + + $this->assertEquals ($config['cops_title_default'], $currentPage->title); + $this->assertCount (6, $currentPage->entryArray); + $this->assertEquals ("Authors", $currentPage->entryArray [0]->title); + $this->assertEquals ("Alphabetical index of the 5 authors", $currentPage->entryArray [0]->content); + $this->assertEquals ("Series", $currentPage->entryArray [1]->title); + $this->assertEquals ("Alphabetical index of the 3 series", $currentPage->entryArray [1]->content); + $this->assertEquals ("Tags", $currentPage->entryArray [2]->title); + $this->assertEquals ("Alphabetical index of the 10 tags", $currentPage->entryArray [2]->content); + $this->assertEquals ("Languages", $currentPage->entryArray [3]->title); + $this->assertEquals ("Alphabetical index of the single language", $currentPage->entryArray [3]->content); + $this->assertEquals ("All books", $currentPage->entryArray [4]->title); + $this->assertEquals ("Alphabetical index of the 14 books", $currentPage->entryArray [4]->content); + $this->assertEquals ("Recent additions", $currentPage->entryArray [5]->title); + $this->assertEquals ("50 most recent books", $currentPage->entryArray [5]->content); + $this->assertFalse ($currentPage->ContainsBook ()); + } + + public function testPageAllAuthors () + { + global $config; + $page = Base::PAGE_ALL_AUTHORS; + $query = NULL; + $search = NULL; + $qid = NULL; + $n = "1"; + $database = NULL; + + $config['cops_author_split_first_letter'] = "0"; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Authors", $currentPage->title); + $this->assertCount (5, $currentPage->entryArray); + $this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + + $config['cops_author_split_first_letter'] = 1; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Authors", $currentPage->title); + $this->assertCount (4, $currentPage->entryArray); + $this->assertEquals ("C", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + } + + public function testPageAuthorsFirstLetter () + { + global $config; + $page = Base::PAGE_AUTHORS_FIRST_LETTER; + $query = NULL; + $search = NULL; + $qid = "C"; + $n = "1"; + $database = NULL; + + // Author Lewis Carroll + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("1 author starting with C", $currentPage->title); + $this->assertCount (1, $currentPage->entryArray); + $this->assertFalse ($currentPage->ContainsBook ()); + } + + public function testPageAuthorsDetail () + { + global $config; + $page = Base::PAGE_AUTHOR_DETAIL; + $query = NULL; + $search = NULL; + $qid = "1"; + $n = "1"; + $database = NULL; + $_SERVER['QUERY_STRING'] = "page=" . Base::PAGE_AUTHOR_DETAIL . "&id=1&n=1"; + + $config['cops_max_item_per_page'] = 2; + + // First page + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Doyle, Arthur Conan", $currentPage->title); + $this->assertEquals (4, $currentPage->getMaxPage ()); + $this->assertCount (2, $currentPage->entryArray); + $this->assertTrue ($currentPage->ContainsBook ()); + $this->assertTrue ($currentPage->IsPaginated ()); + $this->assertNull ($currentPage->getPrevLink ()); + + // Last page + $config['cops_max_item_per_page'] = 5; + $n = "2"; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Doyle, Arthur Conan", $currentPage->title); + $this->assertEquals (2, $currentPage->getMaxPage ()); + $this->assertCount (3, $currentPage->entryArray); + $this->assertTrue ($currentPage->ContainsBook ()); + $this->assertTrue ($currentPage->IsPaginated ()); + $this->assertNull ($currentPage->getNextLink ()); + + // No pagination + $config['cops_max_item_per_page'] = -1; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Doyle, Arthur Conan", $currentPage->title); + $this->assertCount (8, $currentPage->entryArray); + $this->assertTrue ($currentPage->ContainsBook ()); + $this->assertFalse ($currentPage->IsPaginated ()); + } + + public function testPageAllBooks () + { + global $config; + $page = Base::PAGE_ALL_BOOKS; + $query = NULL; + $search = NULL; + $qid = NULL; + $n = "1"; + $database = NULL; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("All books", $currentPage->title); + $this->assertCount (9, $currentPage->entryArray); + $this->assertEquals ("A", $currentPage->entryArray [0]->title); + $this->assertEquals ("C", $currentPage->entryArray [1]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + } + + public function testPageAllBooksByLetter () + { + global $config; + $page = Base::PAGE_ALL_BOOKS_LETTER; + $query = NULL; + $search = NULL; + $qid = "C"; + $n = "1"; + $database = NULL; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("2 books starting with C", $currentPage->title); + $this->assertCount (2, $currentPage->entryArray); + $this->assertEquals ("The Call of the Wild", $currentPage->entryArray [0]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + } + +} \ No newline at end of file From 1c2bb4ede381cc47e38475163d5f98fd3d259fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Sat, 12 Oct 2013 08:19:18 +0200 Subject: [PATCH 6/6] Add series pages. re #96 --- test/pageTest.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/pageTest.php b/test/pageTest.php index 8756bb9..5fd7ddf 100644 --- a/test/pageTest.php +++ b/test/pageTest.php @@ -175,4 +175,42 @@ class PageTest extends PHPUnit_Framework_TestCase $this->assertTrue ($currentPage->ContainsBook ()); } + public function testPageAllSeries () + { + global $config; + $page = Base::PAGE_ALL_SERIES; + $query = NULL; + $search = NULL; + $qid = NULL; + $n = "1"; + $database = NULL; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Series", $currentPage->title); + $this->assertCount (3, $currentPage->entryArray); + $this->assertEquals ("D'Artagnan Romances", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + } + + public function testPageSeriesDetail () + { + global $config; + $page = Base::PAGE_SERIE_DETAIL; + $query = NULL; + $search = NULL; + $qid = "1"; + $n = "1"; + $database = NULL; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Sherlock Holmes", $currentPage->title); + $this->assertCount (7, $currentPage->entryArray); + $this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [0]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + } + } \ No newline at end of file