From 7ae6041c29b057a12d7190d1ce180aad64f6f022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Wed, 27 Aug 2014 10:02:15 +0200 Subject: [PATCH] Add a proper test for server side rendering (can check syntax errors). re #171 --- base.php | 5 +++++ test/baseTest.php | 31 +++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/base.php b/base.php index 22dbd6a..cd9d650 100644 --- a/base.php +++ b/base.php @@ -31,6 +31,11 @@ function serverSideRender ($data) { "header" => $header, "footer" => $footer, "main" => $main)); + // If there is a syntax error in the function created + // $dot will be equal to FALSE + if (!$dot) { + return FALSE; + } // Execute the template if (!empty ($data)) { return $dot ($data); diff --git a/test/baseTest.php b/test/baseTest.php index ab95f82..acf9414 100644 --- a/test/baseTest.php +++ b/test/baseTest.php @@ -19,35 +19,50 @@ class BaseTest extends PHPUnit_Framework_TestCase $this->assertEquals ("?key=value&otherKey=&db=0", addURLParameter ("?key=value&otherKey", "db", "0")); } - /* For now I can't manage to make phpunit fail if a syntax error happens ... */ - public function testServerSideRender () + /** + * FALSE is returned if the create_function failed (meaning there was a syntax error) + * @dataProvider providerTemplate + */ + public function testServerSideRender ($template) { + $_COOKIE["template"] = $template; $this->assertNull (serverSideRender (NULL)); } - /* The function for the head of the HTML catalog */ - public function testGenerateHeader () + /** + * The function for the head of the HTML catalog + * @dataProvider providerTemplate + */ + public function testGenerateHeader ($templateName) { $_SERVER["HTTP_USER_AGENT"] = "Firefox"; global $config; - $headcontent = file_get_contents(dirname(__FILE__) . '/../templates/' . getCurrentTemplate () . '/file.html'); + $headcontent = file_get_contents(dirname(__FILE__) . '/../templates/' . $templateName . '/file.html'); $template = new doT (); - $dot = $template->template ($headcontent, NULL); + $tpl = $template->template ($headcontent, NULL); $data = array("title" => $config['cops_title_default'], "version" => VERSION, "opds_url" => $config['cops_full_url'] . "feed.php", "customHeader" => "", - "template" => getCurrentTemplate (), + "template" => $templateName, "server_side_rendering" => useServerSideRendering (), "current_css" => getCurrentCss (), "favico" => $config['cops_icon'], "getjson_url" => "getJSON.php?" . addURLParameter (getQueryString (), "complete", 1)); - $head = $dot ($data); + $head = $tpl ($data); $this->assertContains ("", $head); $this->assertContains ("", $head); } + public function providerTemplate () + { + return array ( + array ("bootstrap"), + array ("default") + ); + } + public function testLocalize () { $this->assertEquals ("Authors", localize ("authors.title"));