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 'test_framework/framework.php';
require_once '../phpBB/includes/constants.php'; require_once '../phpBB/includes/core/bootstrap.php';
require_once '../phpBB/includes/functions.php';
require_once '../phpBB/includes/template.php';
class phpbb_template_template_test extends phpbb_test_case 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; private $template_path;
// Keep the contents of the cache for debugging? // Keep the contents of the cache for debugging?
const PRESERVE_CACHE = false; const PRESERVE_CACHE = true;
private function display($handle) private function display($handle)
{ {
@ -41,7 +39,7 @@ class phpbb_template_template_test extends phpbb_test_case
private function setup_engine() private function setup_engine()
{ {
$this->template_path = dirname(__FILE__) . '/templates'; $this->template_path = dirname(__FILE__) . '/templates';
$this->template = new template; $this->template = new phpbb_template;
$this->template->set_custom_template($this->template_path, 'tests'); $this->template->set_custom_template($this->template_path, 'tests');
} }
@ -60,8 +58,9 @@ class phpbb_template_template_test extends phpbb_test_case
unlink($file); unlink($file);
} }
$GLOBALS['config'] = array( phpbb::$config = array(
'load_tplcompile' => true 'load_tplcompile' => true,
'tpl_allow_php' => false,
); );
} }
@ -192,7 +191,7 @@ class phpbb_template_template_test extends phpbb_test_case
array( array(
'define.html', 'define.html',
array(), 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(), array(),
"xyz\nabc\n\n00\n11\n22\n33\n44\n55\n66\n\n144\n144", "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->template->set_filenames(array('test' => $filename));
$this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist'); $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)); $expecting = sprintf('template->_tpl_load_file(): File %s does not exist or is empty', realpath($this->template_path) . '/' . $filename);
$this->display('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;
}
}
} }
public function test_empty_file() public function test_empty_file()
{ {
$this->setExpectedTriggerError(E_USER_ERROR, sprintf("template->set_filenames: Empty filename specified for test")); $expecting = 'template->set_filenames: Empty filename specified for test';
$this->template->set_filenames(array('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() public function test_invalid_handle()
{ {
$this->setExpectedTriggerError(E_USER_ERROR, sprintf("template->_tpl_load(): No file specified for handle test")); $expecting = 'template->_tpl_load(): No file specified for handle test';
$this->display('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) 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->template->destroy_block_vars($block);
} }
$this->assertEquals($expected, $this->display('test'), "Testing $file"); try
$this->assertFileExists($cache_file); {
$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 // For debugging
if (self::PRESERVE_CACHE) if (self::PRESERVE_CACHE)
@ -363,9 +415,7 @@ class phpbb_template_template_test extends phpbb_test_case
public function test_php() public function test_php()
{ {
global $config; phpbb::$config['tpl_allow_php'] = true;
$config['tpl_allow_php'] = 1;
$cache_file = $this->template->cachepath . 'php.html.' . PHP_EXT; $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); $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() 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(); $cwd = getcwd();
chdir(dirname(__FILE__) . '/templates'); 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->template->set_filenames(array('test' => 'includephp.html'));
$this->assertEquals('testing included php', $this->display('test'), "Testing $file"); $this->assertEquals('testing included php', $this->display('test'), "Testing $file");
chdir($cwd); chdir($cwd);
unset($config['tpl_allow_php']); phpbb::$config['tpl_allow_php'] = false;
} }
*/
public static function alter_block_array_data() public static function alter_block_array_data()
{ {
return array( return array(

View file

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

View file

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