From 1800432c4c7904971be0bc95905fd5ae279a50b7 Mon Sep 17 00:00:00 2001 From: uwetews Date: Wed, 30 Dec 2015 18:23:46 +0100 Subject: [PATCH] Test E_NOTICE suppression on undefined variables https://github.com/smarty-php/smarty/issues/145 --- .../UndefinedTemplateVarTest.php | 70 +++++++++++++++++++ .../A_2/UndefinedTemplateVar/cache/dummy.txt | 0 .../templates/001_include.tpl | 1 + .../templates/001_main.tpl | 1 + .../templates_c/dummy.txt | 0 5 files changed, 72 insertions(+) create mode 100644 tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php create mode 100644 tests/UnitTests/A_2/UndefinedTemplateVar/cache/dummy.txt create mode 100644 tests/UnitTests/A_2/UndefinedTemplateVar/templates/001_include.tpl create mode 100644 tests/UnitTests/A_2/UndefinedTemplateVar/templates/001_main.tpl create mode 100644 tests/UnitTests/A_2/UndefinedTemplateVar/templates_c/dummy.txt diff --git a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php new file mode 100644 index 00000000..2e2fc065 --- /dev/null +++ b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php @@ -0,0 +1,70 @@ +setUpSmarty(__DIR__); + error_reporting(E_ALL | E_STRICT); + } + + /** + * Test E_NOTICE suppression template fetched by Smarty object + */ + public function testE_NoticeDisabled() + { + $e1 = error_reporting(); + $this->smarty->setErrorReporting(E_ALL & ~E_NOTICE); + $this->assertEquals('undefined = ', $this->smarty->fetch('001_main.tpl')); + $e2 = error_reporting(); + $this->assertEquals($e1, $e2); + } + + /** + * Test E_NOTICE suppression template fetched by template object + */ + public function testE_NoticeDisabledTplObject_1() + { + $e1 = error_reporting(); + $this->smarty->setErrorReporting(E_ALL & ~E_NOTICE); + $tpl = $this->smarty->createTemplate('001_main.tpl'); + $this->assertEquals('undefined = ', $tpl->fetch()); + $e2 = error_reporting(); + $this->assertEquals($e1, $e2); + } + + public function testE_NoticeDisabledTplObject_2() + { + $e1 = error_reporting(); + $this->smarty->setErrorReporting(E_ALL & ~E_NOTICE); + $tpl = $this->smarty->createTemplate('001_main.tpl'); + $this->assertEquals('undefined = ', $this->smarty->fetch($tpl)); + $e2 = error_reporting(); + $this->assertEquals($e1, $e2); + } + + /** + * Throw E_NOTICE message + * + * @expectedException PHPUnit_Framework_Error + * @expectedExceptionMessage Undefined index: foo + */ + public function testE_Notice() + { + $e1 = error_reporting(); + $this->assertEquals('undefined = ', $this->smarty->fetch('001_main.tpl')); + $e2 = error_reporting(); + $this->assertEquals($e1, $e2); + } +} diff --git a/tests/UnitTests/A_2/UndefinedTemplateVar/cache/dummy.txt b/tests/UnitTests/A_2/UndefinedTemplateVar/cache/dummy.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/UnitTests/A_2/UndefinedTemplateVar/templates/001_include.tpl b/tests/UnitTests/A_2/UndefinedTemplateVar/templates/001_include.tpl new file mode 100644 index 00000000..df554272 --- /dev/null +++ b/tests/UnitTests/A_2/UndefinedTemplateVar/templates/001_include.tpl @@ -0,0 +1 @@ +undefined = {$foo} \ No newline at end of file diff --git a/tests/UnitTests/A_2/UndefinedTemplateVar/templates/001_main.tpl b/tests/UnitTests/A_2/UndefinedTemplateVar/templates/001_main.tpl new file mode 100644 index 00000000..534e9ff7 --- /dev/null +++ b/tests/UnitTests/A_2/UndefinedTemplateVar/templates/001_main.tpl @@ -0,0 +1 @@ +{include '001_include.tpl'} \ No newline at end of file diff --git a/tests/UnitTests/A_2/UndefinedTemplateVar/templates_c/dummy.txt b/tests/UnitTests/A_2/UndefinedTemplateVar/templates_c/dummy.txt new file mode 100644 index 00000000..e69de29b