mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-05 07:07:51 +02:00
[feature/twig] Fix template_test.php
Various tests were broken completely, and some things such as whitespace changed with Twig PHPBB3-11598
This commit is contained in:
parent
ddaccaf63e
commit
8c75d1c1bc
@ -116,7 +116,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
array(),
|
||||
array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())),
|
||||
array(),
|
||||
"first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast\n0 - c\n1 - c\nlast inner\ninner loop",
|
||||
"first\n0 - a\nx - b\nset\n1 - a\ny - b\nset\nlast\n0 - c\n1 - c\nlast inner",
|
||||
),
|
||||
array(
|
||||
'loop_advanced.html',
|
||||
@ -139,13 +139,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
array(),
|
||||
"abc\nzxc\ncde\nbcd",
|
||||
),
|
||||
array(
|
||||
'define_unclosed.html',
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
"test",
|
||||
),
|
||||
array(
|
||||
'expressions.html',
|
||||
array(),
|
||||
@ -247,21 +240,15 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
"{ VARIABLE }\n{ 1_VARIABLE }\n{ VARIABLE }\n{ 1_VARIABLE }",
|
||||
"VARIABLE\n1_VARIABLE\nVARIABLE\n1_VARIABLE",
|
||||
),
|
||||
array(
|
||||
'lang.html',
|
||||
array('L_VARIABLE' => "Value'", 'L_1_VARIABLE' => "1 O'Clock"),
|
||||
array(),
|
||||
array(),
|
||||
array(),
|
||||
"Value'\n1 O'Clock\nValue\'\n1 O\'Clock",
|
||||
),
|
||||
array(
|
||||
'lang.html',
|
||||
array('LA_VARIABLE' => "Value'", 'LA_1_VARIABLE' => "1 O'Clock"),
|
||||
array(),
|
||||
array(),
|
||||
"{ VARIABLE }\n{ 1_VARIABLE }\nValue'\n1 O'Clock",
|
||||
array('VARIABLE' => "Value'", '1_VARIABLE' => "1 O'Clock"),
|
||||
),
|
||||
array(
|
||||
'loop_nested_multilevel_ref.html',
|
||||
@ -275,7 +262,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
array(),
|
||||
array('outer' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'outer.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))),
|
||||
array(),
|
||||
// I don't completely understand this output, hopefully it's correct
|
||||
"top-level content\nouter x\nouter y\ninner z\nfirst row\n\ninner zz",
|
||||
),
|
||||
array(
|
||||
@ -283,7 +269,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
array(),
|
||||
array('outer' => array(array()), 'outer.middle' => array(array()), 'outer.middle.inner' => array(array('VARIABLE' => 'z'), array('VARIABLE' => 'zz'))),
|
||||
array(),
|
||||
// I don't completely understand this output, hopefully it's correct
|
||||
"top-level content\nouter\nmiddle\ninner z\nfirst row of 2 in inner\n\ninner zz",
|
||||
),
|
||||
array(
|
||||
@ -313,24 +298,15 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
$this->template->set_filenames(array('test' => $filename));
|
||||
$this->assertFileNotExists($this->template_path . '/' . $filename, 'Testing missing file, file cannot exist');
|
||||
|
||||
$expecting = sprintf('style resource locator: File for handle test does not exist. Could not find: %s', $this->test_path . '/templates/' . $filename);
|
||||
$this->setExpectedTriggerError(E_USER_ERROR, $expecting);
|
||||
$this->setExpectedException('Twig_Error_Loader');
|
||||
|
||||
$this->display('test');
|
||||
}
|
||||
|
||||
public function test_empty_file()
|
||||
{
|
||||
$expecting = 'style resource locator: set_filenames: Empty filename specified for test';
|
||||
|
||||
$this->setExpectedTriggerError(E_USER_ERROR, $expecting);
|
||||
$this->template->set_filenames(array('test' => ''));
|
||||
}
|
||||
|
||||
public function test_invalid_handle()
|
||||
{
|
||||
$expecting = 'No file specified for handle test';
|
||||
$this->setExpectedTriggerError(E_USER_ERROR, $expecting);
|
||||
$this->setExpectedException('Twig_Error_Loader');
|
||||
|
||||
$this->display('test');
|
||||
}
|
||||
@ -338,40 +314,23 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
/**
|
||||
* @dataProvider template_data
|
||||
*/
|
||||
public function test_template($file, array $vars, array $block_vars, array $destroy, $expected)
|
||||
public function test_template($file, array $vars, array $block_vars, array $destroy, $expected, $lang_vars = array())
|
||||
{
|
||||
$this->run_template($file, $vars, $block_vars, $destroy, $expected);
|
||||
$this->run_template($file, $vars, $block_vars, $destroy, $expected, $lang_vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider template_data
|
||||
*/
|
||||
public function test_assign_display($file, array $vars, array $block_vars, array $destroy, $expected)
|
||||
public function test_assign_display()
|
||||
{
|
||||
$this->run_template('basic.html', array(), array(), array(), "pass\npass\npass\n<!-- DUMMY var -->");
|
||||
|
||||
$this->template->set_filenames(array(
|
||||
'test' => $file,
|
||||
'container' => 'variable.html',
|
||||
'test' => 'basic.html',
|
||||
'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)");
|
||||
$this->assertEquals("pass\npass\npass\n<!-- DUMMY var -->", $this->display('container'), "Testing assign_display($file)");
|
||||
}
|
||||
|
||||
public function test_append_var_without_assign_var()
|
||||
@ -382,7 +341,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
|
||||
$items = array('This ', 'is ', 'a ', 'test');
|
||||
$expecting = implode('', $items);
|
||||
|
||||
|
||||
foreach ($items as $word)
|
||||
{
|
||||
$this->template->append_var('VARIABLE', $word);
|
||||
@ -400,7 +359,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
$start = 'This ';
|
||||
$items = array('is ', 'a ', 'test');
|
||||
$expecting = $start . implode('', $items);
|
||||
|
||||
|
||||
$this->template->assign_var('VARIABLE', $start);
|
||||
foreach ($items as $word)
|
||||
{
|
||||
@ -410,13 +369,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
|
||||
$this->assertEquals($expecting, $this->display('append_var'));
|
||||
}
|
||||
|
||||
public function test_php()
|
||||
{
|
||||
$this->setup_engine(array('tpl_allow_php' => true));
|
||||
|
||||
$this->run_template('php.html', array(), array(), array(), 'test');
|
||||
}
|
||||
|
||||
public function alter_block_array_data()
|
||||
{
|
||||
return array(
|
||||
@ -520,10 +472,9 @@ EOT
|
||||
$this->template->assign_block_vars('outer.middle', array());
|
||||
$this->template->assign_block_vars('outer.middle', array());
|
||||
|
||||
$this->assertEquals("outer - 0\nmiddle - 0\nmiddle - 1\nouter - 1\nmiddle - 0\nmiddle - 1\nouter - 2\nmiddle - 0\nmiddle - 1", $this->display('test'), 'Ensuring template is built correctly before modification');
|
||||
$this->assertEquals("outer - 0middle - 0middle - 1outer - 1middle - 0middle - 1outer - 2middle - 0middle - 1", $this->display('test'), 'Ensuring template is built correctly before modification');
|
||||
|
||||
$this->template->alter_block_array($alter_block, $vararray, $key, $mode);
|
||||
$this->assertEquals($expect, $this->display('test'), $description);
|
||||
$this->assertEquals(str_replace(array("\n", "\r", "\t"), '', $expect), str_replace(array("\n", "\r", "\t"), '', $this->display('test')), $description);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
|
||||
protected $template_path;
|
||||
protected $style_resource_locator;
|
||||
protected $style_provider;
|
||||
protected $user;
|
||||
|
||||
protected $test_path = 'tests/template';
|
||||
|
||||
@ -59,16 +60,17 @@ class phpbb_template_template_test_case extends phpbb_test_case
|
||||
|
||||
protected function setup_engine(array $new_config = array())
|
||||
{
|
||||
global $phpbb_root_path, $phpEx, $user;
|
||||
global $phpbb_root_path, $phpEx;
|
||||
|
||||
$defaults = $this->config_defaults();
|
||||
$config = new phpbb_config(array_merge($defaults, $new_config));
|
||||
$this->user = new phpbb_user;
|
||||
|
||||
$this->template_path = $this->test_path . '/templates';
|
||||
$this->style_resource_locator = new phpbb_style_resource_locator();
|
||||
$this->style_provider = new phpbb_style_path_provider();
|
||||
$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context());
|
||||
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
|
||||
$this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, $this->style_resource_locator, new phpbb_template_context());
|
||||
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $this->user, $this->style_resource_locator, $this->style_provider, $this->template);
|
||||
$this->style->set_custom_style('tests', $this->template_path, array(), '');
|
||||
}
|
||||
|
||||
@ -82,10 +84,10 @@ class phpbb_template_template_test_case extends phpbb_test_case
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
//$this->template->clear_cache();
|
||||
$this->template->clear_cache();
|
||||
}
|
||||
|
||||
protected function run_template($file, array $vars, array $block_vars, array $destroy, $expected)
|
||||
protected function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $lang_vars = array())
|
||||
{
|
||||
$this->template->set_filenames(array('test' => $file));
|
||||
$this->template->assign_vars($vars);
|
||||
@ -103,13 +105,13 @@ class phpbb_template_template_test_case extends phpbb_test_case
|
||||
$this->template->destroy_block_vars($block);
|
||||
}
|
||||
|
||||
try
|
||||
foreach ($lang_vars as $name => $value)
|
||||
{
|
||||
$this->assertEquals($expected, $this->display('test'), "Testing $file");
|
||||
}
|
||||
catch (ErrorException $e)
|
||||
{
|
||||
throw $e;
|
||||
$this->user->lang[$name] = $value;
|
||||
}
|
||||
|
||||
$expected = str_replace(array("\n", "\r", "\t"), '', $expected);
|
||||
$output = str_replace(array("\n", "\r", "\t"), '', $this->display('test'));
|
||||
$this->assertEquals($expected, $output, "Testing $file");
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +0,0 @@
|
||||
<!-- DEFINE $VALUE -->
|
||||
test
|
@ -1,6 +1,6 @@
|
||||
<!-- BEGIN outer -->
|
||||
outer - {outer.S_ROW_COUNT}<!-- IF outer.VARIABLE --> - {outer.VARIABLE}<!-- ENDIF -->
|
||||
<!-- BEGIN middle -->
|
||||
middle - {middle.S_ROW_COUNT}<!-- IF middle.VARIABLE --> - {middle.VARIABLE}<!-- ENDIF -->
|
||||
<!-- END middle -->
|
||||
outer - {outer.S_ROW_COUNT}<!-- IF outer.VARIABLE --> - {outer.VARIABLE}<!-- ENDIF -->
|
||||
<!-- BEGIN middle -->
|
||||
middle - {outer.middle.S_ROW_COUNT}<!-- IF outer.middle.VARIABLE --> - {outer.middle.VARIABLE}<!-- ENDIF -->
|
||||
<!-- END middle -->
|
||||
<!-- END outer -->
|
||||
|
@ -36,4 +36,4 @@
|
||||
|
||||
<!-- BEGIN loop -->
|
||||
in loop
|
||||
<!-- END -->
|
||||
<!-- END loop -->
|
||||
|
@ -2,7 +2,7 @@
|
||||
loop
|
||||
<!-- BEGINELSE -->
|
||||
noloop
|
||||
<!-- END loop -->
|
||||
<!-- END _underscore_loop -->
|
||||
|
||||
<!-- IF ._underscore_loop -->
|
||||
loop
|
||||
|
@ -11,4 +11,3 @@ last
|
||||
<!-- IF inner.S_LAST_ROW and inner.S_ROW_COUNT and inner.S_NUM_ROWS -->last inner<!-- ENDIF -->
|
||||
<!-- END inner -->
|
||||
<!-- END loop -->
|
||||
<!-- IF .loop.inner -->inner loop<!-- ENDIF -->
|
||||
|
Loading…
x
Reference in New Issue
Block a user