2014-02-11 21:51:26 +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");
|
|
|
|
require_once (dirname(__FILE__) . "/../epubfs.php");
|
|
|
|
|
|
|
|
class EpubFsTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
2014-02-12 15:09:18 +02:00
|
|
|
private static $book;
|
|
|
|
private static $add;
|
2014-02-11 21:51:26 +02:00
|
|
|
|
|
|
|
|
2014-02-12 15:09:18 +02:00
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
|
|
|
$idData = 20;
|
|
|
|
self::$add = "data=$idData&";
|
|
|
|
$myBook = Book::getBookByDataId($idData);
|
2014-02-11 21:51:26 +02:00
|
|
|
|
2014-02-12 15:09:18 +02:00
|
|
|
self::$book = new EPub ($myBook->getFilePath ("EPUB", $idData));
|
|
|
|
self::$book->initSpineComponent ();
|
|
|
|
}
|
2014-02-11 21:51:26 +02:00
|
|
|
|
2014-02-12 15:09:18 +02:00
|
|
|
public function testUrlImage () {
|
|
|
|
$data = getComponentContent (self::$book, "cover.xml", self::$add);
|
2014-02-11 21:51:26 +02:00
|
|
|
|
|
|
|
$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 () {
|
2014-02-12 15:09:18 +02:00
|
|
|
$data = getComponentContent (self::$book, "title.xml", self::$add);
|
2014-02-11 21:51:26 +02:00
|
|
|
|
|
|
|
$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 () {
|
2014-02-12 15:09:18 +02:00
|
|
|
$data = getComponentContent (self::$book, "css~SLASH~title.css", self::$add);
|
2014-02-11 21:51:26 +02:00
|
|
|
|
|
|
|
$import = "";
|
|
|
|
if (preg_match("/import \'(.*?)\'/", $data, $matches)) {
|
|
|
|
$import = $matches [1];
|
|
|
|
}
|
|
|
|
$this->assertEquals ('epubfs.php?data=20&comp=css~SLASH~page.css', $import);
|
|
|
|
}
|
2014-02-13 14:51:01 +02:00
|
|
|
|
|
|
|
public function testUrlInCss () {
|
|
|
|
$data = getComponentContent (self::$book, "css~SLASH~main.css", self::$add);
|
|
|
|
|
|
|
|
$src = "";
|
|
|
|
if (preg_match("/url\s*\(\'(.*?)\'\)/", $data, $matches)) {
|
|
|
|
$src = $matches [1];
|
|
|
|
}
|
|
|
|
$this->assertEquals ('epubfs.php?data=20&comp=fonts~SLASH~times.ttf', $src);
|
|
|
|
}
|
2014-02-20 09:49:18 +02:00
|
|
|
|
|
|
|
public function testDirectLink () {
|
|
|
|
$data = getComponentContent (self::$book, "main10.xml", self::$add);
|
|
|
|
|
|
|
|
$src = "";
|
|
|
|
if (preg_match("/href\='(.*?)' title=\"Direct Link\"/", $data, $matches)) {
|
|
|
|
$src = $matches [1];
|
|
|
|
}
|
|
|
|
$this->assertEquals ('epubfs.php?data=20&comp=main2.xml', $src);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDirectLinkWithAnchor () {
|
|
|
|
$data = getComponentContent (self::$book, "main10.xml", self::$add);
|
|
|
|
|
|
|
|
$src = "";
|
|
|
|
if (preg_match("/href\='(.*?)' title=\"Direct Link with anchor\"/", $data, $matches)) {
|
|
|
|
$src = $matches [1];
|
|
|
|
}
|
|
|
|
$this->assertEquals ('epubfs.php?data=20&comp=main2.xml#anchor', $src);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAnchorOnly () {
|
|
|
|
$data = getComponentContent (self::$book, "main10.xml", self::$add);
|
|
|
|
|
|
|
|
$src = "";
|
|
|
|
if (preg_match("/href\='(.*?)' title=\"Link to anchor\"/", $data, $matches)) {
|
|
|
|
$src = $matches [1];
|
|
|
|
}
|
|
|
|
$this->assertEquals ('#anchor', $src);
|
|
|
|
}
|
2014-02-11 21:51:26 +02:00
|
|
|
}
|