From 56b2b87423c9afd62312fd36b5c2f6fff2d1d8a7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 10 May 2012 03:36:58 -0400 Subject: [PATCH] [ticket/10882] Add a test for including a nonexistent file. PHPBB3-10882 --- tests/template/invalid_constructs_test.php | 32 +++++++++++++++++++ .../invalid/include_nonexistent_file.html | 1 + .../output/include_nonexistent_file.html | 1 + 3 files changed, 34 insertions(+) create mode 100644 tests/template/templates/invalid/include_nonexistent_file.html create mode 100644 tests/template/templates/invalid/output/include_nonexistent_file.html diff --git a/tests/template/invalid_constructs_test.php b/tests/template/invalid_constructs_test.php index 8d54df5014..2430b5b9b1 100644 --- a/tests/template/invalid_constructs_test.php +++ b/tests/template/invalid_constructs_test.php @@ -37,6 +37,21 @@ class phpbb_template_template_test extends phpbb_template_template_test_case ); } + 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 */ @@ -52,4 +67,21 @@ class phpbb_template_template_test extends phpbb_template_template_test_case $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/templates/invalid/include_nonexistent_file.html b/tests/template/templates/invalid/include_nonexistent_file.html new file mode 100644 index 0000000000..617d2fdaaa --- /dev/null +++ b/tests/template/templates/invalid/include_nonexistent_file.html @@ -0,0 +1 @@ + diff --git a/tests/template/templates/invalid/output/include_nonexistent_file.html b/tests/template/templates/invalid/output/include_nonexistent_file.html new file mode 100644 index 0000000000..8a118d2713 --- /dev/null +++ b/tests/template/templates/invalid/output/include_nonexistent_file.html @@ -0,0 +1 @@ +style resource locator: File for handle nonexistent.html does not exist. Could not find: