1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-19 23:32:02 +02:00

Fix most of the template test suite :)

git-svn-id: file:///svn/phpbb/trunk@9588 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Chris Smith 2009-06-13 20:23:07 +00:00
parent fd1608ab82
commit 2839f3a964
3 changed files with 87 additions and 27 deletions

View File

@ -14,9 +14,7 @@ define('PHPBB_ROOT_PATH', '../phpBB/');
require_once 'test_framework/framework.php';
require_once '../phpBB/includes/constants.php';
require_once '../phpBB/includes/functions.php';
require_once '../phpBB/includes/template.php';
require_once '../phpBB/includes/core/bootstrap.php';
class phpbb_template_template_test extends phpbb_test_case
{
@ -24,7 +22,7 @@ class phpbb_template_template_test extends phpbb_test_case
private $template_path;
// Keep the contents of the cache for debugging?
const PRESERVE_CACHE = false;
const PRESERVE_CACHE = true;
private function display($handle)
{
@ -41,7 +39,7 @@ class phpbb_template_template_test extends phpbb_test_case
private function setup_engine()
{
$this->template_path = dirname(__FILE__) . '/templates';
$this->template = new template;
$this->template = new phpbb_template;
$this->template->set_custom_template($this->template_path, 'tests');
}
@ -60,8 +58,9 @@ class phpbb_template_template_test extends phpbb_test_case
unlink($file);
}
$GLOBALS['config'] = array(
'load_tplcompile' => true
phpbb::$config = array(
'load_tplcompile' => true,
'tpl_allow_php' => false,
);
}
@ -192,7 +191,7 @@ class phpbb_template_template_test extends phpbb_test_case
array(
'define.html',
array(),
array('loop' => array(array(), array(), array(), array(), array(), array(), array())),
array('loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())),
array(),
"xyz\nabc\n\n00\n11\n22\n33\n44\n55\n66\n\n144\n144",
),
@ -269,22 +268,63 @@ class phpbb_template_template_test extends phpbb_test_case
$this->template->set_filenames(array('test' => $filename));
$this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist');
$this->setExpectedTriggerError(E_USER_ERROR, sprintf('template->_tpl_load_file(): File %s does not exist or is empty', realpath($this->template_path) . '/' . $filename));
$this->display('test');
$expecting = sprintf('template->_tpl_load_file(): File %s does not exist or is empty', realpath($this->template_path) . '/' . $filename);
try
{
$this->display('test');
}
catch (ErrorException $e)
{
$this->assertEquals($expecting, $e->getMessage());
if ($expecting != $e->getMessage())
{
// Unrelated error message throw it out
throw $e;
}
}
}
public function test_empty_file()
{
$this->setExpectedTriggerError(E_USER_ERROR, sprintf("template->set_filenames: Empty filename specified for test"));
$this->template->set_filenames(array('test' => ''));
$expecting = 'template->set_filenames: Empty filename specified for test';
try
{
$this->template->set_filenames(array('test' => ''));
}
catch (ErrorException $e)
{
$this->assertEquals($expecting, $e->getMessage());
if ($expecting != $e->getMessage())
{
// Unrelated error message throw it out
throw $e;
}
}
}
public function test_invalid_handle()
{
$this->setExpectedTriggerError(E_USER_ERROR, sprintf("template->_tpl_load(): No file specified for handle test"));
$this->display('test');
}
$expecting = 'template->_tpl_load(): No file specified for handle test';
try
{
$this->display('test');
}
catch (ErrorException $e)
{
$this->assertEquals($expecting, $e->getMessage());
if ($expecting != $e->getMessage())
{
// Unrelated error message throw it out
throw $e;
}
}
}
private function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $cache_file)
{
@ -304,8 +344,20 @@ class phpbb_template_template_test extends phpbb_test_case
$this->template->destroy_block_vars($block);
}
$this->assertEquals($expected, $this->display('test'), "Testing $file");
$this->assertFileExists($cache_file);
try
{
$this->assertEquals($expected, $this->display('test'), "Testing $file");
$this->assertFileExists($cache_file);
}
catch (ErrorException $e)
{
if (file_exists($cache_file))
{
copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file));
}
throw $e;
}
// For debugging
if (self::PRESERVE_CACHE)
@ -363,9 +415,7 @@ class phpbb_template_template_test extends phpbb_test_case
public function test_php()
{
global $config;
$config['tpl_allow_php'] = 1;
phpbb::$config['tpl_allow_php'] = true;
$cache_file = $this->template->cachepath . 'php.html.' . PHP_EXT;
@ -373,28 +423,28 @@ class phpbb_template_template_test extends phpbb_test_case
$this->run_template('php.html', array(), array(), array(), 'test', $cache_file);
unset($config['tpl_allow_php']);
phpbb::$config['tpl_allow_php'] = false;
}
/*
public function test_includephp()
{
global $config;
phpbb::$config['tpl_allow_php'] = true;
$config['tpl_allow_php'] = 1;
$cache_file = $this->template->cachepath . 'includephp.html.' . PHP_EXT;
$cwd = getcwd();
chdir(dirname(__FILE__) . '/templates');
//$this->run_template('includephp.html', array(), array(), array(), 'testing included php', $cache_file);
$this->run_template('includephp.html', array(), array(), array(), 'testing included php', $cache_file);
$this->template->set_filenames(array('test' => 'includephp.html'));
$this->assertEquals('testing included php', $this->display('test'), "Testing $file");
chdir($cwd);
unset($config['tpl_allow_php']);
phpbb::$config['tpl_allow_php'] = false;
}
*/
public static function alter_block_array_data()
{
return array(

View File

@ -22,6 +22,9 @@
<!-- END loop -->
<!-- BEGIN test -->
<!-- BEGIN deep -->
<!-- BEGIN defines -->
<!-- DEFINE test.deep.defines.$VALUE = 12 * 12 -->
{test.deep.defines.$VALUE}
@ -33,3 +36,6 @@
<!-- UNDEFINE test.deep.defines.$VALUE -->
{test.deep.defines.$VALUE}
<!-- END defines -->
<!-- END deep -->
<!-- END test -->

View File

@ -5,3 +5,7 @@
<!-- ELSE -->
0
<!-- ENDIF -->
<!-- IF !!(S_VALUE > S_OTHER_VALUE) -->
0
<!-- ENDIF -->