From 755d6581ffc734a2580ff3a89a2cec9640b49dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Tue, 11 Feb 2014 20:51:26 +0100 Subject: [PATCH] Add a test for the epubfs handler. --- test/EpubFsTest.php | 82 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 test/EpubFsTest.php diff --git a/test/EpubFsTest.php b/test/EpubFsTest.php new file mode 100644 index 0000000..6d27ce0 --- /dev/null +++ b/test/EpubFsTest.php @@ -0,0 +1,82 @@ + + */ + +require_once (dirname(__FILE__) . "/config_test.php"); +require_once (dirname(__FILE__) . "/../book.php"); +require_once (dirname(__FILE__) . "/../epubfs.php"); + +class EpubFsTest extends PHPUnit_Framework_TestCase +{ + public function testUrlImage () { + $idData = 20; + $add = "data=$idData&"; + $myBook = Book::getBookByDataId($idData); + + $this->assertNotNull($myBook); + + $book = new EPub ($myBook->getFilePath ("EPUB", $idData)); + + $book->initSpineComponent (); + + $data = getComponentContent ($book, "cover.xml", $add); + + $src = ""; + if (preg_match("/src\=\'(.*?)\'/", $data, $matches)) { + $src = $matches [1]; + } + $this->assertEquals ('epubfs.php?data=20&comp=images~SLASH~cover.png', $src); + + } + + public function testUrlHref () { + $idData = 20; + $add = "data=$idData&"; + $myBook = Book::getBookByDataId($idData); + + $this->assertNotNull($myBook); + + $book = new EPub ($myBook->getFilePath ("EPUB", $idData)); + + $book->initSpineComponent (); + + $data = getComponentContent ($book, "title.xml", $add); + + $src = ""; + if (preg_match("/src\=\'(.*?)\'/", $data, $matches)) { + $src = $matches [1]; + } + $this->assertEquals ('epubfs.php?data=20&comp=images~SLASH~logo~DASH~feedbooks~DASH~tiny.png', $src); + + $href = ""; + if (preg_match("/href\=\'(.*?)\'/", $data, $matches)) { + $href = $matches [1]; + } + $this->assertEquals ('epubfs.php?data=20&comp=css~SLASH~title.css', $href); + + } + + public function testImportCss () { + $idData = 20; + $add = "data=$idData&"; + $myBook = Book::getBookByDataId($idData); + + $this->assertNotNull($myBook); + + $book = new EPub ($myBook->getFilePath ("EPUB", $idData)); + + $book->initSpineComponent (); + + $data = getComponentContent ($book, "css~SLASH~title.css", $add); + + $import = ""; + if (preg_match("/import \'(.*?)\'/", $data, $matches)) { + $import = $matches [1]; + } + $this->assertEquals ('epubfs.php?data=20&comp=css~SLASH~page.css', $import); + } +} \ No newline at end of file