Add a proper test for server side rendering (can check syntax errors). re #171

This commit is contained in:
Sébastien Lucas 2014-08-27 10:02:15 +02:00
parent be50ee2cb8
commit 7ae6041c29
2 changed files with 28 additions and 8 deletions

View file

@ -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);

View file

@ -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>", $head);
$this->assertContains ("</head>", $head);
}
public function providerTemplate ()
{
return array (
array ("bootstrap"),
array ("default")
);
}
public function testLocalize ()
{
$this->assertEquals ("Authors", localize ("authors.title"));