Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...) http://blog.slucas.fr/en/oss/calibre-opds-php-server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

968 lines
33KB

  1. <?php
  2. /**
  3. * COPS (Calibre OPDS PHP Server) test file
  4. *
  5. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  6. * @author Sébastien Lucas <sebastien@slucas.fr>
  7. */
  8. require_once (dirname(__FILE__) . "/config_test.php");
  9. require_once (dirname(__FILE__) . "/../book.php");
  10. class PageTest extends PHPUnit_Framework_TestCase
  11. {
  12. public function testPageIndex ()
  13. {
  14. global $config;
  15. $page = Base::PAGE_INDEX;
  16. $query = NULL;
  17. $qid = NULL;
  18. $n = "1";
  19. $currentPage = Page::getPage ($page, $qid, $query, $n);
  20. $currentPage->InitializeContent ();
  21. $this->assertEquals ($config['cops_title_default'], $currentPage->title);
  22. $this->assertCount (8, $currentPage->entryArray);
  23. $this->assertEquals ("Authors", $currentPage->entryArray [0]->title);
  24. $this->assertEquals ("Alphabetical index of the 6 authors", $currentPage->entryArray [0]->content);
  25. $this->assertEquals (6, $currentPage->entryArray [0]->numberOfElement);
  26. $this->assertEquals ("Series", $currentPage->entryArray [1]->title);
  27. $this->assertEquals ("Alphabetical index of the 4 series", $currentPage->entryArray [1]->content);
  28. $this->assertEquals (4, $currentPage->entryArray [1]->numberOfElement);
  29. $this->assertEquals ("Publishers", $currentPage->entryArray [2]->title);
  30. $this->assertEquals ("Alphabetical index of the 6 publishers", $currentPage->entryArray [2]->content);
  31. $this->assertEquals (6, $currentPage->entryArray [2]->numberOfElement);
  32. $this->assertEquals ("Tags", $currentPage->entryArray [3]->title);
  33. $this->assertEquals ("Alphabetical index of the 11 tags", $currentPage->entryArray [3]->content);
  34. $this->assertEquals (11, $currentPage->entryArray [3]->numberOfElement);
  35. $this->assertEquals ("Ratings", $currentPage->entryArray [4]->title);
  36. $this->assertEquals ("3 ratings", $currentPage->entryArray [4]->content);
  37. $this->assertEquals (3, $currentPage->entryArray [4]->numberOfElement);
  38. $this->assertEquals ("Languages", $currentPage->entryArray [5]->title);
  39. $this->assertEquals ("Alphabetical index of the 2 languages", $currentPage->entryArray [5]->content);
  40. $this->assertEquals (2, $currentPage->entryArray [5]->numberOfElement);
  41. $this->assertEquals ("All books", $currentPage->entryArray [6]->title);
  42. $this->assertEquals ("Alphabetical index of the 15 books", $currentPage->entryArray [6]->content);
  43. $this->assertEquals (15, $currentPage->entryArray [6]->numberOfElement);
  44. $this->assertEquals ("Recent additions", $currentPage->entryArray [7]->title);
  45. $this->assertEquals ("50 most recent books", $currentPage->entryArray [7]->content);
  46. $this->assertEquals (50, $currentPage->entryArray [7]->numberOfElement);
  47. $this->assertFalse ($currentPage->ContainsBook ());
  48. }
  49. public function testPageIndexWithIgnored ()
  50. {
  51. global $config;
  52. $page = Base::PAGE_INDEX;
  53. $query = NULL;
  54. $qid = NULL;
  55. $n = "1";
  56. $config ['cops_ignored_categories'] = array ("author", "series", "tag", "publisher", "language");
  57. $currentPage = Page::getPage ($page, $qid, $query, $n);
  58. $currentPage->InitializeContent ();
  59. $this->assertEquals ($config['cops_title_default'], $currentPage->title);
  60. $this->assertCount (3, $currentPage->entryArray);
  61. $this->assertEquals ("Ratings", $currentPage->entryArray [0]->title);
  62. $this->assertEquals ("All books", $currentPage->entryArray [1]->title);
  63. $this->assertEquals ("Alphabetical index of the 15 books", $currentPage->entryArray [1]->content);
  64. $this->assertEquals ("Recent additions", $currentPage->entryArray [2]->title);
  65. $this->assertEquals ("50 most recent books", $currentPage->entryArray [2]->content);
  66. $this->assertFalse ($currentPage->ContainsBook ());
  67. }
  68. public function testPageIndexWithCustomColumn_Type1 ()
  69. {
  70. global $config;
  71. $page = Base::PAGE_INDEX;
  72. $query = NULL;
  73. $qid = NULL;
  74. $n = "1";
  75. $config['cops_calibre_custom_column'] = array ("type1");
  76. $currentPage = Page::getPage ($page, $qid, $query, $n);
  77. $currentPage->InitializeContent ();
  78. $this->assertCount (9, $currentPage->entryArray);
  79. $this->assertEquals ("Type1", $currentPage->entryArray [6]->title);
  80. $this->assertEquals ("Alphabetical index of the 2 tags", $currentPage->entryArray [6]->content);
  81. $this->assertEquals (2, $currentPage->entryArray [6]->numberOfElement);
  82. $config['cops_calibre_custom_column'] = array ();
  83. }
  84. public function testPageIndexWithCustomColumn_Type2 ()
  85. {
  86. global $config;
  87. $page = Base::PAGE_INDEX;
  88. $query = NULL;
  89. $qid = NULL;
  90. $n = "1";
  91. $config['cops_calibre_custom_column'] = array ("type2");
  92. $currentPage = Page::getPage ($page, $qid, $query, $n);
  93. $currentPage->InitializeContent ();
  94. $this->assertCount (9, $currentPage->entryArray);
  95. $this->assertEquals ("Type2", $currentPage->entryArray [6]->title);
  96. $this->assertEquals ("Alphabetical index of the 3 tags", $currentPage->entryArray [6]->content);
  97. $this->assertEquals (3, $currentPage->entryArray [6]->numberOfElement);
  98. $config['cops_calibre_custom_column'] = array ();
  99. }
  100. public function testPageIndexWithCustomColumn_Type4 ()
  101. {
  102. global $config;
  103. $page = Base::PAGE_INDEX;
  104. $query = NULL;
  105. $qid = NULL;
  106. $n = "1";
  107. $config['cops_calibre_custom_column'] = array ("type4");
  108. $currentPage = Page::getPage ($page, $qid, $query, $n);
  109. $currentPage->InitializeContent ();
  110. $this->assertCount (9, $currentPage->entryArray);
  111. $this->assertEquals ("Type4", $currentPage->entryArray [6]->title);
  112. $this->assertEquals ("Alphabetical index of the 2 tags", $currentPage->entryArray [6]->content);
  113. $this->assertEquals (2, $currentPage->entryArray [6]->numberOfElement);
  114. $config['cops_calibre_custom_column'] = array ();
  115. }
  116. public function testPageIndexWithCustomColumn_ManyTypes ()
  117. {
  118. global $config;
  119. $page = Base::PAGE_INDEX;
  120. $query = NULL;
  121. $qid = NULL;
  122. $n = "1";
  123. $config['cops_calibre_custom_column'] = array ("type1", "type2", "type4");
  124. $currentPage = Page::getPage ($page, $qid, $query, $n);
  125. $currentPage->InitializeContent ();
  126. $this->assertCount (11, $currentPage->entryArray);
  127. $config['cops_calibre_custom_column'] = array ();
  128. }
  129. public function testPageAllCustom_Type4 ()
  130. {
  131. $page = Base::PAGE_ALL_CUSTOMS;
  132. $query = NULL;
  133. $qid = NULL;
  134. $n = "1";
  135. $_GET ["custom"] = "1";
  136. $currentPage = Page::getPage ($page, $qid, $query, $n);
  137. $currentPage->InitializeContent ();
  138. $this->assertEquals ("Type4", $currentPage->title);
  139. $this->assertCount (2, $currentPage->entryArray);
  140. $this->assertEquals ("SeriesLike", $currentPage->entryArray [0]->title);
  141. $this->assertEquals (2, $currentPage->entryArray [0]->numberOfElement);
  142. $this->assertFalse ($currentPage->ContainsBook ());
  143. $_GET ["custom"] = NULL;
  144. }
  145. public function testPageAllCustom_Type2 ()
  146. {
  147. $page = Base::PAGE_ALL_CUSTOMS;
  148. $query = NULL;
  149. $qid = NULL;
  150. $n = "1";
  151. $_GET ["custom"] = "2";
  152. $currentPage = Page::getPage ($page, $qid, $query, $n);
  153. $currentPage->InitializeContent ();
  154. $this->assertEquals ("Type2", $currentPage->title);
  155. $this->assertCount (3, $currentPage->entryArray);
  156. $this->assertEquals ("tag1", $currentPage->entryArray [0]->title);
  157. $this->assertEquals (2, $currentPage->entryArray [0]->numberOfElement);
  158. $this->assertFalse ($currentPage->ContainsBook ());
  159. $_GET ["custom"] = NULL;
  160. }
  161. public function testPageAllCustom_Type1 ()
  162. {
  163. $page = Base::PAGE_ALL_CUSTOMS;
  164. $query = NULL;
  165. $qid = NULL;
  166. $n = "1";
  167. $_GET ["custom"] = "3";
  168. $currentPage = Page::getPage ($page, $qid, $query, $n);
  169. $currentPage->InitializeContent ();
  170. $this->assertEquals ("Type1", $currentPage->title);
  171. $this->assertCount (2, $currentPage->entryArray);
  172. $this->assertEquals ("other", $currentPage->entryArray [0]->title);
  173. $this->assertEquals (1, $currentPage->entryArray [0]->numberOfElement);
  174. $this->assertFalse ($currentPage->ContainsBook ());
  175. $_GET ["custom"] = NULL;
  176. }
  177. public function testPageCustomDetail_Type4 ()
  178. {
  179. $page = Base::PAGE_CUSTOM_DETAIL;
  180. $query = NULL;
  181. $qid = "1";
  182. $n = "1";
  183. $_GET ["custom"] = "1";
  184. $currentPage = Page::getPage ($page, $qid, $query, $n);
  185. $currentPage->InitializeContent ();
  186. $this->assertEquals ("SeriesLike", $currentPage->title);
  187. $this->assertCount (2, $currentPage->entryArray);
  188. $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title);
  189. $this->assertTrue ($currentPage->ContainsBook ());
  190. $_GET ["custom"] = NULL;
  191. }
  192. public function testPageCustomDetail_Type2 ()
  193. {
  194. $page = Base::PAGE_CUSTOM_DETAIL;
  195. $query = NULL;
  196. $qid = "1";
  197. $n = "1";
  198. $_GET ["custom"] = "2";
  199. $currentPage = Page::getPage ($page, $qid, $query, $n);
  200. $currentPage->InitializeContent ();
  201. $this->assertEquals ("tag1", $currentPage->title);
  202. $this->assertCount (2, $currentPage->entryArray);
  203. $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title);
  204. $this->assertTrue ($currentPage->ContainsBook ());
  205. $_GET ["custom"] = NULL;
  206. }
  207. public function testPageCustomDetail_Type1 ()
  208. {
  209. $page = Base::PAGE_CUSTOM_DETAIL;
  210. $query = NULL;
  211. $qid = "1";
  212. $n = "1";
  213. $_GET ["custom"] = "3";
  214. $qid = "2";
  215. $currentPage = Page::getPage ($page, $qid, $query, $n);
  216. $currentPage->InitializeContent ();
  217. $this->assertEquals ("other", $currentPage->title);
  218. $this->assertCount (1, $currentPage->entryArray);
  219. $this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [0]->title);
  220. $this->assertTrue ($currentPage->ContainsBook ());
  221. $_GET ["custom"] = NULL;
  222. }
  223. public function testPageAllAuthors_WithFullName ()
  224. {
  225. global $config;
  226. $page = Base::PAGE_ALL_AUTHORS;
  227. $query = NULL;
  228. $qid = NULL;
  229. $n = "1";
  230. $config['cops_author_split_first_letter'] = "0";
  231. $currentPage = Page::getPage ($page, $qid, $query, $n);
  232. $currentPage->InitializeContent ();
  233. $this->assertEquals ("Authors", $currentPage->title);
  234. $this->assertCount (6, $currentPage->entryArray);
  235. $this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title);
  236. $this->assertFalse ($currentPage->ContainsBook ());
  237. $config['cops_author_split_first_letter'] = "1";
  238. }
  239. public function testPageAllAuthors_SplittedByFirstLetter ()
  240. {
  241. global $config;
  242. $page = Base::PAGE_ALL_AUTHORS;
  243. $query = NULL;
  244. $qid = NULL;
  245. $n = "1";
  246. $currentPage = Page::getPage ($page, $qid, $query, $n);
  247. $currentPage->InitializeContent ();
  248. $this->assertEquals ("Authors", $currentPage->title);
  249. $this->assertCount (5, $currentPage->entryArray);
  250. $this->assertEquals ("C", $currentPage->entryArray [0]->title);
  251. $this->assertEquals (1, $currentPage->entryArray [0]->numberOfElement);
  252. $this->assertFalse ($currentPage->ContainsBook ());
  253. }
  254. public function testPageAuthorsFirstLetter ()
  255. {
  256. $page = Base::PAGE_AUTHORS_FIRST_LETTER;
  257. $query = NULL;
  258. $qid = "C";
  259. $n = "1";
  260. // Author Lewis Carroll
  261. $currentPage = Page::getPage ($page, $qid, $query, $n);
  262. $currentPage->InitializeContent ();
  263. $this->assertEquals ("1 author starting with C", $currentPage->title);
  264. $this->assertCount (1, $currentPage->entryArray);
  265. $this->assertFalse ($currentPage->ContainsBook ());
  266. }
  267. public function testPageAuthorsDetail_FirstPage ()
  268. {
  269. global $config;
  270. $page = Base::PAGE_AUTHOR_DETAIL;
  271. $query = NULL;
  272. $qid = "1";
  273. $n = "1";
  274. $_SERVER['QUERY_STRING'] = "page=" . Base::PAGE_AUTHOR_DETAIL . "&id=1&n=1";
  275. $config['cops_max_item_per_page'] = 2;
  276. // First page
  277. $currentPage = Page::getPage ($page, $qid, $query, $n);
  278. $currentPage->InitializeContent ();
  279. $this->assertEquals ("Arthur Conan Doyle", $currentPage->title);
  280. $this->assertEquals (4, $currentPage->getMaxPage ());
  281. $this->assertCount (2, $currentPage->entryArray);
  282. $this->assertTrue ($currentPage->ContainsBook ());
  283. $this->assertTrue ($currentPage->IsPaginated ());
  284. $this->assertNull ($currentPage->getPrevLink ());
  285. $config['cops_max_item_per_page'] = -1;
  286. }
  287. public function testPageAuthorsDetail_LastPage ()
  288. {
  289. global $config;
  290. $page = Base::PAGE_AUTHOR_DETAIL;
  291. $query = NULL;
  292. $qid = "1";
  293. $n = "1";
  294. $_SERVER['QUERY_STRING'] = "page=" . Base::PAGE_AUTHOR_DETAIL . "&id=1&n=1";
  295. // Last page
  296. $config['cops_max_item_per_page'] = 5;
  297. $n = "2";
  298. $currentPage = Page::getPage ($page, $qid, $query, $n);
  299. $currentPage->InitializeContent ();
  300. $this->assertEquals ("Arthur Conan Doyle", $currentPage->title);
  301. $this->assertEquals (2, $currentPage->getMaxPage ());
  302. $this->assertCount (3, $currentPage->entryArray);
  303. $this->assertTrue ($currentPage->ContainsBook ());
  304. $this->assertTrue ($currentPage->IsPaginated ());
  305. $this->assertNull ($currentPage->getNextLink ());
  306. // No pagination
  307. $config['cops_max_item_per_page'] = -1;
  308. }
  309. public function testPageAuthorsDetail_NoPagination ()
  310. {
  311. global $config;
  312. $page = Base::PAGE_AUTHOR_DETAIL;
  313. $query = NULL;
  314. $qid = "1";
  315. $n = "1";
  316. $_SERVER['QUERY_STRING'] = "page=" . Base::PAGE_AUTHOR_DETAIL . "&id=1&n=1";
  317. // No pagination
  318. $config['cops_max_item_per_page'] = -1;
  319. $currentPage = Page::getPage ($page, $qid, $query, $n);
  320. $currentPage->InitializeContent ();
  321. $this->assertEquals ("Arthur Conan Doyle", $currentPage->title);
  322. $this->assertCount (8, $currentPage->entryArray);
  323. $this->assertTrue ($currentPage->ContainsBook ());
  324. $this->assertFalse ($currentPage->IsPaginated ());
  325. }
  326. public function testPageAllBooks_WithFullName ()
  327. {
  328. global $config;
  329. $page = Base::PAGE_ALL_BOOKS;
  330. $query = NULL;
  331. $qid = NULL;
  332. $n = "1";
  333. $config['cops_titles_split_first_letter'] = 0;
  334. $currentPage = Page::getPage ($page, $qid, $query, $n);
  335. $currentPage->InitializeContent ();
  336. $this->assertEquals ("All books", $currentPage->title);
  337. $this->assertCount (15, $currentPage->entryArray);
  338. $this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title);
  339. $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [1]->title);
  340. $this->assertTrue ($currentPage->ContainsBook ());
  341. $config['cops_titles_split_first_letter'] = 1;
  342. }
  343. public function testPageAllBooks_SplittedByFirstLetter ()
  344. {
  345. global $config;
  346. $page = Base::PAGE_ALL_BOOKS;
  347. $query = NULL;
  348. $qid = NULL;
  349. $n = "1";
  350. $currentPage = Page::getPage ($page, $qid, $query, $n);
  351. $currentPage->InitializeContent ();
  352. $this->assertEquals ("All books", $currentPage->title);
  353. $this->assertCount (9, $currentPage->entryArray);
  354. $this->assertEquals ("A", $currentPage->entryArray [0]->title);
  355. $this->assertEquals ("C", $currentPage->entryArray [1]->title);
  356. $this->assertFalse ($currentPage->ContainsBook ());
  357. }
  358. public function testPageAllBooksByLetter ()
  359. {
  360. $page = Base::PAGE_ALL_BOOKS_LETTER;
  361. $query = NULL;
  362. $qid = "C";
  363. $n = "1";
  364. $currentPage = Page::getPage ($page, $qid, $query, $n);
  365. $currentPage->InitializeContent ();
  366. $this->assertEquals ("3 books starting with C", $currentPage->title);
  367. $this->assertCount (3, $currentPage->entryArray);
  368. $this->assertEquals ("The Call of the Wild", $currentPage->entryArray [0]->title);
  369. $this->assertTrue ($currentPage->ContainsBook ());
  370. }
  371. public function testPageAllSeries ()
  372. {
  373. $page = Base::PAGE_ALL_SERIES;
  374. $query = NULL;
  375. $qid = NULL;
  376. $n = "1";
  377. $currentPage = Page::getPage ($page, $qid, $query, $n);
  378. $currentPage->InitializeContent ();
  379. $this->assertEquals ("Series", $currentPage->title);
  380. $this->assertCount (4, $currentPage->entryArray);
  381. $this->assertEquals ("D'Artagnan Romances", $currentPage->entryArray [0]->title);
  382. $this->assertFalse ($currentPage->ContainsBook ());
  383. }
  384. public function testPageSeriesDetail ()
  385. {
  386. $page = Base::PAGE_SERIE_DETAIL;
  387. $query = NULL;
  388. $qid = "1";
  389. $n = "1";
  390. $currentPage = Page::getPage ($page, $qid, $query, $n);
  391. $currentPage->InitializeContent ();
  392. $this->assertEquals ("Sherlock Holmes", $currentPage->title);
  393. $this->assertCount (7, $currentPage->entryArray);
  394. $this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [0]->title);
  395. $this->assertTrue ($currentPage->ContainsBook ());
  396. }
  397. public function testPageAllPublishers ()
  398. {
  399. $page = Base::PAGE_ALL_PUBLISHERS;
  400. $query = NULL;
  401. $qid = NULL;
  402. $n = "1";
  403. $currentPage = Page::getPage ($page, $qid, $query, $n);
  404. $currentPage->InitializeContent ();
  405. $this->assertEquals ("Publishers", $currentPage->title);
  406. $this->assertCount (6, $currentPage->entryArray);
  407. $this->assertEquals ("D. Appleton and Company", $currentPage->entryArray [0]->title);
  408. $this->assertFalse ($currentPage->ContainsBook ());
  409. }
  410. public function testPagePublishersDetail ()
  411. {
  412. $page = Base::PAGE_PUBLISHER_DETAIL;
  413. $query = NULL;
  414. $qid = "6";
  415. $n = "1";
  416. $currentPage = Page::getPage ($page, $qid, $query, $n);
  417. $currentPage->InitializeContent ();
  418. $this->assertEquals ("Strand Magazine", $currentPage->title);
  419. $this->assertCount (8, $currentPage->entryArray);
  420. $this->assertEquals ("The Return of Sherlock Holmes", $currentPage->entryArray [0]->title);
  421. $this->assertTrue ($currentPage->ContainsBook ());
  422. }
  423. public function testPageAllTags ()
  424. {
  425. $page = Base::PAGE_ALL_TAGS;
  426. $query = NULL;
  427. $qid = NULL;
  428. $n = "1";
  429. $currentPage = Page::getPage ($page, $qid, $query, $n);
  430. $currentPage->InitializeContent ();
  431. $this->assertEquals ("Tags", $currentPage->title);
  432. $this->assertCount (11, $currentPage->entryArray);
  433. $this->assertEquals ("Action & Adventure", $currentPage->entryArray [0]->title);
  434. $this->assertFalse ($currentPage->ContainsBook ());
  435. }
  436. public function testPageTagDetail ()
  437. {
  438. $page = Base::PAGE_TAG_DETAIL;
  439. $query = NULL;
  440. $qid = "1";
  441. $n = "1";
  442. $currentPage = Page::getPage ($page, $qid, $query, $n);
  443. $currentPage->InitializeContent ();
  444. $this->assertEquals ("Fiction", $currentPage->title);
  445. $this->assertCount (14, $currentPage->entryArray);
  446. $this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title);
  447. $this->assertTrue ($currentPage->ContainsBook ());
  448. }
  449. public function testPageAllLanguages ()
  450. {
  451. $page = Base::PAGE_ALL_LANGUAGES;
  452. $query = NULL;
  453. $qid = NULL;
  454. $n = "1";
  455. $currentPage = Page::getPage ($page, $qid, $query, $n);
  456. $currentPage->InitializeContent ();
  457. $this->assertEquals ("Languages", $currentPage->title);
  458. $this->assertCount (2, $currentPage->entryArray);
  459. $this->assertEquals ("English", $currentPage->entryArray [0]->title);
  460. $this->assertEquals ("French", $currentPage->entryArray [1]->title);
  461. $this->assertFalse ($currentPage->ContainsBook ());
  462. }
  463. public function testPageLanguageDetail ()
  464. {
  465. $page = Base::PAGE_LANGUAGE_DETAIL;
  466. $query = NULL;
  467. $qid = "1";
  468. $n = "1";
  469. $currentPage = Page::getPage ($page, $qid, $query, $n);
  470. $currentPage->InitializeContent ();
  471. $this->assertEquals ("English", $currentPage->title);
  472. $this->assertCount (14, $currentPage->entryArray);
  473. $this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title);
  474. $this->assertTrue ($currentPage->ContainsBook ());
  475. }
  476. public function testPageAllRatings ()
  477. {
  478. $page = Base::PAGE_ALL_RATINGS;
  479. $query = NULL;
  480. $qid = NULL;
  481. $n = "1";
  482. $currentPage = Page::getPage ($page, $qid, $query, $n);
  483. $currentPage->InitializeContent ();
  484. $this->assertEquals ("Ratings", $currentPage->title);
  485. $this->assertCount (3, $currentPage->entryArray);
  486. $this->assertEquals ("2 stars", $currentPage->entryArray [0]->title);
  487. $this->assertFalse ($currentPage->ContainsBook ());
  488. }
  489. public function testPageRatingDetail ()
  490. {
  491. $page = Base::PAGE_RATING_DETAIL;
  492. $query = NULL;
  493. $qid = "1";
  494. $n = "1";
  495. $currentPage = Page::getPage ($page, $qid, $query, $n);
  496. $currentPage->InitializeContent ();
  497. $this->assertEquals ("5 stars", $currentPage->title);
  498. $this->assertCount (4, $currentPage->entryArray);
  499. $this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title);
  500. $this->assertTrue ($currentPage->ContainsBook ());
  501. }
  502. public function testPageRecent ()
  503. {
  504. $page = Base::PAGE_ALL_RECENT_BOOKS;
  505. $query = NULL;
  506. $qid = NULL;
  507. $n = "1";
  508. $currentPage = Page::getPage ($page, $qid, $query, $n);
  509. $currentPage->InitializeContent ();
  510. $this->assertEquals ("Recent additions", $currentPage->title);
  511. $this->assertCount (15, $currentPage->entryArray);
  512. $this->assertEquals ("La curée", $currentPage->entryArray [0]->title);
  513. $this->assertTrue ($currentPage->ContainsBook ());
  514. }
  515. public function testPageRecent_WithFacets_IncludedTag ()
  516. {
  517. $page = Base::PAGE_ALL_RECENT_BOOKS;
  518. $query = NULL;
  519. $qid = NULL;
  520. $n = "1";
  521. $_GET["tag"] = "Historical";
  522. $currentPage = Page::getPage ($page, $qid, $query, $n);
  523. $currentPage->InitializeContent ();
  524. $this->assertEquals ("Recent additions", $currentPage->title);
  525. $this->assertCount (2, $currentPage->entryArray);
  526. $this->assertEquals ("Twenty Years After", $currentPage->entryArray [0]->title);
  527. $this->assertTrue ($currentPage->ContainsBook ());
  528. $_GET["tag"] = NULL;
  529. }
  530. public function testPageRecent_WithFacets_ExcludedTag ()
  531. {
  532. $page = Base::PAGE_ALL_RECENT_BOOKS;
  533. $query = NULL;
  534. $qid = NULL;
  535. $n = "1";
  536. $_GET["tag"] = "!Romance";
  537. $currentPage = Page::getPage ($page, $qid, $query, $n);
  538. $currentPage->InitializeContent ();
  539. $this->assertEquals ("Recent additions", $currentPage->title);
  540. $this->assertCount (13, $currentPage->entryArray);
  541. $this->assertEquals ("La curée", $currentPage->entryArray [0]->title);
  542. $this->assertTrue ($currentPage->ContainsBook ());
  543. $_GET["tag"] = NULL;
  544. }
  545. public function testPageBookDetail ()
  546. {
  547. $page = Base::PAGE_BOOK_DETAIL;
  548. $query = NULL;
  549. $qid = "2";
  550. $n = "1";
  551. $currentPage = Page::getPage ($page, $qid, $query, $n);
  552. $currentPage->InitializeContent ();
  553. $this->assertEquals ("The Return of Sherlock Holmes", $currentPage->title);
  554. $this->assertCount (0, $currentPage->entryArray);
  555. $this->assertFalse ($currentPage->ContainsBook ());
  556. }
  557. public function testPageSearch_WithOnlyBooksReturned ()
  558. {
  559. global $config;
  560. $page = Base::PAGE_OPENSEARCH_QUERY;
  561. $query = "alice";
  562. $qid = NULL;
  563. $n = "1";
  564. // Only books returned
  565. $currentPage = Page::getPage ($page, $qid, $query, $n);
  566. $currentPage->InitializeContent ();
  567. $this->assertEquals ("Search result for *alice*", $currentPage->title);
  568. $this->assertCount (1, $currentPage->entryArray);
  569. $this->assertEquals ("Search result for *alice* in books", $currentPage->entryArray [0]->title);
  570. $this->assertEquals ("2 books", $currentPage->entryArray [0]->content);
  571. $this->assertFalse ($currentPage->ContainsBook ());
  572. }
  573. public function testPageSearch_WithAuthorsIgnored ()
  574. {
  575. global $config;
  576. $page = Base::PAGE_OPENSEARCH_QUERY;
  577. // Match Lewis Caroll & Scarlet
  578. $query = "car";
  579. $qid = NULL;
  580. $n = "1";
  581. $config ['cops_ignored_categories'] = array ("author");
  582. $currentPage = Page::getPage ($page, $qid, $query, $n);
  583. $currentPage->InitializeContent ();
  584. $this->assertEquals ("Search result for *car*", $currentPage->title);
  585. $this->assertCount (1, $currentPage->entryArray);
  586. $this->assertEquals ("Search result for *car* in books", $currentPage->entryArray [0]->title);
  587. $this->assertEquals ("1 book", $currentPage->entryArray [0]->content);
  588. $this->assertFalse ($currentPage->ContainsBook ());
  589. $config ['cops_ignored_categories'] = array ();
  590. }
  591. public function testPageSearch_WithTwoCategories ()
  592. {
  593. global $config;
  594. $page = Base::PAGE_OPENSEARCH_QUERY;
  595. // Match Lewis Caroll & Scarlet
  596. $query = "car";
  597. $qid = NULL;
  598. $n = "1";
  599. $currentPage = Page::getPage ($page, $qid, $query, $n);
  600. $currentPage->InitializeContent ();
  601. $this->assertEquals ("Search result for *car*", $currentPage->title);
  602. $this->assertCount (2, $currentPage->entryArray);
  603. $this->assertEquals ("Search result for *car* in books", $currentPage->entryArray [0]->title);
  604. $this->assertEquals ("1 book", $currentPage->entryArray [0]->content);
  605. $this->assertEquals ("Search result for *car* in authors", $currentPage->entryArray [1]->title);
  606. $this->assertEquals ("1 author", $currentPage->entryArray [1]->content);
  607. $this->assertFalse ($currentPage->ContainsBook ());
  608. }
  609. /**
  610. * @dataProvider providerAccentuatedCharacters
  611. */
  612. public function testPageSearch_WithAccentuatedCharacters ($query, $count, $content)
  613. {
  614. global $config;
  615. $page = Base::PAGE_OPENSEARCH_QUERY;
  616. $qid = NULL;
  617. $n = "1";
  618. $currentPage = Page::getPage ($page, $qid, $query, $n);
  619. $currentPage->InitializeContent ();
  620. $this->assertEquals ("Search result for *$query*", $currentPage->title);
  621. $this->assertCount ($count, $currentPage->entryArray);
  622. if ($count > 0) {
  623. $this->assertEquals ($content, $currentPage->entryArray [0]->content);
  624. }
  625. $this->assertFalse ($currentPage->ContainsBook ());
  626. }
  627. public function providerAccentuatedCharacters ()
  628. {
  629. return array (
  630. array ("curée", 1, "1 book"),
  631. array ("Émile zola", 1, "1 author"),
  632. array ("émile zola", 0, NULL), // With standard search upper does not work with diacritics
  633. array ("Littérature", 1, "1 tag"),
  634. array ("Eugène Fasquelle", 1, "1 publisher")
  635. );
  636. }
  637. /**
  638. * @dataProvider providerNormalizedSearch
  639. */
  640. public function testPageSearch_WithNormalizedSearch_Book ($query, $count, $content)
  641. {
  642. global $config;
  643. $page = Base::PAGE_OPENSEARCH_QUERY;
  644. $qid = NULL;
  645. $n = "1";
  646. $config ['cops_normalized_search'] = "1";
  647. Base::clearDb ();
  648. if (!useNormAndUp ()) {
  649. $this->markTestIncomplete();
  650. }
  651. $currentPage = Page::getPage ($page, $qid, $query, $n);
  652. $currentPage->InitializeContent ();
  653. $this->assertEquals ("Search result for *$query*", $currentPage->title);
  654. $this->assertCount ($count, $currentPage->entryArray);
  655. if ($count > 0) {
  656. $this->assertEquals ($content, $currentPage->entryArray [0]->content);
  657. }
  658. $this->assertFalse ($currentPage->ContainsBook ());
  659. $config ['cops_normalized_search'] = "0";
  660. Base::clearDb ();
  661. }
  662. public function providerNormalizedSearch ()
  663. {
  664. return array (
  665. array ("curee", 1, "1 book"),
  666. array ("emile zola", 1, "1 author"),
  667. array ("émile zola", 1, "1 author"),
  668. array ("Litterature", 1, "1 tag"),
  669. array ("Litterâture", 1, "1 tag"),
  670. array ("Serie des Rougon", 1, "1 series"),
  671. array ("Eugene Fasquelle", 1, "1 publisher")
  672. );
  673. }
  674. public function testAuthorSearch_ByName ()
  675. {
  676. global $config;
  677. $page = Base::PAGE_OPENSEARCH_QUERY;
  678. $query = "Lewis Carroll";
  679. $_GET ["scope"] = "author";
  680. $qid = NULL;
  681. $n = "1";
  682. $currentPage = Page::getPage ($page, $qid, $query, $n);
  683. $currentPage->InitializeContent ();
  684. $this->assertEquals ("Search result for *Lewis Carroll* in authors", $currentPage->title);
  685. $this->assertCount (1, $currentPage->entryArray);
  686. $this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title);
  687. $this->assertFalse ($currentPage->ContainsBook ());
  688. }
  689. public function testAuthorSearch_BySort ()
  690. {
  691. global $config;
  692. $page = Base::PAGE_OPENSEARCH_QUERY;
  693. $query = "Carroll, Lewis";
  694. $_GET ["scope"] = "author";
  695. $qid = NULL;
  696. $n = "1";
  697. $currentPage = Page::getPage ($page, $qid, $query, $n);
  698. $currentPage->InitializeContent ();
  699. $this->assertEquals ("Search result for *Carroll, Lewis* in authors", $currentPage->title);
  700. $this->assertCount (1, $currentPage->entryArray);
  701. $this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title);
  702. $this->assertFalse ($currentPage->ContainsBook ());
  703. }
  704. public function testPageSearchScopeAuthors ()
  705. {
  706. $page = Base::PAGE_OPENSEARCH_QUERY;
  707. $qid = NULL;
  708. $n = "1";
  709. $_GET ["scope"] = "author";
  710. // Match Lewis Carroll
  711. $query = "car";
  712. $currentPage = Page::getPage ($page, $qid, $query, $n);
  713. $currentPage->InitializeContent ();
  714. $this->assertEquals ("Search result for *car* in authors", $currentPage->title);
  715. $this->assertCount (1, $currentPage->entryArray);
  716. $this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title);
  717. $this->assertFalse ($currentPage->ContainsBook ());
  718. $_GET ["scope"] = NULL;
  719. }
  720. public function testPageSearchScopeSeries ()
  721. {
  722. $page = Base::PAGE_OPENSEARCH_QUERY;
  723. $qid = NULL;
  724. $n = "1";
  725. $_GET ["scope"] = "series";
  726. // Match Holmes
  727. $query = "hol";
  728. $currentPage = Page::getPage ($page, $qid, $query, $n);
  729. $currentPage->InitializeContent ();
  730. $this->assertEquals ("Search result for *hol* in series", $currentPage->title);
  731. $this->assertCount (1, $currentPage->entryArray);
  732. $this->assertEquals ("Sherlock Holmes", $currentPage->entryArray [0]->title);
  733. $this->assertFalse ($currentPage->ContainsBook ());
  734. $_GET ["scope"] = NULL;
  735. }
  736. public function testPageSearchScopeBooks ()
  737. {
  738. $page = Base::PAGE_OPENSEARCH_QUERY;
  739. $qid = NULL;
  740. $n = "1";
  741. $_GET ["scope"] = "book";
  742. // Match Holmes
  743. $query = "hol";
  744. $currentPage = Page::getPage ($page, $qid, $query, $n);
  745. $currentPage->InitializeContent ();
  746. $this->assertEquals ("Search result for *hol* in books", $currentPage->title);
  747. $this->assertCount (4, $currentPage->entryArray);
  748. $this->assertTrue ($currentPage->ContainsBook ());
  749. $_GET ["scope"] = NULL;
  750. }
  751. public function testPageSearchScopePublishers ()
  752. {
  753. $page = Base::PAGE_OPENSEARCH_QUERY;
  754. $qid = NULL;
  755. $n = "1";
  756. $_GET ["scope"] = "publisher";
  757. // Match Holmes
  758. $query = "millan";
  759. $currentPage = Page::getPage ($page, $qid, $query, $n);
  760. $currentPage->InitializeContent ();
  761. $this->assertEquals ("Search result for *millan* in publishers", $currentPage->title);
  762. $this->assertCount (2, $currentPage->entryArray);
  763. $this->assertEquals ("Macmillan and Co. London", $currentPage->entryArray [0]->title);
  764. $this->assertFalse ($currentPage->ContainsBook ());
  765. $_GET ["scope"] = NULL;
  766. }
  767. public function testPageSearchScopeTags ()
  768. {
  769. $page = Base::PAGE_OPENSEARCH_QUERY;
  770. $qid = NULL;
  771. $n = "1";
  772. $_GET ["scope"] = "tag";
  773. // Match Holmes
  774. $query = "fic";
  775. $currentPage = Page::getPage ($page, $qid, $query, $n);
  776. $currentPage->InitializeContent ();
  777. $this->assertEquals ("Search result for *fic* in tags", $currentPage->title);
  778. $this->assertCount (2, $currentPage->entryArray);
  779. $this->assertFalse ($currentPage->ContainsBook ());
  780. $_GET ["scope"] = NULL;
  781. }
  782. }