diff --git a/test/jsonTest.php b/test/jsonTest.php new file mode 100644 index 0000000..c5f31a5 --- /dev/null +++ b/test/jsonTest.php @@ -0,0 +1,63 @@ + + */ + +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"]); + } +} \ No newline at end of file