aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/controller/helper_url_test.php5
-rw-r--r--tests/extension/metadata_manager_test.php3
-rw-r--r--tests/template/includephp_test.php17
-rw-r--r--tests/template/invalid_constructs_test.php87
-rw-r--r--tests/template/renderer_eval_test.php31
-rw-r--r--tests/template/subdir/includephp_from_subdir_test.php4
-rw-r--r--tests/template/template_compile_test.php31
-rw-r--r--tests/template/template_events_test.php20
-rw-r--r--tests/template/template_includejs_test.php15
-rw-r--r--tests/template/template_inheritance_test.php11
-rw-r--r--tests/template/template_locate_test.php68
-rw-r--r--tests/template/template_spacing_test.php87
-rw-r--r--tests/template/template_test.php111
-rw-r--r--tests/template/template_test_case.php66
-rw-r--r--tests/template/template_test_case_with_tree.php2
-rw-r--r--tests/template/templates/define_unclosed.html2
-rw-r--r--tests/template/templates/includejs.html2
-rw-r--r--tests/template/templates/invalid/include_nonexistent_file.html1
-rw-r--r--tests/template/templates/invalid/unknown_tag.html1
-rw-r--r--tests/template/templates/loop_nested.html8
-rw-r--r--tests/template/templates/loop_nested2.html6
-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
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php11
25 files changed, 104 insertions, 490 deletions
diff --git a/tests/controller/helper_url_test.php b/tests/controller/helper_url_test.php
index 2c22700ca6..e376efde66 100644
--- a/tests/controller/helper_url_test.php
+++ b/tests/controller/helper_url_test.php
@@ -45,15 +45,14 @@ class phpbb_controller_helper_url_test extends phpbb_test_case
*/
public function test_helper_url($route, $params, $is_amp, $session_id, $expected, $description)
{
- global $phpbb_dispatcher;
+ global $phpbb_dispatcher, $phpbb_root_path, $phpEx;
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
$this->style_resource_locator = new phpbb_style_resource_locator();
$this->user = $this->getMock('phpbb_user');
- $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $this->user, $this->style_resource_locator, new phpbb_template_context());
+ $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context());
$helper = new phpbb_controller_helper($this->template, $this->user, '', 'php');
$this->assertEquals($helper->url($route, $params, $is_amp, $session_id), $expected);
}
}
-
diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php
index d410333f09..bd88f396d9 100644
--- a/tests/extension/metadata_manager_test.php
+++ b/tests/extension/metadata_manager_test.php
@@ -42,12 +42,11 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
$this->user = new phpbb_user();
$this->table_prefix = 'phpbb_';
- $this->template = new phpbb_template(
+ $this->template = new phpbb_template_twig(
$this->phpbb_root_path,
$this->phpEx,
$this->config,
$this->user,
- new phpbb_style_resource_locator(),
new phpbb_template_context()
);
diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php
index f1012b6939..a3dc9bd5c5 100644
--- a/tests/template/includephp_test.php
+++ b/tests/template/includephp_test.php
@@ -15,9 +15,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case
{
$this->setup_engine(array('tpl_allow_php' => true));
- $cache_file = $this->template->cachepath . 'includephp_relative.html.php';
-
- $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php", $cache_file);
+ $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php");
$this->template->set_filenames(array('test' => 'includephp_relative.html'));
$this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");
@@ -27,9 +25,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case
{
$this->setup_engine(array('tpl_allow_php' => true));
- $cache_file = $this->template->cachepath . 'includephp_variables.html.php';
-
- $this->run_template('includephp_variables.html', array('TEMPLATES' => 'templates'), array(), array(), "Path includes variables.\ntesting included php", $cache_file);
+ $this->run_template('includephp_variables.html', array('TEMPLATES' => 'templates'), array(), array(), "Path includes variables.\ntesting included php");
$this->template->set_filenames(array('test' => 'includephp_variables.html'));
$this->assertEquals("Path includes variables.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");
@@ -37,11 +33,13 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case
public function test_includephp_absolute()
{
- $path_to_php = dirname(__FILE__) . '/templates/_dummy_include.php.inc';
+ global $phpbb_root_path;
+
+ $path_to_php = str_replace('\\', '/', dirname(__FILE__)) . '/templates/_dummy_include.php.inc';
$this->assertTrue(phpbb_is_absolute($path_to_php));
$template_text = "Path is absolute.\n<!-- INCLUDEPHP $path_to_php -->";
- $cache_dir = dirname($this->template->cachepath) . '/';
+ $cache_dir = dirname($phpbb_root_path . 'cache') . '/';
$fp = fopen($cache_dir . 'includephp_absolute.html', 'w');
fputs($fp, $template_text);
fclose($fp);
@@ -49,9 +47,8 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case
$this->setup_engine(array('tpl_allow_php' => true));
$this->style->set_custom_style('tests', $cache_dir, array(), '');
- $cache_file = $this->template->cachepath . 'includephp_absolute.html.php';
- $this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php", $cache_file);
+ $this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php");
$this->template->set_filenames(array('test' => 'includephp_absolute.html'));
$this->assertEquals("Path is absolute.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");
diff --git a/tests/template/invalid_constructs_test.php b/tests/template/invalid_constructs_test.php
deleted file mode 100644
index 19d192b8b6..0000000000
--- a/tests/template/invalid_constructs_test.php
+++ /dev/null
@@ -1,87 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2012 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
-*
-*/
-
-require_once dirname(__FILE__) . '/template_test_case.php';
-
-class phpbb_template_invalid_constructs_test extends phpbb_template_template_test_case
-{
- public function template_data()
- {
- return array(
- array(
- 'Unknown tag',
- 'invalid/unknown_tag.html',
- array(),
- array(),
- array(),
- 'invalid/output/unknown_tag.html',
- ),
- /*
- * Produces a parse error which is fatal, therefore
- * destroying the test suite.
- array(
- 'ENDIF without IF',
- 'invalid/endif_without_if.html',
- array(),
- array(),
- array(),
- 'invalid/output/endif_without_if.html',
- ),
- */
- );
- }
-
- public function template_data_error()
- {
- return array(
- array(
- 'Include a nonexistent file',
- 'invalid/include_nonexistent_file.html',
- array(),
- array(),
- array(),
- E_USER_ERROR,
- 'invalid/output/include_nonexistent_file.html',
- ),
- );
- }
-
- /**
- * @dataProvider template_data
- */
- public function test_template($description, $file, $vars, $block_vars, $destroy, $expected)
- {
- $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php';
-
- $this->assertFileNotExists($cache_file);
-
- $expected = file_get_contents(dirname(__FILE__) . '/templates/' . $expected);
- // apparently the template engine does not put
- // the trailing newline into compiled templates
- $expected = trim($expected);
- $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file);
- }
-
- /**
- * @dataProvider template_data_error
- */
- public function test_template_error($description, $file, $vars, $block_vars, $destroy, $error, $expected)
- {
- $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php';
-
- $this->assertFileNotExists($cache_file);
-
- $expected = file_get_contents(dirname(__FILE__) . '/templates/' . $expected);
- // apparently the template engine does not put
- // the trailing newline into compiled templates
- $expected = trim($expected);
- $this->setExpectedTriggerError($error, $expected);
- $this->run_template($file, $vars, $block_vars, $destroy, '', $cache_file);
- }
-}
diff --git a/tests/template/renderer_eval_test.php b/tests/template/renderer_eval_test.php
deleted file mode 100644
index 7ebb8b9bda..0000000000
--- a/tests/template/renderer_eval_test.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
-*
-*/
-
-class phpbb_template_renderer_eval_test extends phpbb_test_case
-{
- public function test_eval()
- {
- $compiled_code = '<a href="<?php echo \'Test\'; ?>">';
- $valid_code = '<a href="Test">';
- $context = new phpbb_template_context();
- $template = new phpbb_template_renderer_eval($compiled_code, NULL);
- ob_start();
- try
- {
- $template->render($context, array());
- }
- catch (Exception $exception)
- {
- ob_end_clean();
- throw $exception;
- }
- $output = ob_get_clean();
- $this->assertEquals($valid_code, $output);
- }
-}
diff --git a/tests/template/subdir/includephp_from_subdir_test.php b/tests/template/subdir/includephp_from_subdir_test.php
index 517cb85a30..6f9bc1efa6 100644
--- a/tests/template/subdir/includephp_from_subdir_test.php
+++ b/tests/template/subdir/includephp_from_subdir_test.php
@@ -19,9 +19,7 @@ class phpbb_template_subdir_includephp_from_subdir_test extends phpbb_template_t
{
$this->setup_engine(array('tpl_allow_php' => true));
- $cache_file = $this->template->cachepath . 'includephp_relative.html.php';
-
- $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php", $cache_file);
+ $this->run_template('includephp_relative.html', array(), array(), array(), "Path is relative to board root.\ntesting included php");
$this->template->set_filenames(array('test' => 'includephp_relative.html'));
$this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");
diff --git a/tests/template/template_compile_test.php b/tests/template/template_compile_test.php
deleted file mode 100644
index 7393fc1747..0000000000
--- a/tests/template/template_compile_test.php
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
-*
-*/
-
-require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
-
-class phpbb_template_template_compile_test extends phpbb_test_case
-{
- private $template_compile;
- private $template_path;
-
- protected function setUp()
- {
- $this->template_compile = new phpbb_template_compile(false, null, $this->style_resource_locator, '');
- $this->template_path = dirname(__FILE__) . '/templates';
- }
-
- public function test_in_phpbb()
- {
- $output = $this->template_compile->compile_file($this->template_path . '/trivial.html');
- $this->assertTrue(strlen($output) > 0);
- $statements = explode(';', $output);
- $first_statement = $statements[0];
- $this->assertTrue(!!preg_match('#if.*defined.*IN_PHPBB.*exit#', $first_statement));
- }
-}
diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php
index 0ac50c7f2b..f7bcd2dcc6 100644
--- a/tests/template/template_events_test.php
+++ b/tests/template/template_events_test.php
@@ -54,11 +54,9 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c
array(),
array(),
array(),
-'Kappa test event in all
-Omega test event in all
-Zeta test event in all
-Kappa test event in silver
-Omega test event in silver',
+'Kappa test event in silver
+Omega test event in silver
+Zeta test event in all',
),
array(
'Template event with inheritance - child',
@@ -68,10 +66,9 @@ Omega test event in silver',
array(),
array(),
array(),
-'Kappa test event in all
-Omega test event in all
-Zeta test event in all
-Kappa test event in silver_inherit',
+'Kappa test event in silver_inherit
+Omega test event in silver
+Zeta test event in all',
),
array(
'Definition in parent style',
@@ -95,8 +92,7 @@ Kappa test event in silver_inherit',
$this->setup_engine_for_events($dataset, $style_names);
// Run test
- $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php';
- $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file);
+ $this->run_template($file, $vars, $block_vars, $destroy, $expected);
}
protected function setup_engine_for_events($dataset, $style_names, array $new_config = array())
@@ -111,7 +107,7 @@ Kappa test event in silver_inherit',
$this->extension_manager = new phpbb_mock_filesystem_extension_manager(
dirname(__FILE__) . "/datasets/$dataset/"
);
- $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager);
+ $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context, $this->extension_manager);
$this->style_provider = new phpbb_style_path_provider();
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
$this->style->set_custom_style('silver', array($this->template_path), $style_names, '');
diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php
index 22b020208b..a57b219150 100644
--- a/tests/template/template_includejs_test.php
+++ b/tests/template/template_includejs_test.php
@@ -18,16 +18,15 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes
// Prepare correct result
$scripts = array(
- '<script src="' . $this->test_path . '/templates/parent_and_child.js?assets_version=1"></script>',
- '<script src="' . $this->test_path . '/parent_templates/parent_only.js?assets_version=1"></script>',
- '<script src="' . $this->test_path . '/templates/child_only.js?assets_version=1"></script>',
- '<script src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>',
- '<script src="' . $this->test_path . '/templates/subdir/subsubdir/parent_only.js?assets_version=1"></script>',
- '<script src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>',
+ '<script type="text/javascript" src="' . $this->test_path . '/templates/parent_and_child.js?assets_version=1"></script>',
+ '<script type="text/javascript" src="' . $this->test_path . '/parent_templates/parent_only.js?assets_version=1"></script>',
+ '<script type="text/javascript" src="' . $this->test_path . '/templates/child_only.js?assets_version=1"></script>',
+ '<script type="text/javascript" src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>',
+ '<script type="text/javascript" src="' . $this->test_path . '/templates/subdir/subsubdir/parent_only.js?assets_version=1"></script>',
+ '<script type="text/javascript" src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>',
);
// Run test
- $cache_file = $this->template->cachepath . 'includejs.html.php';
- $this->run_template('includejs.html', array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir', 'EXT' => 'js'), array(), array(), implode('', $scripts), $cache_file);
+ $this->run_template('includejs.html', array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir', 'EXT' => 'js'), array(), array(), implode('', $scripts));
}
}
diff --git a/tests/template/template_inheritance_test.php b/tests/template/template_inheritance_test.php
index febfed9ef0..cc71ff99e0 100644
--- a/tests/template/template_inheritance_test.php
+++ b/tests/template/template_inheritance_test.php
@@ -50,15 +50,6 @@ class phpbb_template_template_inheritance_test extends phpbb_template_template_t
*/
public function test_template($name, $file, array $vars, array $block_vars, array $destroy, $expected)
{
- $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php';
-
- $this->assertFileNotExists($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, $destroy, $expected, $cache_file);
+ $this->run_template($file, $vars, $block_vars, $destroy, $expected);
}
}
diff --git a/tests/template/template_locate_test.php b/tests/template/template_locate_test.php
deleted file mode 100644
index 851dcae8ea..0000000000
--- a/tests/template/template_locate_test.php
+++ /dev/null
@@ -1,68 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
-*
-*/
-
-require_once dirname(__FILE__) . '/template_test_case_with_tree.php';
-
-class phpbb_template_template_locate_test extends phpbb_template_template_test_case_with_tree
-{
- public function template_data()
- {
- return array(
- // First element of the array is test name - keep them distinct
- array(
- 'simple inheritance - only parent template exists',
- $this->test_path . '/parent_templates/parent_only.html',
- 'parent_only.html',
- false,
- true,
- ),
- array(
- 'simple inheritance - only child template exists',
- $this->test_path . '/templates/child_only.html',
- 'child_only.html',
- false,
- true,
- ),
- array(
- 'simple inheritance - both parent and child templates exist',
- $this->test_path . '/templates/parent_and_child.html',
- 'parent_and_child.html',
- false,
- true,
- ),
- array(
- 'find first template - only child template exists in main style',
- 'child_only.html',
- array('parent_only.html', 'child_only.html'),
- false,
- false,
- ),
- array(
- 'find first template - both templates exist in main style',
- 'parent_and_child.html',
- array('parent_and_child.html', 'child_only.html'),
- false,
- false,
- ),
- );
- }
-
- /**
- * @dataProvider template_data
- */
- public function test_template($name, $expected, $files, $return_default, $return_full_path)
- {
- // Reset the engine state
- $this->setup_engine();
-
- // Locate template
- $result = $this->style_resource_locator->get_first_template_location($files, $return_default, $return_full_path);
- $this->assertSame($expected, $result);
- }
-}
diff --git a/tests/template/template_spacing_test.php b/tests/template/template_spacing_test.php
deleted file mode 100644
index 83f8711b38..0000000000
--- a/tests/template/template_spacing_test.php
+++ /dev/null
@@ -1,87 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2013 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
-*
-*/
-
-require_once dirname(__FILE__) . '/template_test_case.php';
-
-class phpbb_template_template_spacing_test extends phpbb_template_template_test_case
-{
- public function template_data()
- {
- return array(
- /*
- array(
- '', // Description
- '', // dataset
- array(), // style names
- '', // file
- array(), // vars
- array(), // block vars
- array(), // destroy
- '', // expected result
- ),
- */
- array(
- 'Spacing in templates',
- 'ext_trivial',
- array(),
- 'variable_spacing.html',
- array(
- 'VARIABLE' => '{}',
- ),
- array(),
- array(),
- '|{}|
-{}|{}|
-|{}
-<div class="{}">test</div>',
- ),
- );
- }
-
- /**
- * @dataProvider template_data
- */
- public function test_template($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected)
- {
- // Run test
- $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php';
- $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file);
- }
-
- /**
- * @dataProvider template_data
- */
- public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected)
- {
- // Reset the engine state
- $this->setup_engine_for_events($dataset, $style_names);
-
- // Run test
- $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php';
- $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file);
- }
-
- protected function setup_engine_for_events($dataset, $style_names, array $new_config = array())
- {
- global $phpbb_root_path, $phpEx, $user;
-
- $defaults = $this->config_defaults();
- $config = new phpbb_config(array_merge($defaults, $new_config));
-
- $this->template_path = dirname(__FILE__) . "/datasets/$dataset/styles/silver/template";
- $this->style_resource_locator = new phpbb_style_resource_locator();
- $this->extension_manager = new phpbb_mock_filesystem_extension_manager(
- dirname(__FILE__) . "/datasets/$dataset/"
- );
- $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager);
- $this->style_provider = new phpbb_style_path_provider();
- $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
- $this->style->set_custom_style('silver', array($this->template_path), $style_names, '');
- }
-}
diff --git a/tests/template/template_test.php b/tests/template/template_test.php
index a3c0b69123..4970ce0363 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',
@@ -126,6 +126,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
"101234561\nx\n101234561\nx\n101234561\nx\n1234561\nx\n1\nx\n101\nx\n234\nx\n10\nx\n561\nx\n561",
),
array(
+ 'loop_nested2.html',
+ array(),
+ array('outer' => array(array(), array()), 'outer.middle' => array(array(), array())),
+ array(),
+ "o0o1m01m11",
+ ),
+ array(
'define.html',
array(),
array('loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())),
@@ -140,13 +147,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 +247,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 +269,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 +276,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 +305,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,49 +321,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())
{
- $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php';
-
- $this->assertFileNotExists($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, $destroy, $expected, $cache_file);
+ $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()
@@ -391,7 +348,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);
@@ -409,7 +366,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)
{
@@ -421,13 +378,20 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
public function test_php()
{
- $this->setup_engine(array('tpl_allow_php' => true));
+ global $phpbb_root_path;
+
+ $template_text = '<!-- PHP -->echo "test";<!-- ENDPHP -->';
- $cache_file = $this->template->cachepath . 'php.html.php';
+ $cache_dir = dirname($phpbb_root_path . 'cache') . '/';
+ $fp = fopen($cache_dir . 'php.html', 'w');
+ fputs($fp, $template_text);
+ fclose($fp);
- $this->assertFileNotExists($cache_file);
+ $this->setup_engine(array('tpl_allow_php' => true));
- $this->run_template('php.html', array(), array(), array(), 'test', $cache_file);
+ $this->style->set_custom_style('tests', $cache_dir, array(), '');
+
+ $this->run_template('php.html', array(), array(), array(), 'test');
}
public function alter_block_array_data()
@@ -533,10 +497,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 5d38ebed67..3e2cd5a387 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';
@@ -28,7 +29,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
try
{
- $this->assertTrue($this->template->display($handle, false));
+ $this->template->display($handle, false);
}
catch (Exception $exception)
{
@@ -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($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, 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(), '');
}
@@ -77,43 +79,15 @@ class phpbb_template_template_test_case extends phpbb_test_case
// Test the engine can be used
$this->setup_engine();
- $template_cache_dir = dirname($this->template->cachepath);
- if (!is_writable($template_cache_dir))
- {
- $this->markTestSkipped("Template cache directory ({$template_cache_dir}) is not writable.");
- }
-
- $file_array = scandir($template_cache_dir);
- $file_prefix = basename($this->template->cachepath);
- foreach ($file_array as $file)
- {
- if (strpos($file, $file_prefix) === 0)
- {
- unlink($template_cache_dir . '/' . $file);
- }
- }
-
- $this->setup_engine();
+ $this->template->clear_cache();
}
protected function tearDown()
{
- if (is_object($this->template))
- {
- $template_cache_dir = dirname($this->template->cachepath);
- $file_array = scandir($template_cache_dir);
- $file_prefix = basename($this->template->cachepath);
- foreach ($file_array as $file)
- {
- if (strpos($file, $file_prefix) === 0)
- {
- unlink($template_cache_dir . '/' . $file);
- }
- }
- }
+ $this->template->clear_cache();
}
- protected function run_template($file, array $vars, array $block_vars, array $destroy, $expected, $cache_file)
+ 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);
@@ -131,25 +105,17 @@ class phpbb_template_template_test_case extends phpbb_test_case
$this->template->destroy_block_vars($block);
}
- try
+ // Previous functionality was $cachefile (string), which was removed, check to prevent errors
+ if (is_array($lang_vars))
{
- $this->assertEquals($expected, $this->display('test'), "Testing $file");
- $this->assertFileExists($cache_file);
- }
- catch (ErrorException $e)
- {
- if (file_exists($cache_file))
+ foreach ($lang_vars as $name => $value)
{
- copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file));
+ $this->user->lang[$name] = $value;
}
- throw $e;
}
- // For debugging.
- // When testing eval path the cache file may not exist.
- if (self::PRESERVE_CACHE && file_exists($cache_file))
- {
- copy($cache_file, str_replace('ctpl_', 'tests_ctpl_', $cache_file));
- }
+ $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/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php
index 7585be5728..4b8cbada45 100644
--- a/tests/template/template_test_case_with_tree.php
+++ b/tests/template/template_test_case_with_tree.php
@@ -22,7 +22,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
$this->parent_template_path = $this->test_path . '/parent_templates';
$this->style_resource_locator = new phpbb_style_resource_locator();
$this->style_provider = new phpbb_style_path_provider();
- $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context());
+ $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, 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->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), array(), '');
}
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/includejs.html b/tests/template/templates/includejs.html
index ef73700eeb..229f1ccc19 100644
--- a/tests/template/templates/includejs.html
+++ b/tests/template/templates/includejs.html
@@ -5,4 +5,4 @@
<!-- INCLUDEJS subdir/{PARENT} -->
<!-- INCLUDEJS {SUBDIR}/subsubdir/{PARENT} -->
<!-- INCLUDEJS {SUBDIR}/parent_only.{EXT} -->
-{SCRIPTS}
+{$SCRIPTS}
diff --git a/tests/template/templates/invalid/include_nonexistent_file.html b/tests/template/templates/invalid/include_nonexistent_file.html
deleted file mode 100644
index 617d2fdaaa..0000000000
--- a/tests/template/templates/invalid/include_nonexistent_file.html
+++ /dev/null
@@ -1 +0,0 @@
-<!-- INCLUDE nonexistent.html -->
diff --git a/tests/template/templates/invalid/unknown_tag.html b/tests/template/templates/invalid/unknown_tag.html
deleted file mode 100644
index 1489e5e31a..0000000000
--- a/tests/template/templates/invalid/unknown_tag.html
+++ /dev/null
@@ -1 +0,0 @@
-<!-- UNKNOWNTAG variable.html -->
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_nested2.html b/tests/template/templates/loop_nested2.html
new file mode 100644
index 0000000000..3eeeb5e36a
--- /dev/null
+++ b/tests/template/templates/loop_nested2.html
@@ -0,0 +1,6 @@
+<!-- BEGIN outer -->
+o{outer.S_ROW_COUNT}
+<!-- BEGIN middle -->
+m{outer.middle.S_ROW_COUNT}{outer.S_ROW_COUNT}
+<!-- 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 -->
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index 50b2bf03ec..b83b1ca5ca 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -94,7 +94,16 @@ class phpbb_test_case_helpers
public function makedirs($path)
{
- mkdir($path, 0777, true);
+ if (!is_dir($path))
+ {
+ // Testing
+ if (file_exists($path))
+ {
+ echo $path;
+ }
+
+ mkdir($path, 0777, true);
+ }
}
static public function get_test_config()