1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
<?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 (dirname(__FILE__) . "/../epubfs.php");
require (dirname(__FILE__) . "/config_test.php");
class EpubFsTest extends PHPUnit_Framework_TestCase
{
private static $book;
private static $add;
public static function setUpBeforeClass()
{
$idData = 20;
self::$add = "data=$idData&";
$myBook = Book::getBookByDataId($idData);
self::$book = new EPub ($myBook->getFilePath ("EPUB", $idData));
self::$book->initSpineComponent ();
}
public function testUrlImage () {
$data = getComponentContent (self::$book, "cover.xml", self::$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 () {
$data = getComponentContent (self::$book, "title.xml", self::$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 () {
$data = getComponentContent (self::$book, "css~SLASH~title.css", self::$add);
$import = "";
if (preg_match("/import \'(.*?)\'/", $data, $matches)) {
$import = $matches [1];
}
$this->assertEquals ('epubfs.php?data=20&comp=css~SLASH~page.css', $import);
}
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);
}
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);
}
}
|