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.

73 lines
2.7KB

  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__) . "/../JSON_renderer.php");
  10. class JsonTest extends PHPUnit_Framework_TestCase
  11. {
  12. public function testCompleteArray () {
  13. global $config;
  14. $_SERVER["HTTP_USER_AGENT"] = "Firefox";
  15. $test = array ();
  16. $test = JSONRenderer::addCompleteArray ($test);
  17. $this->assertArrayHasKey ("c", $test);
  18. $this->assertArrayHasKey ("version", $test ["c"]);
  19. $this->assertArrayHasKey ("i18n", $test ["c"]);
  20. $this->assertArrayHasKey ("url", $test ["c"]);
  21. $this->assertArrayHasKey ("config", $test ["c"]);
  22. $this->assertFalse ($test ["c"]["url"]["thumbnailUrl"] == $test ["c"]["url"]["coverUrl"]);
  23. // The thumbnails should be the same as the covers
  24. $config['cops_thumbnail_handling'] = "1";
  25. $test = array ();
  26. $test = JSONRenderer::addCompleteArray ($test);
  27. $this->assertTrue ($test ["c"]["url"]["thumbnailUrl"] == $test ["c"]["url"]["coverUrl"]);
  28. // The thumbnails should be the same as the covers
  29. $config['cops_thumbnail_handling'] = "/images.png";
  30. $test = array ();
  31. $test = JSONRenderer::addCompleteArray ($test);
  32. $this->assertEquals ("/images.png", $test ["c"]["url"]["thumbnailUrl"]);
  33. }
  34. public function testGetBookContentArrayWithoutSeries () {
  35. $book = Book::getBookById(17);
  36. $test = JSONRenderer::getBookContentArray($book);
  37. $this->assertEquals ("", $test ["seriesName"]);
  38. $this->assertEquals ("1.0", $test ["seriesIndex"]);
  39. $this->assertEquals ("", $test ["seriesCompleteName"]);
  40. $this->assertEquals ("", $test ["seriesurl"]);
  41. }
  42. public function testGetBookContentArrayWithSeries () {
  43. $book = Book::getBookById(2);
  44. $test = JSONRenderer::getBookContentArray($book);
  45. $this->assertEquals ("Sherlock Holmes", $test ["seriesName"]);
  46. $this->assertEquals ("6.0", $test ["seriesIndex"]);
  47. $this->assertEquals ("Book 6.0 in the Sherlock Holmes series", $test ["seriesCompleteName"]);
  48. $this->assertStringEndsWith ("?page=7&id=1", $test ["seriesurl"]);
  49. }
  50. public function testGetFullBookContentArray () {
  51. $book = Book::getBookById(17);
  52. $test = JSONRenderer::getFullBookContentArray($book);
  53. $this->assertCount (1, $test ["authors"]);
  54. $this->assertCount (3, $test ["tags"]);
  55. $this->assertCount (3, $test ["datas"]);
  56. }
  57. }