Add a test for function creation. I can't manage to make it fail when needed. Still I'll commit anyway !

This commit is contained in:
Sébastien Lucas 2014-01-06 21:24:11 +01:00
parent f7ecb87af5
commit e96eaf86e5
3 changed files with 31 additions and 16 deletions

View file

@ -16,6 +16,28 @@ function useServerSideRendering () {
return preg_match("/" . $config['cops_server_side_render'] . "/", $_SERVER['HTTP_USER_AGENT']); 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 () { function getQueryString () {
if ( isset($_SERVER['QUERY_STRING']) ) { if ( isset($_SERVER['QUERY_STRING']) ) {
return $_SERVER['QUERY_STRING']; return $_SERVER['QUERY_STRING'];

View file

@ -129,24 +129,10 @@
<body> <body>
<?php <?php
if (useServerSideRendering ()) { if (useServerSideRendering ()) {
// 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');
// Get the data // Get the data
$data = getJson (true); $data = getJson (true);
// Generate the function for the template echo serverSideRender ($data);
$template = new doT ();
$dot = $template->template ($page, array ("bookdetail" => $bookdetail,
"header" => $header,
"footer" => $footer,
"main" => $main));
// Execute the template
echo $dot ($data);
} }
?> ?>
</body> </body>

View file

@ -7,6 +7,7 @@
*/ */
require_once (dirname(__FILE__) . "/config_test.php"); require_once (dirname(__FILE__) . "/config_test.php");
require_once (dirname(__FILE__) . "/../resources/doT-php/doT.php");
require_once (dirname(__FILE__) . "/../base.php"); require_once (dirname(__FILE__) . "/../base.php");
class BaseTest extends PHPUnit_Framework_TestCase class BaseTest extends PHPUnit_Framework_TestCase
@ -18,6 +19,12 @@ class BaseTest extends PHPUnit_Framework_TestCase
$this->assertEquals ("?key=value&otherKey=&db=0", addURLParameter ("?key=value&otherKey", "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 () public function testLocalize ()
{ {
$this->assertEquals ("Authors", localize ("authors.title")); $this->assertEquals ("Authors", localize ("authors.title"));