Add a proper test for server side rendering (can check syntax errors). re #171
This commit is contained in:
parent
be50ee2cb8
commit
7ae6041c29
5
base.php
5
base.php
|
@ -31,6 +31,11 @@ function serverSideRender ($data) {
|
||||||
"header" => $header,
|
"header" => $header,
|
||||||
"footer" => $footer,
|
"footer" => $footer,
|
||||||
"main" => $main));
|
"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
|
// Execute the template
|
||||||
if (!empty ($data)) {
|
if (!empty ($data)) {
|
||||||
return $dot ($data);
|
return $dot ($data);
|
||||||
|
|
|
@ -19,35 +19,50 @@ 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 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));
|
$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";
|
$_SERVER["HTTP_USER_AGENT"] = "Firefox";
|
||||||
global $config;
|
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 ();
|
$template = new doT ();
|
||||||
$dot = $template->template ($headcontent, NULL);
|
$tpl = $template->template ($headcontent, NULL);
|
||||||
$data = array("title" => $config['cops_title_default'],
|
$data = array("title" => $config['cops_title_default'],
|
||||||
"version" => VERSION,
|
"version" => VERSION,
|
||||||
"opds_url" => $config['cops_full_url'] . "feed.php",
|
"opds_url" => $config['cops_full_url'] . "feed.php",
|
||||||
"customHeader" => "",
|
"customHeader" => "",
|
||||||
"template" => getCurrentTemplate (),
|
"template" => $templateName,
|
||||||
"server_side_rendering" => useServerSideRendering (),
|
"server_side_rendering" => useServerSideRendering (),
|
||||||
"current_css" => getCurrentCss (),
|
"current_css" => getCurrentCss (),
|
||||||
"favico" => $config['cops_icon'],
|
"favico" => $config['cops_icon'],
|
||||||
"getjson_url" => "getJSON.php?" . addURLParameter (getQueryString (), "complete", 1));
|
"getjson_url" => "getJSON.php?" . addURLParameter (getQueryString (), "complete", 1));
|
||||||
|
|
||||||
$head = $dot ($data);
|
$head = $tpl ($data);
|
||||||
$this->assertContains ("<head>", $head);
|
$this->assertContains ("<head>", $head);
|
||||||
$this->assertContains ("</head>", $head);
|
$this->assertContains ("</head>", $head);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function providerTemplate ()
|
||||||
|
{
|
||||||
|
return array (
|
||||||
|
array ("bootstrap"),
|
||||||
|
array ("default")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testLocalize ()
|
public function testLocalize ()
|
||||||
{
|
{
|
||||||
$this->assertEquals ("Authors", localize ("authors.title"));
|
$this->assertEquals ("Authors", localize ("authors.title"));
|
||||||
|
|
Loading…
Reference in a new issue