mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
More tests
git-svn-id: file:///svn/phpbb/trunk@9100 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
500eb05c48
commit
6e2d2f85b5
7 changed files with 147 additions and 9 deletions
|
@ -25,12 +25,17 @@ class phpbb_template_template_test extends PHPUnit_Framework_TestCase
|
|||
{
|
||||
ob_start();
|
||||
$this->assertTrue($this->template->display($handle, false));
|
||||
$contents = str_replace("\n\n", "\n", implode("\n", array_map('trim', explode("\n", trim(ob_get_contents())))));
|
||||
$contents = self::trim_template_result(ob_get_contents());
|
||||
ob_end_clean();
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
private static function trim_template_result($result)
|
||||
{
|
||||
return str_replace("\n\n", "\n", implode("\n", array_map('trim', explode("\n", trim($result)))));
|
||||
}
|
||||
|
||||
private function setup_engine()
|
||||
{
|
||||
$this->template = new template;
|
||||
|
@ -68,6 +73,7 @@ class phpbb_template_template_test extends PHPUnit_Framework_TestCase
|
|||
'', // File
|
||||
array(), // vars
|
||||
array(), // block vars
|
||||
array(), // destroy
|
||||
'', // Expected result
|
||||
),
|
||||
*/
|
||||
|
@ -75,84 +81,132 @@ class phpbb_template_template_test extends PHPUnit_Framework_TestCase
|
|||
'variable.html',
|
||||
array('VARIABLE' => 'value'),
|
||||
array(),
|
||||
array(),
|
||||
'value',
|
||||
),
|
||||
array(
|
||||
'if.html',
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
'0',
|
||||
),
|
||||
array(
|
||||
'if.html',
|
||||
array('S_VALUE' => true),
|
||||
array(),
|
||||
array(),
|
||||
'1',
|
||||
),
|
||||
array(
|
||||
'if.html',
|
||||
array('S_VALUE' => true, 'S_OTHER_VALUE' => true),
|
||||
array(),
|
||||
array(),
|
||||
'1',
|
||||
),
|
||||
array(
|
||||
'if.html',
|
||||
array('S_VALUE' => false, 'S_OTHER_VALUE' => true),
|
||||
array(),
|
||||
array(),
|
||||
'2',
|
||||
),
|
||||
array(
|
||||
'loop.html',
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
"noloop\nnoloop",
|
||||
),
|
||||
array(
|
||||
'loop.html',
|
||||
array(),
|
||||
array('loop' => array(array())),
|
||||
array(),
|
||||
"loop\nloop",
|
||||
),
|
||||
array(
|
||||
'loop.html',
|
||||
array(),
|
||||
array('loop' => array(array(), array())),
|
||||
array(),
|
||||
"loop\nloop\nloop\nloop",
|
||||
),
|
||||
array(
|
||||
'loop_vars.html',
|
||||
array(),
|
||||
array('loop' => array(array('VARIABLE' => 'x'))),
|
||||
"first\n0\n0\n1\nx\nlast",
|
||||
array(),
|
||||
"first\n0\n0\n1\nx\nset\nlast",
|
||||
),
|
||||
array(
|
||||
'loop_vars.html',
|
||||
array(),
|
||||
array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y'))),
|
||||
"first\n0\n0\n2\nx\n1\n1\n2\ny\nlast",
|
||||
array(),
|
||||
"first\n0\n0\n2\nx\nset\n1\n1\n2\ny\nset\nlast",
|
||||
),
|
||||
array(
|
||||
'loop_vars.html',
|
||||
array(),
|
||||
array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())),
|
||||
"first\n0\n0\n2\nx\n1\n1\n2\ny\nlast\n0\n1",
|
||||
array(),
|
||||
"first\n0\n0\n2\nx\nset\n1\n1\n2\ny\nset\nlast\n0\n\n1\nlast inner\ninner loop",
|
||||
),
|
||||
array(
|
||||
'loop_advanced.html',
|
||||
array(),
|
||||
array('loop' => array(array(), array(), array(), array(), array(), array(), array())),
|
||||
array(),
|
||||
"101234561\n101234561\n101234561\n1234561\n1\n101\n234\n10\n561\n561",
|
||||
),
|
||||
array(
|
||||
'define.html',
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
"xyz\nabc",
|
||||
),
|
||||
array(
|
||||
'expressions.html',
|
||||
array(),
|
||||
array(),
|
||||
trim(str_repeat("pass\n", 38)),
|
||||
array(),
|
||||
trim(str_repeat("pass\n", 40)),
|
||||
),
|
||||
array(
|
||||
'php.html',
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
'<!-- echo "test"; -->',
|
||||
),
|
||||
array(
|
||||
'include.html',
|
||||
array('VARIABLE' => 'value'),
|
||||
array(),
|
||||
array(),
|
||||
'value',
|
||||
),
|
||||
array(
|
||||
'loop_vars.html',
|
||||
array(),
|
||||
array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())),
|
||||
array('loop'),
|
||||
'',
|
||||
),
|
||||
array(
|
||||
'loop_vars.html',
|
||||
array(),
|
||||
array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())),
|
||||
array('loop.inner'),
|
||||
"first\n0\n0\n2\nx\nset\n1\n1\n2\ny\nset\nlast",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
private function run_template($file, array $vars, array $block_vars, $expected, $cache_file)
|
||||
private function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $cache_file)
|
||||
{
|
||||
$this->template->set_filenames(array('test' => $file));
|
||||
$this->template->assign_vars($vars);
|
||||
|
@ -165,6 +219,11 @@ class phpbb_template_template_test extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
}
|
||||
|
||||
foreach ($destroy as $block)
|
||||
{
|
||||
$this->template->destroy_block_vars($block);
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, $this->display('test'), "Testing $file");
|
||||
$this->assertFileExists($cache_file);
|
||||
}
|
||||
|
@ -172,18 +231,82 @@ class phpbb_template_template_test extends PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* @dataProvider template_data
|
||||
*/
|
||||
public function test_template($file, array $vars, array $block_vars, $expected)
|
||||
public function test_template($file, array $vars, array $block_vars, array $destroy, $expected)
|
||||
{
|
||||
$cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.' . PHP_EXT;
|
||||
|
||||
$this->assertFileNotExists($cache_file);
|
||||
|
||||
$this->run_template($file, $vars, $block_vars, $expected, $cache_file);
|
||||
$this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file);
|
||||
|
||||
// Reset the engine state
|
||||
$this->setup_engine();
|
||||
|
||||
$this->run_template($file, $vars, $block_vars, $expected, $cache_file);
|
||||
$this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider template_data
|
||||
*/
|
||||
public function test_assign_display($file, array $vars, array $block_vars, array $destroy, $expected)
|
||||
{
|
||||
$this->template->set_filenames(array(
|
||||
'test' => $file,
|
||||
'container' => 'variable.html',
|
||||
));
|
||||
$this->template->assign_vars($vars);
|
||||
|
||||
foreach ($block_vars as $block => $loops)
|
||||
{
|
||||
foreach ($loops as $_vars)
|
||||
{
|
||||
$this->template->assign_block_vars($block, $_vars);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($destroy as $block)
|
||||
{
|
||||
$this->template->destroy_block_vars($block);
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, self::trim_template_result($this->template->assign_display('test')), "Testing assign_display($file)");
|
||||
|
||||
$this->template->assign_display('test', 'VARIABLE', false);
|
||||
$this->assertEquals($expected, $this->display('container'), "Testing assign_display($file)");
|
||||
}
|
||||
|
||||
public function test_php()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$config['tpl_allow_php'] = 1;
|
||||
|
||||
$cache_file = $this->template->cachepath . 'php.html.' . PHP_EXT;
|
||||
|
||||
$this->assertFileNotExists($cache_file);
|
||||
|
||||
$this->run_template('php.html', array(), array(), array(), 'test', $cache_file);
|
||||
|
||||
unset($config['tpl_allow_php']);
|
||||
}
|
||||
|
||||
public function test_includephp()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$config['tpl_allow_php'] = 1;
|
||||
|
||||
$cwd = getcwd();
|
||||
chdir(dirname(__FILE__) . '/templates');
|
||||
|
||||
//$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']);
|
||||
}
|
||||
}
|
||||
?>
|
3
tests/template/templates/_dummy_include.php
Normal file
3
tests/template/templates/_dummy_include.php
Normal file
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
|
||||
echo "testing included php";
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
<!-- IF 32 is odd -->fail<!-- ELSE -->pass<!-- ENDIF -->
|
||||
|
||||
<!-- IF 32 is div by 16 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 24 == 24 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
|
@ -83,3 +84,5 @@
|
|||
<!-- IF 6 % 4 == 2 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF 24 mod 12 == 0 -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
||||
<!-- IF not (43 > 53) -->pass<!-- ELSE -->fail<!-- ENDIF -->
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<!-- IF S_VALUE -->
|
||||
1
|
||||
<!-- ELSEIF S_OTHER_VALUE -->
|
||||
2
|
||||
<!-- ELSE -->
|
||||
0
|
||||
<!-- ENDIF -->
|
||||
|
|
1
tests/template/templates/includephp.html
Normal file
1
tests/template/templates/includephp.html
Normal file
|
@ -0,0 +1 @@
|
|||
<!-- INCLUDEPHP _dummy_include.php -->
|
|
@ -9,10 +9,15 @@
|
|||
|
||||
{loop.VARIABLE}
|
||||
|
||||
<!-- IF loop.VARIABLE -->set<!-- ENDIF -->
|
||||
|
||||
<!-- IF loop.S_LAST_ROW -->last<!-- ENDIF -->
|
||||
<!-- BEGIN inner -->
|
||||
|
||||
{inner.S_ROW_NUM}
|
||||
|
||||
<!-- IF inner.S_LAST_ROW and inner.S_ROW_NUM and inner.S_NUM_ROWS -->last inner<!-- ENDIF -->
|
||||
|
||||
<!-- END inner -->
|
||||
<!-- END loop -->
|
||||
<!-- IF .loop.inner -->inner loop<!-- ENDIF -->
|
||||
|
|
1
tests/template/templates/php.html
Normal file
1
tests/template/templates/php.html
Normal file
|
@ -0,0 +1 @@
|
|||
<!-- PHP -->echo "test";<!-- ENDPHP -->
|
Loading…
Add table
Reference in a new issue