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:
parent
f7ecb87af5
commit
e96eaf86e5
22
base.php
22
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'];
|
||||
|
|
18
index.php
18
index.php
|
@ -129,24 +129,10 @@
|
|||
<body>
|
||||
<?php
|
||||
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
|
||||
$data = getJson (true);
|
||||
|
||||
// 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
|
||||
echo $dot ($data);
|
||||
|
||||
echo serverSideRender ($data);
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
|
|
|
@ -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 ()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue