From 9f5f00e1142130adab45e792273f10f0fc2eeb90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Thu, 5 Dec 2013 10:50:53 +0100 Subject: [PATCH] Replace CRLF by LF --- getJSON.php | 46 +- sendtomail.php | 138 ++-- test/bookTest.php | 554 +++++++------- test/coverage-checker.php | 84 +-- test/pageMultidatabaseTest.php | 124 ++-- test/pageTest.php | 1236 ++++++++++++++++---------------- 6 files changed, 1091 insertions(+), 1091 deletions(-) diff --git a/getJSON.php b/getJSON.php index e3974bb..5b8f69f 100644 --- a/getJSON.php +++ b/getJSON.php @@ -1,23 +1,23 @@ - - * - */ - - require_once ("config.php"); - require_once ("base.php"); - require_once ("author.php"); - require_once ("serie.php"); - require_once ("tag.php"); - require_once ("language.php"); - require_once ("customcolumn.php"); - require_once ("book.php"); - - header ("Content-Type:application/json;charset=utf-8"); - - - echo json_encode (getJson ()); - + + * + */ + + require_once ("config.php"); + require_once ("base.php"); + require_once ("author.php"); + require_once ("serie.php"); + require_once ("tag.php"); + require_once ("language.php"); + require_once ("customcolumn.php"); + require_once ("book.php"); + + header ("Content-Type:application/json;charset=utf-8"); + + + echo json_encode (getJson ()); + diff --git a/sendtomail.php b/sendtomail.php index 632752a..690c20a 100644 --- a/sendtomail.php +++ b/sendtomail.php @@ -1,69 +1,69 @@ -getDataById ($idData); - -if (filesize ($data->getLocalPath ()) > 10 * 1024 * 1024) { - echo 'Attachement too big'; - exit; -} - -$mail = new PHPMailer; - -$mail->IsSMTP(); -$mail->Timeout = 30; // 30 seconds as some files can be big -$mail->Host = $config['cops_mail_configuration']["smtp.host"]; -if (!empty ($config['cops_mail_configuration']["smtp.secure"])) { - $mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"]; - $mail->Port = 465; -} -$mail->SMTPAuth = !empty ($config['cops_mail_configuration']["smtp.username"]); -if (!empty ($config['cops_mail_configuration']["smtp.username"])) $mail->Username = $config['cops_mail_configuration']["smtp.username"]; -if (!empty ($config['cops_mail_configuration']["smtp.password"])) $mail->Password = $config['cops_mail_configuration']["smtp.password"]; -if (!empty ($config['cops_mail_configuration']["smtp.secure"])) $mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"]; - -$mail->From = $config['cops_mail_configuration']["address.from"]; -$mail->FromName = $config['cops_title_default']; - -foreach (explode (";", $emailDest) as $emailAddress) { - if (empty ($emailAddress)) { continue; } - $mail->AddAddress($emailAddress); -} - -$mail->AddAttachment($data->getLocalPath ()); - -$mail->IsHTML(false); -$mail->Subject = 'Sent by COPS'; -$mail->Body = 'Sent by COPS'; - -if(!$mail->Send()) { - echo localize ("mail.messagenotsent"); - echo 'Mailer Error: ' . $mail->ErrorInfo; - exit; -} - -echo localize ("mail.messagesent"); - +getDataById ($idData); + +if (filesize ($data->getLocalPath ()) > 10 * 1024 * 1024) { + echo 'Attachement too big'; + exit; +} + +$mail = new PHPMailer; + +$mail->IsSMTP(); +$mail->Timeout = 30; // 30 seconds as some files can be big +$mail->Host = $config['cops_mail_configuration']["smtp.host"]; +if (!empty ($config['cops_mail_configuration']["smtp.secure"])) { + $mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"]; + $mail->Port = 465; +} +$mail->SMTPAuth = !empty ($config['cops_mail_configuration']["smtp.username"]); +if (!empty ($config['cops_mail_configuration']["smtp.username"])) $mail->Username = $config['cops_mail_configuration']["smtp.username"]; +if (!empty ($config['cops_mail_configuration']["smtp.password"])) $mail->Password = $config['cops_mail_configuration']["smtp.password"]; +if (!empty ($config['cops_mail_configuration']["smtp.secure"])) $mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"]; + +$mail->From = $config['cops_mail_configuration']["address.from"]; +$mail->FromName = $config['cops_title_default']; + +foreach (explode (";", $emailDest) as $emailAddress) { + if (empty ($emailAddress)) { continue; } + $mail->AddAddress($emailAddress); +} + +$mail->AddAttachment($data->getLocalPath ()); + +$mail->IsHTML(false); +$mail->Subject = 'Sent by COPS'; +$mail->Body = 'Sent by COPS'; + +if(!$mail->Send()) { + echo localize ("mail.messagenotsent"); + echo 'Mailer Error: ' . $mail->ErrorInfo; + exit; +} + +echo localize ("mail.messagesent"); + diff --git a/test/bookTest.php b/test/bookTest.php index 5ffc3b1..a817a2f 100644 --- a/test/bookTest.php +++ b/test/bookTest.php @@ -1,278 +1,278 @@ - - */ - -require_once (dirname(__FILE__) . "/config_test.php"); -require_once (dirname(__FILE__) . "/../book.php"); - -/* -Publishers: -id:2 (2 books) Macmillan and Co. London: Lewis Caroll -id:3 (2 books) D. Appleton and Company Alexander Dumas -id:4 (1 book) Macmillan Publishers USA: Jack London -id:5 (1 book) Pierson's Magazine: H. G. Wells -id:6 (8 books) Strand Magazine: Arthur Conan Doyle -*/ - -class BookTest extends PHPUnit_Framework_TestCase -{ - public function testGetBookCount () - { - $this->assertEquals (14, Book::getBookCount ()); - } - - public function testGetCount () - { - $entryArray = Book::getCount (); - $this->assertEquals (2, count($entryArray)); - - $entryAllBooks = $entryArray [0]; - $this->assertEquals ("Alphabetical index of the 14 books", $entryAllBooks->content); - - $entryRecentBooks = $entryArray [1]; - $this->assertEquals ("50 most recent books", $entryRecentBooks->content); - - } - - public function testGetCountRecent () - { - global $config; - $config['cops_recentbooks_limit'] = 0; - $entryArray = Book::getCount (); - - $this->assertEquals (1, count($entryArray)); - - $config['cops_recentbooks_limit'] = 2; - $entryArray = Book::getCount (); - - $entryRecentBooks = $entryArray [1]; - $this->assertEquals ("2 most recent books", $entryRecentBooks->content); - - $config['cops_recentbooks_limit'] = 50; - } - - public function testGetBooksByAuthor () - { - // All book by Arthur Conan Doyle - global $config; - - $config['cops_max_item_per_page'] = 5; - list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 1); - $this->assertEquals (5, count($entryArray)); - $this->assertEquals (8, $totalNumber); - - list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 2); - $this->assertEquals (3, count($entryArray)); - $this->assertEquals (8, $totalNumber); - - $config['cops_max_item_per_page'] = -1; - list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, -1); - $this->assertEquals (8, count($entryArray)); - $this->assertEquals (-1, $totalNumber); - } - - public function testGetBooksBySeries () - { - // All book from the Sherlock Holmes series - list ($entryArray, $totalNumber) = Book::getBooksBySeries (1, -1); - $this->assertEquals (7, count($entryArray)); - $this->assertEquals (-1, $totalNumber); - } - - public function testGetBooksByPublisher () - { - // All books from Strand Magazine - list ($entryArray, $totalNumber) = Book::getBooksByPublisher (6, -1); - $this->assertEquals (8, count($entryArray)); - $this->assertEquals (-1, $totalNumber); - } - - public function testGetBooksByTag () - { - // All book with the Fiction tag - list ($entryArray, $totalNumber) = Book::getBooksByTag (1, -1); - $this->assertEquals (14, count($entryArray)); - $this->assertEquals (-1, $totalNumber); - } - - public function testGetBooksByLanguage () - { - // All english book (= all books) - list ($entryArray, $totalNumber) = Book::getBooksByLanguage (1, -1); - $this->assertEquals (14, count($entryArray)); - $this->assertEquals (-1, $totalNumber); - } - - public function testGetAllBooks () - { - // All books by first letter - $entryArray = Book::getAllBooks (); - $this->assertCount (9, $entryArray); - } - - public function testGetBooksByStartingLetter () - { - // All books by first letter - list ($entryArray, $totalNumber) = Book::getBooksByStartingLetter ("T", -1); - $this->assertEquals (-1, $totalNumber); - $this->assertCount (3, $entryArray); - } - - public function testGetBookByDataId () - { - $book = Book::getBookByDataId (17); - - $this->assertEquals ("Alice's Adventures in Wonderland", $book->getTitle ()); - } - - 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 () - { - // also check most of book's class methods - $book = Book::getBookById(2); - $this->assertEquals ("The Return of Sherlock Holmes", $book->getTitle ()); - $this->assertEquals ("urn:uuid:87ddbdeb-1e27-4d06-b79b-4b2a3bfc6a5f", $book->getEntryId ()); - $this->assertEquals ("index.php?page=13&id=2", $book->getDetailUrl ()); - $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 ()); - $book->rating = 8; - // 4 filled stars and one empty - $this->assertEquals ("★★★★☆", $book->getRating ()); - $this->assertEquals ("Strand Magazine", $book->getPublisher()->name); - } - - public function testGetMostInterestingDataToSendToKindle () - { - // Get Alice (available as MOBI, PDF, EPUB in that order) - $book = Book::getBookById(17); - $data = $book->GetMostInterestingDataToSendToKindle (); - $this->assertEquals ("MOBI", $data->format); - array_shift ($book->datas); - $data = $book->GetMostInterestingDataToSendToKindle (); - $this->assertEquals ("PDF", $data->format); - array_shift ($book->datas); - $data = $book->GetMostInterestingDataToSendToKindle (); - $this->assertEquals ("EPUB", $data->format); - } - - public function testGetDataById () - { - global $config; - - // Get Alice MOBI=>17, PDF=>19, EPUB=>20 - $book = Book::getBookById(17); - $data = $book->getDataById (17); - $this->assertEquals ("MOBI", $data->format); - $data = $book->getDataById (20); - $this->assertEquals ("EPUB", $data->format); - $this->assertEquals ("Carroll, Lewis - Alice's Adventures in Wonderland.epub", $data->getUpdatedFilenameEpub ()); - $this->assertEquals ("Carroll, Lewis - Alice's Adventures in Wonderland.kepub.epub", $data->getUpdatedFilenameKepub ()); - $this->assertEquals (dirname(__FILE__) . "/BaseWithSomeBooks/Lewis Carroll/Alice's Adventures in Wonderland (17)/Alice's Adventures in Wonderland - Lewis Carroll.epub", $data->getLocalPath ()); - - $config['cops_use_url_rewriting'] = "1"; - $config['cops_provide_kepub'] = "1"; - $_SERVER["HTTP_USER_AGENT"] = "Kobo"; - $this->assertEquals ("download/20/Carroll%2C+Lewis+-+Alice%27s+Adventures+in+Wonderland.kepub.epub", $data->getHtmlLink ()); - $_SERVER["HTTP_USER_AGENT"] = "Firefox"; - $this->assertEquals ("download/20/Alice%27s+Adventures+in+Wonderland+-+Lewis+Carroll.epub", $data->getHtmlLink ()); - $config['cops_use_url_rewriting'] = "0"; - $this->assertEquals ("fetch.php?data=20&type=epub&id=17", $data->getHtmlLink ()); - } - - 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"] = "Macmillan"; - $_GET["search"] = "1"; - - $array = getJson (); - - $this->assertCount (3, $array); - $this->assertEquals ("2 publishers", $array[0]["title"]); - $this->assertEquals ("Macmillan and Co. London", $array[1]["title"]); - $this->assertEquals ("Macmillan Publishers USA", $array[2]["title"]); - - $_GET["query"] = NULL; - $_GET["search"] = NULL; - } - - public function testTypeaheadSearchMultiDatabase () - { - global $config; - $_GET["query"] = "art"; - $_GET["search"] = "1"; - $_GET["multi"] = "1"; - - $config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/", - "One book" => dirname(__FILE__) . "/BaseWithOneBook/"); - - $array = getJson (); - - $this->assertCount (4, $array); - $this->assertEquals ("Some books", $array[0]["title"]); - $this->assertEquals ("No book", $array[1]["title"]); - $this->assertEquals ("One book", $array[2]["title"]); - $this->assertEquals ("1 book", $array[3]["title"]); - - $_GET["query"] = NULL; - $_GET["search"] = NULL; - } - - public function tearDown () { - Base::clearDb (); - } - + + */ + +require_once (dirname(__FILE__) . "/config_test.php"); +require_once (dirname(__FILE__) . "/../book.php"); + +/* +Publishers: +id:2 (2 books) Macmillan and Co. London: Lewis Caroll +id:3 (2 books) D. Appleton and Company Alexander Dumas +id:4 (1 book) Macmillan Publishers USA: Jack London +id:5 (1 book) Pierson's Magazine: H. G. Wells +id:6 (8 books) Strand Magazine: Arthur Conan Doyle +*/ + +class BookTest extends PHPUnit_Framework_TestCase +{ + public function testGetBookCount () + { + $this->assertEquals (14, Book::getBookCount ()); + } + + public function testGetCount () + { + $entryArray = Book::getCount (); + $this->assertEquals (2, count($entryArray)); + + $entryAllBooks = $entryArray [0]; + $this->assertEquals ("Alphabetical index of the 14 books", $entryAllBooks->content); + + $entryRecentBooks = $entryArray [1]; + $this->assertEquals ("50 most recent books", $entryRecentBooks->content); + + } + + public function testGetCountRecent () + { + global $config; + $config['cops_recentbooks_limit'] = 0; + $entryArray = Book::getCount (); + + $this->assertEquals (1, count($entryArray)); + + $config['cops_recentbooks_limit'] = 2; + $entryArray = Book::getCount (); + + $entryRecentBooks = $entryArray [1]; + $this->assertEquals ("2 most recent books", $entryRecentBooks->content); + + $config['cops_recentbooks_limit'] = 50; + } + + public function testGetBooksByAuthor () + { + // All book by Arthur Conan Doyle + global $config; + + $config['cops_max_item_per_page'] = 5; + list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 1); + $this->assertEquals (5, count($entryArray)); + $this->assertEquals (8, $totalNumber); + + list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 2); + $this->assertEquals (3, count($entryArray)); + $this->assertEquals (8, $totalNumber); + + $config['cops_max_item_per_page'] = -1; + list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, -1); + $this->assertEquals (8, count($entryArray)); + $this->assertEquals (-1, $totalNumber); + } + + public function testGetBooksBySeries () + { + // All book from the Sherlock Holmes series + list ($entryArray, $totalNumber) = Book::getBooksBySeries (1, -1); + $this->assertEquals (7, count($entryArray)); + $this->assertEquals (-1, $totalNumber); + } + + public function testGetBooksByPublisher () + { + // All books from Strand Magazine + list ($entryArray, $totalNumber) = Book::getBooksByPublisher (6, -1); + $this->assertEquals (8, count($entryArray)); + $this->assertEquals (-1, $totalNumber); + } + + public function testGetBooksByTag () + { + // All book with the Fiction tag + list ($entryArray, $totalNumber) = Book::getBooksByTag (1, -1); + $this->assertEquals (14, count($entryArray)); + $this->assertEquals (-1, $totalNumber); + } + + public function testGetBooksByLanguage () + { + // All english book (= all books) + list ($entryArray, $totalNumber) = Book::getBooksByLanguage (1, -1); + $this->assertEquals (14, count($entryArray)); + $this->assertEquals (-1, $totalNumber); + } + + public function testGetAllBooks () + { + // All books by first letter + $entryArray = Book::getAllBooks (); + $this->assertCount (9, $entryArray); + } + + public function testGetBooksByStartingLetter () + { + // All books by first letter + list ($entryArray, $totalNumber) = Book::getBooksByStartingLetter ("T", -1); + $this->assertEquals (-1, $totalNumber); + $this->assertCount (3, $entryArray); + } + + public function testGetBookByDataId () + { + $book = Book::getBookByDataId (17); + + $this->assertEquals ("Alice's Adventures in Wonderland", $book->getTitle ()); + } + + 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 () + { + // also check most of book's class methods + $book = Book::getBookById(2); + $this->assertEquals ("The Return of Sherlock Holmes", $book->getTitle ()); + $this->assertEquals ("urn:uuid:87ddbdeb-1e27-4d06-b79b-4b2a3bfc6a5f", $book->getEntryId ()); + $this->assertEquals ("index.php?page=13&id=2", $book->getDetailUrl ()); + $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 ()); + $book->rating = 8; + // 4 filled stars and one empty + $this->assertEquals ("★★★★☆", $book->getRating ()); + $this->assertEquals ("Strand Magazine", $book->getPublisher()->name); + } + + public function testGetMostInterestingDataToSendToKindle () + { + // Get Alice (available as MOBI, PDF, EPUB in that order) + $book = Book::getBookById(17); + $data = $book->GetMostInterestingDataToSendToKindle (); + $this->assertEquals ("MOBI", $data->format); + array_shift ($book->datas); + $data = $book->GetMostInterestingDataToSendToKindle (); + $this->assertEquals ("PDF", $data->format); + array_shift ($book->datas); + $data = $book->GetMostInterestingDataToSendToKindle (); + $this->assertEquals ("EPUB", $data->format); + } + + public function testGetDataById () + { + global $config; + + // Get Alice MOBI=>17, PDF=>19, EPUB=>20 + $book = Book::getBookById(17); + $data = $book->getDataById (17); + $this->assertEquals ("MOBI", $data->format); + $data = $book->getDataById (20); + $this->assertEquals ("EPUB", $data->format); + $this->assertEquals ("Carroll, Lewis - Alice's Adventures in Wonderland.epub", $data->getUpdatedFilenameEpub ()); + $this->assertEquals ("Carroll, Lewis - Alice's Adventures in Wonderland.kepub.epub", $data->getUpdatedFilenameKepub ()); + $this->assertEquals (dirname(__FILE__) . "/BaseWithSomeBooks/Lewis Carroll/Alice's Adventures in Wonderland (17)/Alice's Adventures in Wonderland - Lewis Carroll.epub", $data->getLocalPath ()); + + $config['cops_use_url_rewriting'] = "1"; + $config['cops_provide_kepub'] = "1"; + $_SERVER["HTTP_USER_AGENT"] = "Kobo"; + $this->assertEquals ("download/20/Carroll%2C+Lewis+-+Alice%27s+Adventures+in+Wonderland.kepub.epub", $data->getHtmlLink ()); + $_SERVER["HTTP_USER_AGENT"] = "Firefox"; + $this->assertEquals ("download/20/Alice%27s+Adventures+in+Wonderland+-+Lewis+Carroll.epub", $data->getHtmlLink ()); + $config['cops_use_url_rewriting'] = "0"; + $this->assertEquals ("fetch.php?data=20&type=epub&id=17", $data->getHtmlLink ()); + } + + 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"] = "Macmillan"; + $_GET["search"] = "1"; + + $array = getJson (); + + $this->assertCount (3, $array); + $this->assertEquals ("2 publishers", $array[0]["title"]); + $this->assertEquals ("Macmillan and Co. London", $array[1]["title"]); + $this->assertEquals ("Macmillan Publishers USA", $array[2]["title"]); + + $_GET["query"] = NULL; + $_GET["search"] = NULL; + } + + public function testTypeaheadSearchMultiDatabase () + { + global $config; + $_GET["query"] = "art"; + $_GET["search"] = "1"; + $_GET["multi"] = "1"; + + $config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/", + "One book" => dirname(__FILE__) . "/BaseWithOneBook/"); + + $array = getJson (); + + $this->assertCount (4, $array); + $this->assertEquals ("Some books", $array[0]["title"]); + $this->assertEquals ("No book", $array[1]["title"]); + $this->assertEquals ("One book", $array[2]["title"]); + $this->assertEquals ("1 book", $array[3]["title"]); + + $_GET["query"] = NULL; + $_GET["search"] = NULL; + } + + public function tearDown () { + Base::clearDb (); + } + } \ No newline at end of file diff --git a/test/coverage-checker.php b/test/coverage-checker.php index 2ac147f..e228ed9 100644 --- a/test/coverage-checker.php +++ b/test/coverage-checker.php @@ -1,42 +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; + +* +* @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/pageMultidatabaseTest.php b/test/pageMultidatabaseTest.php index 1094892..0988e3f 100644 --- a/test/pageMultidatabaseTest.php +++ b/test/pageMultidatabaseTest.php @@ -1,62 +1,62 @@ - - */ - -require_once (dirname(__FILE__) . "/config_test.php"); -require_once (dirname(__FILE__) . "/../book.php"); - -class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase -{ - public function testPageIndex () - { - global $config; - $config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/", - "One book" => dirname(__FILE__) . "/BaseWithOneBook/"); - $page = Base::PAGE_INDEX; - $query = NULL; - $qid = NULL; - $n = "1"; - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ($config['cops_title_default'], $currentPage->title); - $this->assertCount (2, $currentPage->entryArray); - $this->assertEquals ("Some books", $currentPage->entryArray [0]->title); - $this->assertEquals ("14 books", $currentPage->entryArray [0]->content); - $this->assertEquals ("One book", $currentPage->entryArray [1]->title); - $this->assertEquals ("1 book", $currentPage->entryArray [1]->content); - $this->assertFalse ($currentPage->ContainsBook ()); - } - - public function testPageSearchXXX () - { - global $config; - $config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/", - "One book" => dirname(__FILE__) . "/BaseWithOneBook/"); - $page = Base::PAGE_OPENSEARCH_QUERY; - $query = "art"; - $qid = NULL; - $n = "1"; - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("Search result for *art*", $currentPage->title); - $this->assertCount (2, $currentPage->entryArray); - $this->assertEquals ("Some books", $currentPage->entryArray [0]->title); - $this->assertEquals ("10 books", $currentPage->entryArray [0]->content); - $this->assertEquals ("One book", $currentPage->entryArray [1]->title); - $this->assertEquals ("1 book", $currentPage->entryArray [1]->content); - $this->assertFalse ($currentPage->ContainsBook ()); - } - - public static function tearDownAfterClass () { - Base::clearDb (); - } - -} + + */ + +require_once (dirname(__FILE__) . "/config_test.php"); +require_once (dirname(__FILE__) . "/../book.php"); + +class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase +{ + public function testPageIndex () + { + global $config; + $config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/", + "One book" => dirname(__FILE__) . "/BaseWithOneBook/"); + $page = Base::PAGE_INDEX; + $query = NULL; + $qid = NULL; + $n = "1"; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ($config['cops_title_default'], $currentPage->title); + $this->assertCount (2, $currentPage->entryArray); + $this->assertEquals ("Some books", $currentPage->entryArray [0]->title); + $this->assertEquals ("14 books", $currentPage->entryArray [0]->content); + $this->assertEquals ("One book", $currentPage->entryArray [1]->title); + $this->assertEquals ("1 book", $currentPage->entryArray [1]->content); + $this->assertFalse ($currentPage->ContainsBook ()); + } + + public function testPageSearchXXX () + { + global $config; + $config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/", + "One book" => dirname(__FILE__) . "/BaseWithOneBook/"); + $page = Base::PAGE_OPENSEARCH_QUERY; + $query = "art"; + $qid = NULL; + $n = "1"; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *art*", $currentPage->title); + $this->assertCount (2, $currentPage->entryArray); + $this->assertEquals ("Some books", $currentPage->entryArray [0]->title); + $this->assertEquals ("10 books", $currentPage->entryArray [0]->content); + $this->assertEquals ("One book", $currentPage->entryArray [1]->title); + $this->assertEquals ("1 book", $currentPage->entryArray [1]->content); + $this->assertFalse ($currentPage->ContainsBook ()); + } + + public static function tearDownAfterClass () { + Base::clearDb (); + } + +} diff --git a/test/pageTest.php b/test/pageTest.php index b993df8..4d6a58b 100644 --- a/test/pageTest.php +++ b/test/pageTest.php @@ -1,619 +1,619 @@ - - */ - -require_once (dirname(__FILE__) . "/config_test.php"); -require_once (dirname(__FILE__) . "/../book.php"); - -class PageTest extends PHPUnit_Framework_TestCase -{ - public function testPageIndex () - { - global $config; - $page = Base::PAGE_INDEX; - $query = NULL; - $qid = NULL; - $n = "1"; - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ($config['cops_title_default'], $currentPage->title); - $this->assertCount (7, $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 ("Publishers", $currentPage->entryArray [2]->title); - $this->assertEquals ("Alphabetical index of the 5 publishers", $currentPage->entryArray [2]->content); - $this->assertEquals ("Tags", $currentPage->entryArray [3]->title); - $this->assertEquals ("Alphabetical index of the 10 tags", $currentPage->entryArray [3]->content); - $this->assertEquals ("Languages", $currentPage->entryArray [4]->title); - $this->assertEquals ("Alphabetical index of the single language", $currentPage->entryArray [4]->content); - $this->assertEquals ("All books", $currentPage->entryArray [5]->title); - $this->assertEquals ("Alphabetical index of the 14 books", $currentPage->entryArray [5]->content); - $this->assertEquals ("Recent additions", $currentPage->entryArray [6]->title); - $this->assertEquals ("50 most recent books", $currentPage->entryArray [6]->content); - $this->assertFalse ($currentPage->ContainsBook ()); - } - - public function testPageIndexWithCustomColumn () - { - global $config; - $page = Base::PAGE_INDEX; - $query = NULL; - $qid = NULL; - $n = "1"; - - $config['cops_calibre_custom_column'] = array ("type1"); - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertCount (8, $currentPage->entryArray); - $this->assertEquals ("Type1", $currentPage->entryArray [5]->title); - $this->assertEquals ("Alphabetical index of the 2 tags", $currentPage->entryArray [5]->content); - - $config['cops_calibre_custom_column'] = array ("type2"); - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertCount (8, $currentPage->entryArray); - $this->assertEquals ("Type2", $currentPage->entryArray [5]->title); - $this->assertEquals ("Alphabetical index of the 3 tags", $currentPage->entryArray [5]->content); - - $config['cops_calibre_custom_column'] = array ("type4"); - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertCount (8, $currentPage->entryArray); - $this->assertEquals ("Type4", $currentPage->entryArray [5]->title); - $this->assertEquals ("Alphabetical index of the 2 tags", $currentPage->entryArray [5]->content); - - $config['cops_calibre_custom_column'] = array ("type1", "type2", "type4"); - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertCount (10, $currentPage->entryArray); - - $config['cops_calibre_custom_column'] = array (); - } - - public function testPageAllCustom () - { - $page = Base::PAGE_ALL_CUSTOMS; - $query = NULL; - $qid = NULL; - $n = "1"; - - $_GET ["custom"] = "1"; - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("Type4", $currentPage->title); - $this->assertCount (2, $currentPage->entryArray); - $this->assertEquals ("SeriesLike", $currentPage->entryArray [0]->title); - $this->assertFalse ($currentPage->ContainsBook ()); - - $_GET ["custom"] = "2"; - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("Type2", $currentPage->title); - $this->assertCount (3, $currentPage->entryArray); - $this->assertEquals ("tag1", $currentPage->entryArray [0]->title); - $this->assertFalse ($currentPage->ContainsBook ()); - - $_GET ["custom"] = "3"; - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("Type1", $currentPage->title); - $this->assertCount (2, $currentPage->entryArray); - $this->assertEquals ("other", $currentPage->entryArray [0]->title); - $this->assertFalse ($currentPage->ContainsBook ()); - - $_GET ["custom"] = NULL; - } - - public function testPageCustomDetail () - { - $page = Base::PAGE_CUSTOM_DETAIL; - $query = NULL; - $qid = "1"; - $n = "1"; - - $_GET ["custom"] = "1"; - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("SeriesLike", $currentPage->title); - $this->assertCount (2, $currentPage->entryArray); - $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); - $this->assertTrue ($currentPage->ContainsBook ()); - - $_GET ["custom"] = "2"; - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("tag1", $currentPage->title); - $this->assertCount (2, $currentPage->entryArray); - $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); - $this->assertTrue ($currentPage->ContainsBook ()); - - $_GET ["custom"] = "3"; - $qid = "2"; - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("other", $currentPage->title); - $this->assertCount (1, $currentPage->entryArray); - $this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [0]->title); - $this->assertTrue ($currentPage->ContainsBook ()); - - $_GET ["custom"] = NULL; - } - - public function testPageAllAuthors () - { - global $config; - $page = Base::PAGE_ALL_AUTHORS; - $query = NULL; - $qid = NULL; - $n = "1"; - - $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 () - { - $page = Base::PAGE_AUTHORS_FIRST_LETTER; - $query = NULL; - $qid = "C"; - $n = "1"; - - // 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; - $qid = "1"; - $n = "1"; - $_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; - $qid = NULL; - $n = "1"; - - $config['cops_titles_split_first_letter'] = 0; - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("All books", $currentPage->title); - $this->assertCount (14, $currentPage->entryArray); - $this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title); - $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [1]->title); - $this->assertTrue ($currentPage->ContainsBook ()); - - $config['cops_titles_split_first_letter'] = 1; - - $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 () - { - $page = Base::PAGE_ALL_BOOKS_LETTER; - $query = NULL; - $qid = "C"; - $n = "1"; - - $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 ()); - } - - public function testPageAllSeries () - { - $page = Base::PAGE_ALL_SERIES; - $query = NULL; - $qid = NULL; - $n = "1"; - - $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 () - { - $page = Base::PAGE_SERIE_DETAIL; - $query = NULL; - $qid = "1"; - $n = "1"; - $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 ()); - } - - public function testPageAllPublishers () - { - $page = Base::PAGE_ALL_PUBLISHERS; - $query = NULL; - $qid = NULL; - $n = "1"; - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("Publishers", $currentPage->title); - $this->assertCount (5, $currentPage->entryArray); - $this->assertEquals ("D. Appleton and Company", $currentPage->entryArray [0]->title); - $this->assertFalse ($currentPage->ContainsBook ()); - } - - public function testPagePublishersDetail () - { - $page = Base::PAGE_PUBLISHER_DETAIL; - $query = NULL; - $qid = "6"; - $n = "1"; - - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("Strand Magazine", $currentPage->title); - $this->assertCount (8, $currentPage->entryArray); - $this->assertEquals ("The Return of Sherlock Holmes", $currentPage->entryArray [0]->title); - $this->assertTrue ($currentPage->ContainsBook ()); - } - - - public function testPageAllTags () - { - $page = Base::PAGE_ALL_TAGS; - $query = NULL; - $qid = NULL; - $n = "1"; - - $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 () - { - $page = Base::PAGE_TAG_DETAIL; - $query = NULL; - $qid = "1"; - $n = "1"; - - $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 () - { - $page = Base::PAGE_ALL_LANGUAGES; - $query = NULL; - $qid = NULL; - $n = "1"; - - $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 () - { - $page = Base::PAGE_LANGUAGE_DETAIL; - $query = NULL; - $qid = "1"; - $n = "1"; - - $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 () - { - $page = Base::PAGE_ALL_RECENT_BOOKS; - $query = NULL; - $qid = NULL; - $n = "1"; - - $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 () - { - $page = Base::PAGE_BOOK_DETAIL; - $query = NULL; - $qid = "2"; - $n = "1"; - - $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 ()); - } - - public function testPageSearch () - { - $page = Base::PAGE_OPENSEARCH_QUERY; - $query = "alice"; - $qid = NULL; - $n = "1"; - - // Only books returned - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("Search result for *alice*", $currentPage->title); - $this->assertCount (2, $currentPage->entryArray); - $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); - $this->assertEquals ("Through the Looking Glass (And What Alice Found There)", $currentPage->entryArray [1]->title); - $this->assertTrue ($currentPage->ContainsBook ()); - - // Match Lewis Caroll & Scarlet - $query = "car"; - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("Search result for *car*", $currentPage->title); - $this->assertCount (3, $currentPage->entryArray); - $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); - $this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [1]->title); - $this->assertEquals ("Through the Looking Glass (And What Alice Found There)", $currentPage->entryArray [2]->title); - $this->assertTrue ($currentPage->ContainsBook ()); - } - - public function testPageSearchScopeAuthors () - { - $page = Base::PAGE_OPENSEARCH_QUERY; - $qid = NULL; - $n = "1"; - $_GET ["scope"] = "author"; - - // Match Lewis Carroll - $query = "car"; - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("Search result for *car* in authors", $currentPage->title); - $this->assertCount (1, $currentPage->entryArray); - $this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title); - $this->assertFalse ($currentPage->ContainsBook ()); - - $_GET ["scope"] = NULL; - } - - public function testPageSearchScopeSeries () - { - $page = Base::PAGE_OPENSEARCH_QUERY; - $qid = NULL; - $n = "1"; - $_GET ["scope"] = "series"; - - // Match Holmes - $query = "hol"; - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("Search result for *hol* in series", $currentPage->title); - $this->assertCount (1, $currentPage->entryArray); - $this->assertEquals ("Sherlock Holmes", $currentPage->entryArray [0]->title); - $this->assertFalse ($currentPage->ContainsBook ()); - - $_GET ["scope"] = NULL; - } - - public function testPageSearchScopeBooks () - { - $page = Base::PAGE_OPENSEARCH_QUERY; - $qid = NULL; - $n = "1"; - $_GET ["scope"] = "book"; - - // Match Holmes - $query = "hol"; - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("Search result for *hol* in books", $currentPage->title); - $this->assertCount (4, $currentPage->entryArray); - $this->assertTrue ($currentPage->ContainsBook ()); - - $_GET ["scope"] = NULL; - } - - public function testPageSearchScopePublishers () - { - $page = Base::PAGE_OPENSEARCH_QUERY; - $qid = NULL; - $n = "1"; - $_GET ["scope"] = "publisher"; - - // Match Holmes - $query = "millan"; - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("Search result for *millan* in publishers", $currentPage->title); - $this->assertCount (2, $currentPage->entryArray); - $this->assertEquals ("Macmillan and Co. London", $currentPage->entryArray [0]->title); - $this->assertFalse ($currentPage->ContainsBook ()); - - $_GET ["scope"] = NULL; - } - - public function testPageSearchScopeTags () - { - $page = Base::PAGE_OPENSEARCH_QUERY; - $qid = NULL; - $n = "1"; - $_GET ["scope"] = "tag"; - - // Match Holmes - $query = "fic"; - $currentPage = Page::getPage ($page, $qid, $query, $n); - $currentPage->InitializeContent (); - - $this->assertEquals ("Search result for *fic* in tags", $currentPage->title); - $this->assertCount (2, $currentPage->entryArray); - $this->assertFalse ($currentPage->ContainsBook ()); - - $_GET ["scope"] = NULL; - } + + */ + +require_once (dirname(__FILE__) . "/config_test.php"); +require_once (dirname(__FILE__) . "/../book.php"); + +class PageTest extends PHPUnit_Framework_TestCase +{ + public function testPageIndex () + { + global $config; + $page = Base::PAGE_INDEX; + $query = NULL; + $qid = NULL; + $n = "1"; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ($config['cops_title_default'], $currentPage->title); + $this->assertCount (7, $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 ("Publishers", $currentPage->entryArray [2]->title); + $this->assertEquals ("Alphabetical index of the 5 publishers", $currentPage->entryArray [2]->content); + $this->assertEquals ("Tags", $currentPage->entryArray [3]->title); + $this->assertEquals ("Alphabetical index of the 10 tags", $currentPage->entryArray [3]->content); + $this->assertEquals ("Languages", $currentPage->entryArray [4]->title); + $this->assertEquals ("Alphabetical index of the single language", $currentPage->entryArray [4]->content); + $this->assertEquals ("All books", $currentPage->entryArray [5]->title); + $this->assertEquals ("Alphabetical index of the 14 books", $currentPage->entryArray [5]->content); + $this->assertEquals ("Recent additions", $currentPage->entryArray [6]->title); + $this->assertEquals ("50 most recent books", $currentPage->entryArray [6]->content); + $this->assertFalse ($currentPage->ContainsBook ()); + } + + public function testPageIndexWithCustomColumn () + { + global $config; + $page = Base::PAGE_INDEX; + $query = NULL; + $qid = NULL; + $n = "1"; + + $config['cops_calibre_custom_column'] = array ("type1"); + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertCount (8, $currentPage->entryArray); + $this->assertEquals ("Type1", $currentPage->entryArray [5]->title); + $this->assertEquals ("Alphabetical index of the 2 tags", $currentPage->entryArray [5]->content); + + $config['cops_calibre_custom_column'] = array ("type2"); + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertCount (8, $currentPage->entryArray); + $this->assertEquals ("Type2", $currentPage->entryArray [5]->title); + $this->assertEquals ("Alphabetical index of the 3 tags", $currentPage->entryArray [5]->content); + + $config['cops_calibre_custom_column'] = array ("type4"); + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertCount (8, $currentPage->entryArray); + $this->assertEquals ("Type4", $currentPage->entryArray [5]->title); + $this->assertEquals ("Alphabetical index of the 2 tags", $currentPage->entryArray [5]->content); + + $config['cops_calibre_custom_column'] = array ("type1", "type2", "type4"); + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertCount (10, $currentPage->entryArray); + + $config['cops_calibre_custom_column'] = array (); + } + + public function testPageAllCustom () + { + $page = Base::PAGE_ALL_CUSTOMS; + $query = NULL; + $qid = NULL; + $n = "1"; + + $_GET ["custom"] = "1"; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Type4", $currentPage->title); + $this->assertCount (2, $currentPage->entryArray); + $this->assertEquals ("SeriesLike", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + + $_GET ["custom"] = "2"; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Type2", $currentPage->title); + $this->assertCount (3, $currentPage->entryArray); + $this->assertEquals ("tag1", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + + $_GET ["custom"] = "3"; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Type1", $currentPage->title); + $this->assertCount (2, $currentPage->entryArray); + $this->assertEquals ("other", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + + $_GET ["custom"] = NULL; + } + + public function testPageCustomDetail () + { + $page = Base::PAGE_CUSTOM_DETAIL; + $query = NULL; + $qid = "1"; + $n = "1"; + + $_GET ["custom"] = "1"; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("SeriesLike", $currentPage->title); + $this->assertCount (2, $currentPage->entryArray); + $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + + $_GET ["custom"] = "2"; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("tag1", $currentPage->title); + $this->assertCount (2, $currentPage->entryArray); + $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + + $_GET ["custom"] = "3"; + $qid = "2"; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("other", $currentPage->title); + $this->assertCount (1, $currentPage->entryArray); + $this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [0]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + + $_GET ["custom"] = NULL; + } + + public function testPageAllAuthors () + { + global $config; + $page = Base::PAGE_ALL_AUTHORS; + $query = NULL; + $qid = NULL; + $n = "1"; + + $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 () + { + $page = Base::PAGE_AUTHORS_FIRST_LETTER; + $query = NULL; + $qid = "C"; + $n = "1"; + + // 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; + $qid = "1"; + $n = "1"; + $_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; + $qid = NULL; + $n = "1"; + + $config['cops_titles_split_first_letter'] = 0; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("All books", $currentPage->title); + $this->assertCount (14, $currentPage->entryArray); + $this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title); + $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [1]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + + $config['cops_titles_split_first_letter'] = 1; + + $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 () + { + $page = Base::PAGE_ALL_BOOKS_LETTER; + $query = NULL; + $qid = "C"; + $n = "1"; + + $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 ()); + } + + public function testPageAllSeries () + { + $page = Base::PAGE_ALL_SERIES; + $query = NULL; + $qid = NULL; + $n = "1"; + + $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 () + { + $page = Base::PAGE_SERIE_DETAIL; + $query = NULL; + $qid = "1"; + $n = "1"; + $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 ()); + } + + public function testPageAllPublishers () + { + $page = Base::PAGE_ALL_PUBLISHERS; + $query = NULL; + $qid = NULL; + $n = "1"; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Publishers", $currentPage->title); + $this->assertCount (5, $currentPage->entryArray); + $this->assertEquals ("D. Appleton and Company", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + } + + public function testPagePublishersDetail () + { + $page = Base::PAGE_PUBLISHER_DETAIL; + $query = NULL; + $qid = "6"; + $n = "1"; + + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Strand Magazine", $currentPage->title); + $this->assertCount (8, $currentPage->entryArray); + $this->assertEquals ("The Return of Sherlock Holmes", $currentPage->entryArray [0]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + } + + + public function testPageAllTags () + { + $page = Base::PAGE_ALL_TAGS; + $query = NULL; + $qid = NULL; + $n = "1"; + + $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 () + { + $page = Base::PAGE_TAG_DETAIL; + $query = NULL; + $qid = "1"; + $n = "1"; + + $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 () + { + $page = Base::PAGE_ALL_LANGUAGES; + $query = NULL; + $qid = NULL; + $n = "1"; + + $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 () + { + $page = Base::PAGE_LANGUAGE_DETAIL; + $query = NULL; + $qid = "1"; + $n = "1"; + + $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 () + { + $page = Base::PAGE_ALL_RECENT_BOOKS; + $query = NULL; + $qid = NULL; + $n = "1"; + + $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 () + { + $page = Base::PAGE_BOOK_DETAIL; + $query = NULL; + $qid = "2"; + $n = "1"; + + $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 ()); + } + + public function testPageSearch () + { + $page = Base::PAGE_OPENSEARCH_QUERY; + $query = "alice"; + $qid = NULL; + $n = "1"; + + // Only books returned + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *alice*", $currentPage->title); + $this->assertCount (2, $currentPage->entryArray); + $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); + $this->assertEquals ("Through the Looking Glass (And What Alice Found There)", $currentPage->entryArray [1]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + + // Match Lewis Caroll & Scarlet + $query = "car"; + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *car*", $currentPage->title); + $this->assertCount (3, $currentPage->entryArray); + $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); + $this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [1]->title); + $this->assertEquals ("Through the Looking Glass (And What Alice Found There)", $currentPage->entryArray [2]->title); + $this->assertTrue ($currentPage->ContainsBook ()); + } + + public function testPageSearchScopeAuthors () + { + $page = Base::PAGE_OPENSEARCH_QUERY; + $qid = NULL; + $n = "1"; + $_GET ["scope"] = "author"; + + // Match Lewis Carroll + $query = "car"; + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *car* in authors", $currentPage->title); + $this->assertCount (1, $currentPage->entryArray); + $this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + + $_GET ["scope"] = NULL; + } + + public function testPageSearchScopeSeries () + { + $page = Base::PAGE_OPENSEARCH_QUERY; + $qid = NULL; + $n = "1"; + $_GET ["scope"] = "series"; + + // Match Holmes + $query = "hol"; + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *hol* in series", $currentPage->title); + $this->assertCount (1, $currentPage->entryArray); + $this->assertEquals ("Sherlock Holmes", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + + $_GET ["scope"] = NULL; + } + + public function testPageSearchScopeBooks () + { + $page = Base::PAGE_OPENSEARCH_QUERY; + $qid = NULL; + $n = "1"; + $_GET ["scope"] = "book"; + + // Match Holmes + $query = "hol"; + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *hol* in books", $currentPage->title); + $this->assertCount (4, $currentPage->entryArray); + $this->assertTrue ($currentPage->ContainsBook ()); + + $_GET ["scope"] = NULL; + } + + public function testPageSearchScopePublishers () + { + $page = Base::PAGE_OPENSEARCH_QUERY; + $qid = NULL; + $n = "1"; + $_GET ["scope"] = "publisher"; + + // Match Holmes + $query = "millan"; + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *millan* in publishers", $currentPage->title); + $this->assertCount (2, $currentPage->entryArray); + $this->assertEquals ("Macmillan and Co. London", $currentPage->entryArray [0]->title); + $this->assertFalse ($currentPage->ContainsBook ()); + + $_GET ["scope"] = NULL; + } + + public function testPageSearchScopeTags () + { + $page = Base::PAGE_OPENSEARCH_QUERY; + $qid = NULL; + $n = "1"; + $_GET ["scope"] = "tag"; + + // Match Holmes + $query = "fic"; + $currentPage = Page::getPage ($page, $qid, $query, $n); + $currentPage->InitializeContent (); + + $this->assertEquals ("Search result for *fic* in tags", $currentPage->title); + $this->assertCount (2, $currentPage->entryArray); + $this->assertFalse ($currentPage->ContainsBook ()); + + $_GET ["scope"] = NULL; + } } \ No newline at end of file