mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
Run template tests over non-cached data as well
git-svn-id: file:///svn/phpbb/trunk@9092 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
d26f38c4e0
commit
f4c079a62b
2 changed files with 55 additions and 8 deletions
|
@ -29,6 +29,7 @@ $config += array(
|
|||
class phpbb_template_template_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $template;
|
||||
private static $ran_non_cached = false;
|
||||
|
||||
private function display($handle)
|
||||
{
|
||||
|
@ -40,10 +41,18 @@ class phpbb_template_template_test extends PHPUnit_Framework_TestCase
|
|||
return $contents;
|
||||
}
|
||||
|
||||
private function setup_engine()
|
||||
private function setup_engine($clear_cache = false)
|
||||
{
|
||||
$this->template = new template;
|
||||
$this->template->set_custom_template(dirname(__FILE__) . '/templates/', 'tests');
|
||||
|
||||
if ($clear_cache)
|
||||
{
|
||||
foreach (glob($this->template->cachepath . '*') as $file)
|
||||
{
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
|
@ -55,13 +64,6 @@ class phpbb_template_template_test extends PHPUnit_Framework_TestCase
|
|||
{
|
||||
$this->markTestSkipped("Template cache directory is not writable.");
|
||||
}
|
||||
|
||||
$this->error_reporting = error_reporting(error_reporting() & ~E_NOTICE);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
error_reporting($this->error_reporting);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,6 +128,12 @@ class phpbb_template_template_test extends PHPUnit_Framework_TestCase
|
|||
array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y'))),
|
||||
"first\n0\n0\nx\n1\n1\ny\nlast",
|
||||
),
|
||||
array(
|
||||
'loop_vars.html',
|
||||
array(),
|
||||
array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())),
|
||||
"first\n0\n0\nx\n1\n1\ny\nlast\n0\n1",
|
||||
),
|
||||
array(
|
||||
'define.html',
|
||||
array(),
|
||||
|
@ -138,14 +146,48 @@ class phpbb_template_template_test extends PHPUnit_Framework_TestCase
|
|||
array(),
|
||||
trim(str_repeat("pass\n", 38)),
|
||||
),
|
||||
array(
|
||||
'include.html',
|
||||
array('VARIABLE' => 'value'),
|
||||
array(),
|
||||
'value',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider template_data
|
||||
*/
|
||||
public function test_template_no_cache($file, array $vars, array $block_vars, $expected)
|
||||
{
|
||||
$this->setup_engine(true);
|
||||
$this->template->set_filenames(array('test' => $file));
|
||||
$this->template->assign_vars($vars);
|
||||
|
||||
foreach ($block_vars as $block => $loops)
|
||||
{
|
||||
foreach ($loops as $_vars)
|
||||
{
|
||||
$this->template->assign_block_vars($block, $_vars);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, $this->display('test'), "Testing $file");
|
||||
|
||||
self::$ran_non_cached = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider template_data
|
||||
*/
|
||||
public function test_template($file, array $vars, array $block_vars, $expected)
|
||||
{
|
||||
if (!self::$ran_non_cached)
|
||||
{
|
||||
$this->fail('Non cached tests failed to run first');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setup_engine();
|
||||
$this->template->set_filenames(array('test' => $file));
|
||||
$this->template->assign_vars($vars);
|
||||
|
|
|
@ -8,4 +8,9 @@
|
|||
{loop.VARIABLE}
|
||||
|
||||
<!-- IF loop.S_LAST_ROW -->last<!-- ENDIF -->
|
||||
<!-- BEGIN inner -->
|
||||
|
||||
{inner.S_ROW_NUM}
|
||||
|
||||
<!-- END inner -->
|
||||
<!-- END loop -->
|
||||
|
|
Loading…
Add table
Reference in a new issue