aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorNathaniel Guse <nathaniel.guse@gmail.com>2013-07-01 11:58:16 -0500
committerNathaniel Guse <nathaniel.guse@gmail.com>2013-07-01 11:58:16 -0500
commit8c75d1c1bc494220bed313e542902cdc22c5336f (patch)
treee58989d5ab61f8cf1f5fa4427f4a6e28b4839285 /tests
parentddaccaf63e8ae7ff5bd13b187fa40f3d089f02f0 (diff)
downloadforums-8c75d1c1bc494220bed313e542902cdc22c5336f.tar
forums-8c75d1c1bc494220bed313e542902cdc22c5336f.tar.gz
forums-8c75d1c1bc494220bed313e542902cdc22c5336f.tar.bz2
forums-8c75d1c1bc494220bed313e542902cdc22c5336f.tar.xz
forums-8c75d1c1bc494220bed313e542902cdc22c5336f.zip
[feature/twig] Fix template_test.php
Various tests were broken completely, and some things such as whitespace changed with Twig PHPBB3-11598
Diffstat (limited to 'tests')
-rw-r--r--tests/template/template_test.php87
-rw-r--r--tests/template/template_test_case.php24
-rw-r--r--tests/template/templates/define_unclosed.html2
-rw-r--r--tests/template/templates/loop_nested.html8
-rw-r--r--tests/template/templates/loop_size.html2
-rw-r--r--tests/template/templates/loop_underscore.html2
-rw-r--r--tests/template/templates/loop_vars.html1
7 files changed, 38 insertions, 88 deletions
diff --git a/tests/template/template_test.php b/tests/template/template_test.php
index a4748eb0b3..ad4c8fbd17 100644
--- a/tests/template/template_test.php
+++ b/tests/template/template_test.php
@@ -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',
@@ -140,13 +140,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
"abc\nzxc\ncde\nbcd",
),
array(
- 'define_unclosed.html',
- array(),
- array(),
- array(),
- "test",
- ),
- array(
'expressions.html',
array(),
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(),
- "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",
+ "Value'\n1 O'Clock\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);
}
-
-}
+} \ No newline at end of file
diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php
index 23ee8aae04..0a12dff9f4 100644
--- a/tests/template/template_test_case.php
+++ b/tests/template/template_test_case.php
@@ -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");
}
}
diff --git a/tests/template/templates/define_unclosed.html b/tests/template/templates/define_unclosed.html
deleted file mode 100644
index 1c975eab2b..0000000000
--- a/tests/template/templates/define_unclosed.html
+++ /dev/null
@@ -1,2 +0,0 @@
-<!-- DEFINE $VALUE -->
-test
diff --git a/tests/template/templates/loop_nested.html b/tests/template/templates/loop_nested.html
index 45b1ef85d4..3b5ffa5cac 100644
--- a/tests/template/templates/loop_nested.html
+++ b/tests/template/templates/loop_nested.html
@@ -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 -->
diff --git a/tests/template/templates/loop_size.html b/tests/template/templates/loop_size.html
index f1938441df..8f581cef10 100644
--- a/tests/template/templates/loop_size.html
+++ b/tests/template/templates/loop_size.html
@@ -36,4 +36,4 @@
<!-- BEGIN loop -->
in loop
-<!-- END -->
+<!-- END loop -->
diff --git a/tests/template/templates/loop_underscore.html b/tests/template/templates/loop_underscore.html
index dafce5dea6..4001007868 100644
--- a/tests/template/templates/loop_underscore.html
+++ b/tests/template/templates/loop_underscore.html
@@ -2,7 +2,7 @@
loop
<!-- BEGINELSE -->
noloop
-<!-- END loop -->
+<!-- END _underscore_loop -->
<!-- IF ._underscore_loop -->
loop
diff --git a/tests/template/templates/loop_vars.html b/tests/template/templates/loop_vars.html
index d94a0ae0f7..7d86d4b7b6 100644
--- a/tests/template/templates/loop_vars.html
+++ b/tests/template/templates/loop_vars.html
@@ -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 -->