cops/test/pageTest.php

763 lines
27 KiB
PHP
Raw Normal View History

2013-12-05 11:50:53 +02:00
<?php
/**
* COPS (Calibre OPDS PHP Server) test file
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Sébastien Lucas <sebastien@slucas.fr>
*/
require_once (dirname(__FILE__) . "/config_test.php");
require_once (dirname(__FILE__) . "/../book.php");
class PageTest extends PHPUnit_Framework_TestCase
2013-12-05 11:52:51 +02:00
{
2013-12-05 11:50:53 +02:00
public function testPageIndex ()
{
global $config;
$page = Base::PAGE_INDEX;
$query = NULL;
$qid = NULL;
$n = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ($config['cops_title_default'], $currentPage->title);
2014-02-27 12:44:11 +02:00
$this->assertCount (8, $currentPage->entryArray);
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Authors", $currentPage->entryArray [0]->title);
$this->assertEquals ("Alphabetical index of the 6 authors", $currentPage->entryArray [0]->content);
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Series", $currentPage->entryArray [1]->title);
$this->assertEquals ("Alphabetical index of the 4 series", $currentPage->entryArray [1]->content);
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Publishers", $currentPage->entryArray [2]->title);
$this->assertEquals ("Alphabetical index of the 6 publishers", $currentPage->entryArray [2]->content);
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Tags", $currentPage->entryArray [3]->title);
$this->assertEquals ("Alphabetical index of the 11 tags", $currentPage->entryArray [3]->content);
2014-03-20 20:55:10 +02:00
$this->assertEquals ("Ratings", $currentPage->entryArray [4]->title);
$this->assertEquals ("3 ratings", $currentPage->entryArray [4]->content);
2014-02-27 20:37:28 +02:00
$this->assertEquals ("Languages", $currentPage->entryArray [5]->title);
$this->assertEquals ("Alphabetical index of the 2 languages", $currentPage->entryArray [5]->content);
2014-02-27 20:37:28 +02:00
$this->assertEquals ("All books", $currentPage->entryArray [6]->title);
$this->assertEquals ("Alphabetical index of the 15 books", $currentPage->entryArray [6]->content);
2014-02-27 20:37:28 +02:00
$this->assertEquals ("Recent additions", $currentPage->entryArray [7]->title);
$this->assertEquals ("50 most recent books", $currentPage->entryArray [7]->content);
2013-12-05 11:50:53 +02:00
$this->assertFalse ($currentPage->ContainsBook ());
}
2013-12-05 11:52:51 +02:00
public function testPageIndexWithIgnored ()
{
global $config;
$page = Base::PAGE_INDEX;
$query = NULL;
$qid = NULL;
$n = "1";
2014-03-10 14:43:55 +02:00
$config ['cops_ignored_categories'] = array ("author", "series", "tag", "publisher", "language");
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->assertEquals ($config['cops_title_default'], $currentPage->title);
2014-02-27 12:44:11 +02:00
$this->assertCount (3, $currentPage->entryArray);
2014-03-20 20:55:10 +02:00
$this->assertEquals ("Ratings", $currentPage->entryArray [0]->title);
2014-02-27 20:37:28 +02:00
$this->assertEquals ("All books", $currentPage->entryArray [1]->title);
$this->assertEquals ("Alphabetical index of the 15 books", $currentPage->entryArray [1]->content);
2014-02-27 20:37:28 +02:00
$this->assertEquals ("Recent additions", $currentPage->entryArray [2]->title);
$this->assertEquals ("50 most recent books", $currentPage->entryArray [2]->content);
$this->assertFalse ($currentPage->ContainsBook ());
}
2014-03-10 14:43:55 +02:00
2013-12-05 11:50:53 +02:00
public function testPageIndexWithCustomColumn ()
{
global $config;
$page = Base::PAGE_INDEX;
$query = NULL;
$qid = NULL;
$n = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$config['cops_calibre_custom_column'] = array ("type1");
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2014-02-27 12:44:11 +02:00
$this->assertCount (9, $currentPage->entryArray);
2014-02-27 20:37:28 +02:00
$this->assertEquals ("Type1", $currentPage->entryArray [6]->title);
$this->assertEquals ("Alphabetical index of the 2 tags", $currentPage->entryArray [6]->content);
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$config['cops_calibre_custom_column'] = array ("type2");
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2014-02-27 12:44:11 +02:00
$this->assertCount (9, $currentPage->entryArray);
2014-02-27 20:37:28 +02:00
$this->assertEquals ("Type2", $currentPage->entryArray [6]->title);
$this->assertEquals ("Alphabetical index of the 3 tags", $currentPage->entryArray [6]->content);
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$config['cops_calibre_custom_column'] = array ("type4");
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2014-02-27 12:44:11 +02:00
$this->assertCount (9, $currentPage->entryArray);
2014-02-27 20:37:28 +02:00
$this->assertEquals ("Type4", $currentPage->entryArray [6]->title);
$this->assertEquals ("Alphabetical index of the 2 tags", $currentPage->entryArray [6]->content);
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$config['cops_calibre_custom_column'] = array ("type1", "type2", "type4");
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2014-02-27 12:44:11 +02:00
$this->assertCount (11, $currentPage->entryArray);
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$config['cops_calibre_custom_column'] = array ();
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
public function testPageAllCustom ()
{
$page = Base::PAGE_ALL_CUSTOMS;
$query = NULL;
$qid = NULL;
$n = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$_GET ["custom"] = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Type4", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("SeriesLike", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ());
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$_GET ["custom"] = "2";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Type2", $currentPage->title);
$this->assertCount (3, $currentPage->entryArray);
$this->assertEquals ("tag1", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ());
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$_GET ["custom"] = "3";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Type1", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("other", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ());
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$_GET ["custom"] = NULL;
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
public function testPageCustomDetail ()
{
$page = Base::PAGE_CUSTOM_DETAIL;
$query = NULL;
$qid = "1";
$n = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$_GET ["custom"] = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$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 ());
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$_GET ["custom"] = "2";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$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 ());
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$_GET ["custom"] = "3";
$qid = "2";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("other", $currentPage->title);
$this->assertCount (1, $currentPage->entryArray);
$this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ());
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$_GET ["custom"] = NULL;
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
public function testPageAllAuthors ()
{
global $config;
$page = Base::PAGE_ALL_AUTHORS;
$query = NULL;
$qid = NULL;
$n = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$config['cops_author_split_first_letter'] = "0";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Authors", $currentPage->title);
$this->assertCount (6, $currentPage->entryArray);
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ());
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$config['cops_author_split_first_letter'] = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Authors", $currentPage->title);
$this->assertCount (5, $currentPage->entryArray);
2013-12-05 11:50:53 +02:00
$this->assertEquals ("C", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ());
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
public function testPageAuthorsFirstLetter ()
{
$page = Base::PAGE_AUTHORS_FIRST_LETTER;
$query = NULL;
$qid = "C";
$n = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
// Author Lewis Carroll
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("1 author starting with C", $currentPage->title);
$this->assertCount (1, $currentPage->entryArray);
$this->assertFalse ($currentPage->ContainsBook ());
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
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";
2013-12-05 11:52:51 +02:00
$config['cops_max_item_per_page'] = 2;
2013-12-05 11:50:53 +02:00
// First page
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
$this->assertEquals ("Arthur Conan Doyle", $currentPage->title);
2013-12-05 11:50:53 +02:00
$this->assertEquals (4, $currentPage->getMaxPage ());
$this->assertCount (2, $currentPage->entryArray);
$this->assertTrue ($currentPage->ContainsBook ());
$this->assertTrue ($currentPage->IsPaginated ());
$this->assertNull ($currentPage->getPrevLink ());
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
// Last page
2013-12-05 11:52:51 +02:00
$config['cops_max_item_per_page'] = 5;
2013-12-05 11:50:53 +02:00
$n = "2";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
$this->assertEquals ("Arthur Conan Doyle", $currentPage->title);
2013-12-05 11:50:53 +02:00
$this->assertEquals (2, $currentPage->getMaxPage ());
$this->assertCount (3, $currentPage->entryArray);
$this->assertTrue ($currentPage->ContainsBook ());
$this->assertTrue ($currentPage->IsPaginated ());
$this->assertNull ($currentPage->getNextLink ());
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
// No pagination
2013-12-05 11:52:51 +02:00
$config['cops_max_item_per_page'] = -1;
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
$this->assertEquals ("Arthur Conan Doyle", $currentPage->title);
2013-12-05 11:50:53 +02:00
$this->assertCount (8, $currentPage->entryArray);
$this->assertTrue ($currentPage->ContainsBook ());
$this->assertFalse ($currentPage->IsPaginated ());
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
public function testPageAllBooks ()
{
global $config;
$page = Base::PAGE_ALL_BOOKS;
$query = NULL;
$qid = NULL;
$n = "1";
2013-12-05 11:52:51 +02:00
$config['cops_titles_split_first_letter'] = 0;
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("All books", $currentPage->title);
$this->assertCount (15, $currentPage->entryArray);
2013-12-05 11:50:53 +02:00
$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 ());
2013-12-05 11:52:51 +02:00
$config['cops_titles_split_first_letter'] = 1;
2013-12-05 11:50:53 +02:00
$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 ());
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
public function testPageAllBooksByLetter ()
{
$page = Base::PAGE_ALL_BOOKS_LETTER;
$query = NULL;
$qid = "C";
$n = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
$this->assertEquals ("3 books starting with C", $currentPage->title);
$this->assertCount (3, $currentPage->entryArray);
2013-12-05 11:50:53 +02:00
$this->assertEquals ("The Call of the Wild", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ());
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
public function testPageAllSeries ()
{
$page = Base::PAGE_ALL_SERIES;
$query = NULL;
$qid = NULL;
$n = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Series", $currentPage->title);
$this->assertCount (4, $currentPage->entryArray);
2013-12-05 11:50:53 +02:00
$this->assertEquals ("D'Artagnan Romances", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ());
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
public function testPageSeriesDetail ()
{
$page = Base::PAGE_SERIE_DETAIL;
$query = NULL;
$qid = "1";
2013-12-05 11:52:51 +02:00
$n = "1";
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$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";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Publishers", $currentPage->title);
$this->assertCount (6, $currentPage->entryArray);
2013-12-05 11:50:53 +02:00
$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";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$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";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Tags", $currentPage->title);
$this->assertCount (11, $currentPage->entryArray);
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Action & Adventure", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ());
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
public function testPageTagDetail ()
{
$page = Base::PAGE_TAG_DETAIL;
$query = NULL;
$qid = "1";
$n = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$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";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Languages", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray);
2013-12-05 11:50:53 +02:00
$this->assertEquals ("English", $currentPage->entryArray [0]->title);
$this->assertEquals ("French", $currentPage->entryArray [1]->title);
2013-12-05 11:50:53 +02:00
$this->assertFalse ($currentPage->ContainsBook ());
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
public function testPageLanguageDetail ()
{
$page = Base::PAGE_LANGUAGE_DETAIL;
$query = NULL;
$qid = "1";
$n = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$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 ());
}
2013-12-05 11:52:51 +02:00
2014-03-10 15:02:00 +02:00
public function testPageAllRatings ()
{
$page = Base::PAGE_ALL_RATINGS;
$query = NULL;
$qid = NULL;
$n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2014-03-20 20:55:10 +02:00
$this->assertEquals ("Ratings", $currentPage->title);
2014-03-10 15:02:00 +02:00
$this->assertCount (3, $currentPage->entryArray);
$this->assertEquals ("2 stars", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ());
}
public function testPageRatingDetail ()
{
$page = Base::PAGE_RATING_DETAIL;
$query = NULL;
$qid = "1";
$n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->assertEquals ("5 stars", $currentPage->title);
$this->assertCount (4, $currentPage->entryArray);
$this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ());
}
2013-12-05 11:50:53 +02:00
public function testPageRecent ()
{
$page = Base::PAGE_ALL_RECENT_BOOKS;
$query = NULL;
$qid = NULL;
$n = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Recent additions", $currentPage->title);
$this->assertCount (15, $currentPage->entryArray);
$this->assertEquals ("La curée", $currentPage->entryArray [0]->title);
2013-12-05 11:50:53 +02:00
$this->assertTrue ($currentPage->ContainsBook ());
2014-04-30 15:16:42 +03:00
}
2013-12-05 11:52:51 +02:00
2014-04-30 15:16:42 +03:00
public function testPageRecent_WithFacets_IncludedTag ()
{
$page = Base::PAGE_ALL_RECENT_BOOKS;
$query = NULL;
$qid = NULL;
$n = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$_GET["tag"] = "Historical";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Recent additions", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("Twenty Years After", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ());
2013-12-05 11:52:51 +02:00
2014-04-30 15:16:42 +03:00
$_GET["tag"] = NULL;
}
public function testPageRecent_WithFacets_ExcludedTag ()
{
$page = Base::PAGE_ALL_RECENT_BOOKS;
$query = NULL;
$qid = NULL;
$n = "1";
2013-12-05 11:50:53 +02:00
$_GET["tag"] = "!Romance";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Recent additions", $currentPage->title);
$this->assertCount (13, $currentPage->entryArray);
$this->assertEquals ("La curée", $currentPage->entryArray [0]->title);
2013-12-05 11:50:53 +02:00
$this->assertTrue ($currentPage->ContainsBook ());
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$_GET["tag"] = NULL;
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
public function testPageBookDetail ()
{
$page = Base::PAGE_BOOK_DETAIL;
$query = NULL;
$qid = "2";
$n = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("The Return of Sherlock Holmes", $currentPage->title);
$this->assertCount (0, $currentPage->entryArray);
$this->assertFalse ($currentPage->ContainsBook ());
}
2013-12-05 11:52:51 +02:00
2014-04-30 15:09:27 +03:00
public function testPageSearch_WithOnlyBooksReturned ()
2013-12-05 11:50:53 +02:00
{
global $config;
2013-12-05 11:50:53 +02:00
$page = Base::PAGE_OPENSEARCH_QUERY;
$query = "alice";
$qid = NULL;
$n = "1";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
// Only books returned
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Search result for *alice*", $currentPage->title);
$this->assertCount (1, $currentPage->entryArray);
$this->assertEquals ("Search result for *alice* in books", $currentPage->entryArray [0]->title);
$this->assertEquals ("2 books", $currentPage->entryArray [0]->content);
$this->assertFalse ($currentPage->ContainsBook ());
2014-04-30 15:09:27 +03:00
}
2013-12-05 11:52:51 +02:00
2014-04-30 15:09:27 +03:00
public function testPageSearch_WithAuthorsIgnored ()
{
global $config;
$page = Base::PAGE_OPENSEARCH_QUERY;
2013-12-05 11:50:53 +02:00
// Match Lewis Caroll & Scarlet
$query = "car";
2014-04-30 15:09:27 +03:00
$qid = NULL;
$n = "1";
2013-12-17 21:56:41 +02:00
$config ['cops_ignored_categories'] = array ("author");
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->assertEquals ("Search result for *car*", $currentPage->title);
$this->assertCount (1, $currentPage->entryArray);
$this->assertEquals ("Search result for *car* in books", $currentPage->entryArray [0]->title);
$this->assertEquals ("1 book", $currentPage->entryArray [0]->content);
$this->assertFalse ($currentPage->ContainsBook ());
2013-12-17 21:56:41 +02:00
$config ['cops_ignored_categories'] = array ();
2014-04-30 15:09:27 +03:00
}
public function testPageSearch_WithTwoCategories ()
{
global $config;
$page = Base::PAGE_OPENSEARCH_QUERY;
// Match Lewis Caroll & Scarlet
$query = "car";
$qid = NULL;
$n = "1";
2013-12-05 11:50:53 +02:00
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Search result for *car*", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("Search result for *car* in books", $currentPage->entryArray [0]->title);
$this->assertEquals ("1 book", $currentPage->entryArray [0]->content);
$this->assertEquals ("Search result for *car* in authors", $currentPage->entryArray [1]->title);
$this->assertEquals ("1 author", $currentPage->entryArray [1]->content);
$this->assertFalse ($currentPage->ContainsBook ());
2013-12-05 11:50:53 +02:00
}
2013-12-05 11:52:51 +02:00
public function testPageSearch_WithAccentuatedCharacters ()
{
global $config;
$page = Base::PAGE_OPENSEARCH_QUERY;
$query = "curée";
$qid = NULL;
$n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->assertEquals ("Search result for *curée*", $currentPage->title);
$this->assertCount (1, $currentPage->entryArray);
$this->assertEquals ("Search result for *curée* in books", $currentPage->entryArray [0]->title);
$this->assertEquals ("1 book", $currentPage->entryArray [0]->content);
$this->assertFalse ($currentPage->ContainsBook ());
}
public function testPageSearch_WithNormalizedSearch ()
{
global $config;
$page = Base::PAGE_OPENSEARCH_QUERY;
$query = "curee";
$qid = NULL;
$n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
$this->markTestIncomplete();
$this->assertEquals ("Search result for *curee*", $currentPage->title);
$this->assertCount (1, $currentPage->entryArray);
$this->assertEquals ("Search result for *curee* in books", $currentPage->entryArray [0]->title);
$this->assertEquals ("1 book", $currentPage->entryArray [0]->content);
$this->assertFalse ($currentPage->ContainsBook ());
}
2013-12-05 11:50:53 +02:00
public function testPageSearchScopeAuthors ()
{
$page = Base::PAGE_OPENSEARCH_QUERY;
$qid = NULL;
$n = "1";
$_GET ["scope"] = "author";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
// Match Lewis Carroll
$query = "car";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$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 ());
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$_GET ["scope"] = NULL;
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
public function testPageSearchScopeSeries ()
{
$page = Base::PAGE_OPENSEARCH_QUERY;
$qid = NULL;
$n = "1";
$_GET ["scope"] = "series";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
// Match Holmes
$query = "hol";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$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 ());
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$_GET ["scope"] = NULL;
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
public function testPageSearchScopeBooks ()
{
$page = Base::PAGE_OPENSEARCH_QUERY;
$qid = NULL;
$n = "1";
$_GET ["scope"] = "book";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
// Match Holmes
$query = "hol";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Search result for *hol* in books", $currentPage->title);
$this->assertCount (4, $currentPage->entryArray);
$this->assertTrue ($currentPage->ContainsBook ());
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$_GET ["scope"] = NULL;
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
public function testPageSearchScopePublishers ()
{
$page = Base::PAGE_OPENSEARCH_QUERY;
$qid = NULL;
$n = "1";
$_GET ["scope"] = "publisher";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
// Match Holmes
$query = "millan";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$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 ());
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$_GET ["scope"] = NULL;
}
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
public function testPageSearchScopeTags ()
{
$page = Base::PAGE_OPENSEARCH_QUERY;
$qid = NULL;
$n = "1";
$_GET ["scope"] = "tag";
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
// Match Holmes
$query = "fic";
$currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent ();
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$this->assertEquals ("Search result for *fic* in tags", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray);
$this->assertFalse ($currentPage->ContainsBook ());
2013-12-05 11:52:51 +02:00
2013-12-05 11:50:53 +02:00
$_GET ["scope"] = NULL;
}
2013-10-12 08:56:17 +03:00
}