From bbc3105466ccd43d94423325a68c626c76dec5f9 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 8 Jul 2010 22:44:28 +0200 Subject: [PATCH] [ticket/9701] Prevent notices from being hidden by template tests The template tests disable NOTICEs for the duration of template execution since the current version of the template engine does not generate sufficiently clean code. The error level is reset aftwards, however that part is skipped when trigger_error is called which is converted into a regular exception by PHPUnit and passed down until caught. Such exceptions are now caught to reset the error level, and then the exception is rethrown. This uncovered another issue in the template tests which only passed because NOTICEs were unintentionally disabled at this point. assign_display is also required to operate without NOTICEs. The respective code has been added around its callee as well. However no handling of exceptions takes place there. If another test checking for errors in that function is ever added similar catch logic will have to be added there. PHPBB3-9701 --- tests/template/template.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/template/template.php b/tests/template/template.php index 145fe8de61..024d3712f7 100644 --- a/tests/template/template.php +++ b/tests/template/template.php @@ -26,12 +26,24 @@ class phpbb_template_template_test extends phpbb_test_case error_reporting($error_level & ~E_NOTICE); ob_start(); - $this->assertTrue($this->template->display($handle, false)); + + try + { + $this->assertTrue($this->template->display($handle, false)); + } + catch (Exception $exception) + { + // reset the error level even when an error occured + // PHPUnit turns trigger_error into exceptions as well + error_reporting($error_level); + throw $exception; + } + + $result = self::trim_template_result(ob_get_clean()); // reset error level error_reporting($error_level); - - return self::trim_template_result(ob_get_clean()); + return $result; } private static function trim_template_result($result) @@ -368,9 +380,15 @@ class phpbb_template_template_test extends phpbb_test_case $this->template->destroy_block_vars($block); } + $error_level = error_reporting(); + error_reporting($error_level & ~E_NOTICE); + $this->assertEquals($expected, self::trim_template_result($this->template->assign_display('test')), "Testing assign_display($file)"); $this->template->assign_display('test', 'VARIABLE', false); + + error_reporting($error_level); + $this->assertEquals($expected, $this->display('container'), "Testing assign_display($file)"); }