Add basic test to Json_renderer
This commit is contained in:
parent
655589d407
commit
6213a0e499
63
test/jsonTest.php
Normal file
63
test/jsonTest.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?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__) . "/../JSON_renderer.php");
|
||||
|
||||
class JsonTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCompleteArray () {
|
||||
global $config;
|
||||
|
||||
$_SERVER["HTTP_USER_AGENT"] = "Firefox";
|
||||
$test = array ();
|
||||
$test = JSONRenderer::addCompleteArray ($test);
|
||||
$this->assertArrayHasKey ("c", $test);
|
||||
$this->assertArrayHasKey ("version", $test ["c"]);
|
||||
$this->assertArrayHasKey ("i18n", $test ["c"]);
|
||||
$this->assertArrayHasKey ("url", $test ["c"]);
|
||||
$this->assertArrayHasKey ("config", $test ["c"]);
|
||||
|
||||
$this->assertFalse ($test ["c"]["url"]["thumbnailUrl"] == $test ["c"]["url"]["coverUrl"]);
|
||||
|
||||
// The thumbnails should be the same as the covers
|
||||
$config['cops_thumbnail_handling'] = "1";
|
||||
$test = array ();
|
||||
$test = JSONRenderer::addCompleteArray ($test);
|
||||
|
||||
$this->assertTrue ($test ["c"]["url"]["thumbnailUrl"] == $test ["c"]["url"]["coverUrl"]);
|
||||
|
||||
// The thumbnails should be the same as the covers
|
||||
$config['cops_thumbnail_handling'] = "/images.png";
|
||||
$test = array ();
|
||||
$test = JSONRenderer::addCompleteArray ($test);
|
||||
|
||||
$this->assertEquals ("/images.png", $test ["c"]["url"]["thumbnailUrl"]);
|
||||
}
|
||||
|
||||
public function testGetBookContentArrayWithoutSeries () {
|
||||
$book = Book::getBookById(17);
|
||||
$test = JSONRenderer::getBookContentArray($book);
|
||||
|
||||
$this->assertEquals ("", $test ["seriesName"]);
|
||||
$this->assertEquals ("1.0", $test ["seriesIndex"]);
|
||||
$this->assertEquals ("", $test ["seriesCompleteName"]);
|
||||
$this->assertEquals ("", $test ["seriesurl"]);
|
||||
}
|
||||
|
||||
public function testGetBookContentArrayWithSeries () {
|
||||
$book = Book::getBookById(2);
|
||||
|
||||
$test = JSONRenderer::getBookContentArray($book);
|
||||
|
||||
$this->assertEquals ("Sherlock Holmes", $test ["seriesName"]);
|
||||
$this->assertEquals ("6.0", $test ["seriesIndex"]);
|
||||
$this->assertEquals ("Book 6.0 in the Sherlock Holmes series", $test ["seriesCompleteName"]);
|
||||
$this->assertStringEndsWith ("?page=7&id=1", $test ["seriesurl"]);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue