From e96eaf86e53f37effb5a2cb6b30f718a9e410529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Mon, 6 Jan 2014 21:24:11 +0100 Subject: [PATCH] Add a test for function creation. I can't manage to make it fail when needed. Still I'll commit anyway ! --- base.php | 22 ++++++++++++++++++++++ index.php | 18 ++---------------- test/baseTest.php | 7 +++++++ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/base.php b/base.php index 6bf75ea..65b5a50 100644 --- a/base.php +++ b/base.php @@ -16,6 +16,28 @@ function useServerSideRendering () { return preg_match("/" . $config['cops_server_side_render'] . "/", $_SERVER['HTTP_USER_AGENT']); } +function serverSideRender ($data) { + // Get the templates + $header = file_get_contents('templates/default/header.html'); + $footer = file_get_contents('templates/default/footer.html'); + $main = file_get_contents('templates/default/main.html'); + $bookdetail = file_get_contents('templates/default/bookdetail.html'); + $page = file_get_contents('templates/default/page.html'); + + // Generate the function for the template + $template = new doT (); + $dot = $template->template ($page, array ("bookdetail" => $bookdetail, + "header" => $header, + "footer" => $footer, + "main" => $main)); + // Execute the template + if (!empty ($data)) { + return $dot ($data); + } + + return NULL; +} + function getQueryString () { if ( isset($_SERVER['QUERY_STRING']) ) { return $_SERVER['QUERY_STRING']; diff --git a/index.php b/index.php index 2b68608..946834b 100644 --- a/index.php +++ b/index.php @@ -129,24 +129,10 @@ template ($page, array ("bookdetail" => $bookdetail, - "header" => $header, - "footer" => $footer, - "main" => $main)); - // Execute the template - echo $dot ($data); + + echo serverSideRender ($data); } ?> diff --git a/test/baseTest.php b/test/baseTest.php index afd9f62..74f81ba 100644 --- a/test/baseTest.php +++ b/test/baseTest.php @@ -7,6 +7,7 @@ */ require_once (dirname(__FILE__) . "/config_test.php"); +require_once (dirname(__FILE__) . "/../resources/doT-php/doT.php"); require_once (dirname(__FILE__) . "/../base.php"); class BaseTest extends PHPUnit_Framework_TestCase @@ -17,6 +18,12 @@ class BaseTest extends PHPUnit_Framework_TestCase $this->assertEquals ("?key=value&db=0", addURLParameter ("?key=value", "db", "0")); $this->assertEquals ("?key=value&otherKey=&db=0", addURLParameter ("?key=value&otherKey", "db", "0")); } + + /* For now I can't manager to make phpunit fail if a syntax error happens ... */ + public function testServerSideRender () + { + $this->assertNull (serverSideRender (NULL)); + } public function testLocalize () {