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