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.

107 lines
3.4KB

  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. require_once (dirname(__FILE__) . "/../epubfs.php");
  11. class EpubFsTest extends PHPUnit_Framework_TestCase
  12. {
  13. private static $book;
  14. private static $add;
  15. public static function setUpBeforeClass()
  16. {
  17. $idData = 20;
  18. self::$add = "data=$idData&";
  19. $myBook = Book::getBookByDataId($idData);
  20. self::$book = new EPub ($myBook->getFilePath ("EPUB", $idData));
  21. self::$book->initSpineComponent ();
  22. }
  23. public function testUrlImage () {
  24. $data = getComponentContent (self::$book, "cover.xml", self::$add);
  25. $src = "";
  26. if (preg_match("/src\=\'(.*?)\'/", $data, $matches)) {
  27. $src = $matches [1];
  28. }
  29. $this->assertEquals ('epubfs.php?data=20&amp;comp=images~SLASH~cover.png', $src);
  30. }
  31. public function testUrlHref () {
  32. $data = getComponentContent (self::$book, "title.xml", self::$add);
  33. $src = "";
  34. if (preg_match("/src\=\'(.*?)\'/", $data, $matches)) {
  35. $src = $matches [1];
  36. }
  37. $this->assertEquals ('epubfs.php?data=20&amp;comp=images~SLASH~logo~DASH~feedbooks~DASH~tiny.png', $src);
  38. $href = "";
  39. if (preg_match("/href\=\'(.*?)\'/", $data, $matches)) {
  40. $href = $matches [1];
  41. }
  42. $this->assertEquals ('epubfs.php?data=20&amp;comp=css~SLASH~title.css', $href);
  43. }
  44. public function testImportCss () {
  45. $data = getComponentContent (self::$book, "css~SLASH~title.css", self::$add);
  46. $import = "";
  47. if (preg_match("/import \'(.*?)\'/", $data, $matches)) {
  48. $import = $matches [1];
  49. }
  50. $this->assertEquals ('epubfs.php?data=20&amp;comp=css~SLASH~page.css', $import);
  51. }
  52. public function testUrlInCss () {
  53. $data = getComponentContent (self::$book, "css~SLASH~main.css", self::$add);
  54. $src = "";
  55. if (preg_match("/url\s*\(\'(.*?)\'\)/", $data, $matches)) {
  56. $src = $matches [1];
  57. }
  58. $this->assertEquals ('epubfs.php?data=20&comp=fonts~SLASH~times.ttf', $src);
  59. }
  60. public function testDirectLink () {
  61. $data = getComponentContent (self::$book, "main10.xml", self::$add);
  62. $src = "";
  63. if (preg_match("/href\='(.*?)' title=\"Direct Link\"/", $data, $matches)) {
  64. $src = $matches [1];
  65. }
  66. $this->assertEquals ('epubfs.php?data=20&amp;comp=main2.xml', $src);
  67. }
  68. public function testDirectLinkWithAnchor () {
  69. $data = getComponentContent (self::$book, "main10.xml", self::$add);
  70. $src = "";
  71. if (preg_match("/href\='(.*?)' title=\"Direct Link with anchor\"/", $data, $matches)) {
  72. $src = $matches [1];
  73. }
  74. $this->assertEquals ('epubfs.php?data=20&amp;comp=main2.xml#anchor', $src);
  75. }
  76. public function testAnchorOnly () {
  77. $data = getComponentContent (self::$book, "main10.xml", self::$add);
  78. $src = "";
  79. if (preg_match("/href\='(.*?)' title=\"Link to anchor\"/", $data, $matches)) {
  80. $src = $matches [1];
  81. }
  82. $this->assertEquals ('#anchor', $src);
  83. }
  84. }