diff --git a/tests/all_tests.php b/tests/all_tests.php index 8a871917eb..2b68fd7264 100644 --- a/tests/all_tests.php +++ b/tests/all_tests.php @@ -22,6 +22,7 @@ require_once 'bbcode/all_tests.php'; require_once 'utf/all_tests.php'; require_once 'request/all_tests.php'; require_once 'security/all_tests.php'; +require_once 'template/all_tests.php'; // exclude the test directory from code coverage reports PHPUnit_Util_Filter::addDirectoryToFilter('./'); @@ -41,6 +42,7 @@ class phpbb_all_tests $suite->addTest(phpbb_utf_all_tests::suite()); $suite->addTest(phpbb_request_all_tests::suite()); $suite->addTest(phpbb_security_all_tests::suite()); + $suite->addTest(phpbb_template_all_tests::suite()); return $suite; } diff --git a/tests/template/all_tests.php b/tests/template/all_tests.php new file mode 100644 index 0000000000..50f6aa6ee8 --- /dev/null +++ b/tests/template/all_tests.php @@ -0,0 +1,44 @@ +addTestSuite('phpbb_template_template_test'); + + return $suite; + } +} + +if (PHPUnit_MAIN_METHOD == 'phpbb_template_all_tests::main') +{ + phpbb_template_all_tests::main(); +} +?> \ No newline at end of file diff --git a/tests/template/template.php b/tests/template/template.php new file mode 100644 index 0000000000..e2d9429511 --- /dev/null +++ b/tests/template/template.php @@ -0,0 +1,144 @@ + true +); + +class phpbb_template_template_test extends PHPUnit_Framework_TestCase +{ + private $template; + + private function display($handle) + { + 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()))))); + ob_end_clean(); + + return $contents; + } + + private function setup_engine() + { + $this->template = new template; + $this->template->set_custom_template(dirname(__FILE__) . '/templates/', 'tests'); + } + + protected function setUp() + { + + } + + public static function template_data() + { + return array( + /* + array( + '', // File + array(), // vars + array(), // block vars + '', // Expected result + ), + */ + array( + 'variable.html', + array('VARIABLE' => 'value'), + array(), + 'value', + ), + array( + 'if.html', + array(), + array(), + '0', + ), + array( + 'if.html', + array('S_VALUE' => true), + array(), + '1', + ), + array( + 'loop.html', + array(), + array(), + "noloop\nnoloop", + ), + array( + 'loop.html', + array(), + array('loop' => array(array())), + "loop\nloop", + ), + array( + 'loop.html', + array(), + array('loop' => array(array(), array())), + "loop\nloop\nloop", + ), + array( + 'loop_vars.html', + array(), + array('loop' => array(array('VARIABLE' => 'x'))), + "first\n0\nx\nlast", + ), + array( + 'loop_vars.html', + array(), + array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y'))), + "first\n0\nx\n1\ny\nlast", + ), + array( + 'define.html', + array(), + array(), + "xyz\nabc", + ), + array( + 'expressions.html', + array(), + array(), + trim(str_repeat("pass\n", 38)), + ), + ); + } + + /** + * @dataProvider template_data + */ + public function test_template($file, array $vars, array $block_vars, $expected) + { + $this->setup_engine(); + $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.html"); + } +} +?> \ No newline at end of file diff --git a/tests/template/templates/basic.html b/tests/template/templates/basic.html new file mode 100644 index 0000000000..1a3fd5a96a --- /dev/null +++ b/tests/template/templates/basic.html @@ -0,0 +1,18 @@ + +fail + + +pass + + +fail + +fail + +pass + + +fail + +pass + diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html new file mode 100644 index 0000000000..94741e53fc --- /dev/null +++ b/tests/template/templates/define.html @@ -0,0 +1,11 @@ + + +{$VALUE} + + + +{$VALUE} + + + +{$VALUE} diff --git a/tests/template/templates/expressions.html b/tests/template/templates/expressions.html new file mode 100644 index 0000000000..c70dc9418c --- /dev/null +++ b/tests/template/templates/expressions.html @@ -0,0 +1,85 @@ +passfail + +failpass + +failpass + +passfail + +failpass + + +passfail + +passfail + +passfail + + +passfail + +passfail + +passfail + +passfail + + +passfail + +passfail + + +passfail + +passfail + +passfail + +passfail + +passfail + +passfail + + +passfail + +passfail + + +passfail + +passfail + +passfail + +passfail + +passfail + +passfail + + +passfail + +passfail + + +passfail + +passfail + + +passfail + +passfail + +passfail + +passfail + + +passfail + +passfail diff --git a/tests/template/templates/if.html b/tests/template/templates/if.html new file mode 100644 index 0000000000..d8343c4391 --- /dev/null +++ b/tests/template/templates/if.html @@ -0,0 +1,5 @@ + +1 + +0 + diff --git a/tests/template/templates/loop.html b/tests/template/templates/loop.html new file mode 100644 index 0000000000..ae921fc929 --- /dev/null +++ b/tests/template/templates/loop.html @@ -0,0 +1,11 @@ + +loop + +noloop + + + +loop + +noloop + diff --git a/tests/template/templates/loop_vars.html b/tests/template/templates/loop_vars.html new file mode 100644 index 0000000000..0da0af4758 --- /dev/null +++ b/tests/template/templates/loop_vars.html @@ -0,0 +1,9 @@ + +first + +{loop.S_ROW_COUNT} + +{loop.VARIABLE} + +last + diff --git a/tests/template/templates/variable.html b/tests/template/templates/variable.html new file mode 100644 index 0000000000..f68f91597c --- /dev/null +++ b/tests/template/templates/variable.html @@ -0,0 +1 @@ +{VARIABLE}