From ce756af4ca518eddbc6a66f13ab052010057fca4 Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Tue, 5 May 2015 23:45:28 +0200 Subject: [PATCH] Update tests --- .../Extends/ExtendsResourceTest.php | 95 ++++- .../Extends/templates/021_child.tpl | 1 + .../Extends/templates/021_grandchild.tpl | 1 + .../Extends/templates/021_parent.tpl | 1 + .../Extends/templates/022_child.tpl | 4 + .../TagTests/Php/CompilePhp2Test.php | 393 ------------------ .../TagTests/Php/CompilePhpTest.php | 219 ++++++---- 7 files changed, 241 insertions(+), 473 deletions(-) create mode 100644 tests/UnitTests/ResourceTests/Extends/templates/021_child.tpl create mode 100644 tests/UnitTests/ResourceTests/Extends/templates/021_grandchild.tpl create mode 100644 tests/UnitTests/ResourceTests/Extends/templates/021_parent.tpl create mode 100644 tests/UnitTests/ResourceTests/Extends/templates/022_child.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Php/CompilePhp2Test.php diff --git a/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php b/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php index 263e730f..77007871 100644 --- a/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php +++ b/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php @@ -31,7 +31,6 @@ class ExtendsResourceTest extends PHPUnit_Smarty $result = $this->smarty->fetch('extends:003_parent.tpl|003_child_prepend.tpl'); $this->assertContains("prepend - Default Title", $result); } - /** * test child/parent template chain with apppend */ @@ -41,5 +40,99 @@ class ExtendsResourceTest extends PHPUnit_Smarty $result = $this->smarty->fetch('extends:004_parent.tpl|004_child_append.tpl'); $this->assertContains("Default Title - append", $result); } + /** + * test grandchild/child/parent dependency test1 + */ + public function testCompileBlockGrandChildMustCompile_021_1() + { + $this->cleanDirs(); + $this->smarty->caching = true; + $this->smarty->cache_lifetime = 1000; + $tpl = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl'); + $this->assertFalse($tpl->isCached()); + $result = $this->smarty->fetch($tpl); + $this->assertContains('Grandchild Page Title', $result); + $this->smarty->template_objects = null; + $tpl2 = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl'); + $this->assertTrue($tpl2->isCached()); + $result = $this->smarty->fetch($tpl2); + $this->assertContains('Grandchild Page Title', $result); + } + + /** + * test grandchild/child/parent dependency test2 + * + */ + public function testCompileBlockGrandChildMustCompile_021_2() + { + sleep(2); + touch($this->smarty->getTemplateDir(0) . '021_grandchild.tpl'); + clearstatcache(); + $this->smarty->caching = true; + $this->smarty->cache_lifetime = 1000; + $tpl = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl'); + $this->assertFalse($tpl->isCached()); + $result = $this->smarty->fetch($tpl); + $this->assertContains('Grandchild Page Title', $result); + $this->smarty->template_objects = null; + $tpl2 = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl'); + $this->assertTrue($tpl2->isCached()); + $result = $this->smarty->fetch($tpl2); + $this->assertContains('Grandchild Page Title', $result); + } + + /** + * test grandchild/child/parent dependency test3 + * + */ + public function testCompileBlockGrandChildMustCompile_021_3() + { + sleep(2); + touch($this->smarty->getTemplateDir(0) . '021_child.tpl'); + clearstatcache(); + $this->smarty->caching = true; + $this->smarty->cache_lifetime = 1000; + $tpl = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl'); + $this->assertFalse($tpl->isCached()); + $result = $this->smarty->fetch($tpl); + $this->assertContains('Grandchild Page Title', $result); + $this->smarty->template_objects = null; + $tpl2 = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl'); + $this->assertTrue($tpl2->isCached()); + $result = $this->smarty->fetch($tpl2); + $this->assertContains('Grandchild Page Title', $result); + } + + /** + * test grandchild/child/parent dependency test4 + * + */ + public function testCompileBlockGrandChildMustCompile_021_4() + { + sleep(2); + touch($this->smarty->getTemplateDir(0) . '021_parent.tpl'); + clearstatcache(); + $this->smarty->caching = true; + $this->smarty->cache_lifetime = 1000; + $tpl = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl'); + $this->assertFalse($tpl->isCached()); + $result = $this->smarty->fetch($tpl); + $this->assertContains('Grandchild Page Title', $result); + $this->smarty->template_objects = null; + $tpl2 = $this->smarty->createTemplate('extends:021_parent.tpl|021_child.tpl|021_grandchild.tpl'); + $this->assertTrue($tpl2->isCached()); + $result = $this->smarty->fetch($tpl2); + $this->assertContains('Grandchild Page Title', $result); + } + /** + * test child/parent template chain with prepend + */ + public function testCompileBlockChildPrepend_0032() + { + $this->smarty->caching = true; + $result = $this->smarty->fetch('extends:003_parent.tpl|003_child_prepend.tpl'); + $this->assertContains("prepend - Default Title", $result); + } + } diff --git a/tests/UnitTests/ResourceTests/Extends/templates/021_child.tpl b/tests/UnitTests/ResourceTests/Extends/templates/021_child.tpl new file mode 100644 index 00000000..7c5bda39 --- /dev/null +++ b/tests/UnitTests/ResourceTests/Extends/templates/021_child.tpl @@ -0,0 +1 @@ +{block name='title'}Page Title{/block} diff --git a/tests/UnitTests/ResourceTests/Extends/templates/021_grandchild.tpl b/tests/UnitTests/ResourceTests/Extends/templates/021_grandchild.tpl new file mode 100644 index 00000000..afedae7c --- /dev/null +++ b/tests/UnitTests/ResourceTests/Extends/templates/021_grandchild.tpl @@ -0,0 +1 @@ +{block name='title'}Grandchild Page Title{/block} diff --git a/tests/UnitTests/ResourceTests/Extends/templates/021_parent.tpl b/tests/UnitTests/ResourceTests/Extends/templates/021_parent.tpl new file mode 100644 index 00000000..e007864b --- /dev/null +++ b/tests/UnitTests/ResourceTests/Extends/templates/021_parent.tpl @@ -0,0 +1 @@ +{block name='title'}Default Title{/block} diff --git a/tests/UnitTests/ResourceTests/Extends/templates/022_child.tpl b/tests/UnitTests/ResourceTests/Extends/templates/022_child.tpl new file mode 100644 index 00000000..305d805b --- /dev/null +++ b/tests/UnitTests/ResourceTests/Extends/templates/022_child.tpl @@ -0,0 +1,4 @@ +{extends file='022_parent.tpl'} +{block name='title'}Page Title{/block} + + diff --git a/tests/UnitTests/TemplateSource/TagTests/Php/CompilePhp2Test.php b/tests/UnitTests/TemplateSource/TagTests/Php/CompilePhp2Test.php deleted file mode 100644 index eb8b02b7..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Php/CompilePhp2Test.php +++ /dev/null @@ -1,393 +0,0 @@ - tag - * - * @package PHPunit - * @author Uwe Tews - */ - -/** - * class for {php} and tag tests - */ -class CompilePhp2Test extends PHPUnit_Smarty -{ - public $loadSmartyBC = true; - public $loadSmarty = false; - public function setUp() - { - $this->setUpSmarty(__DIR__); - $this->smartyBC->disableSecurity(); - } - - - public function testInit() - { - $this->cleanDirs(); - } - public function testEndTagInStrings1() - { - $str = <<< STR -" => 3 ); -\$b = Array("?>" => "?>"); -\$c = Array("a" => Array("b" => 7)); -class d_class -{ - public \$d_attr = 8; -} -\$d = new d_class(); -\$e = Array("f" => \$d); - -// '" -# '" - -echo '{\$a["?>"]}'; -echo "{\$a['?>']}"; -echo '{\$a["{\$b["?>"]}"]}'; -echo "{\$c['a']['b']}"; -echo "a{\$e['f']->d_attr}a"; -?> -STR; - - $this->smartyBC->left_delimiter = '{{'; - $this->smartyBC->right_delimiter = '}}'; - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content)); - - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $this->smartyBC->disableSecurity(); - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals('{$a["?>"]}3{$a["{$b["?>"]}"]}7a8a', $content); - } - - public function testEndTagInStrings2() - { - $str = <<< STR -" => 3 ); -\$b = Array("?>" => "?>"); - -echo "{\$a["?>"]}"; -echo "{\$a["{\$b["?>"]}"]}"; -?> -STR; - - $this->smartyBC->left_delimiter = '{{'; - $this->smartyBC->right_delimiter = '}}'; - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content)); - - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $this->smartyBC->disableSecurity(); - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals('33', $content); - } - - public function testEndTagInStrings3() - { - $str = <<< STR -a'; -echo '?>\\\\'; -echo '\\\\\\'?>a'; -echo '/*'; // */ -echo 1+1; -?> -STR; - - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content)); - - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $this->smartyBC->disableSecurity(); - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals('a?>a?>\\\\\'?>a/*2', $content); - } - - public function testEndTagInStrings4() - { - $str = <<< STR -a"; -echo "?>\\\\"; -echo "\\"?>"; -echo "\\\\\\"?>a"; -echo "/*"; -echo 1+1; -?> -STR; - - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content)); - - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $this->smartyBC->disableSecurity(); - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals('a?>a?>\\"?>\\"?>a/*2', $content); - } - - public function testEndTagInHEREDOC() - { - $str = <<< STR - - - "! ?> /* - LALA -LALA ; -LALA;1+1; -LALA; -echo << -STR; - // " Fix emacs highlighting which chokes on preceding open quote - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content)); - - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $this->smartyBC->disableSecurity(); - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals(" LALA\n ?>\n\n \"! ?> /*\n LALA\nLALA ;\nLALA;1+1;LALA2;1+1;", str_replace("\r", '', $content)); - } - - public function testEmbeddingsInHEREDOC1() - { - $str = <<< STR -'" => 1); - -echo <<< EOT -{\$a["EOT?>'"]} -EOT; -?> -STR; - // ' Fix emacs highlighting which chokes on preceding open quote - $this->smartyBC->left_delimiter = '{{'; - $this->smartyBC->right_delimiter = '}}'; - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content)); - - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $this->smartyBC->disableSecurity(); - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals("1", $content); - } - - public function testEmbeddingsInHEREDOC2() - { - $str = <<< STR -'" => 1); - -echo <<< EOT -{\$a[<<' -EOT2 -]} -EOT -; -?> -STR; - // ' Fix emacs highlighting which chokes on preceding open quote - $this->smartyBC->left_delimiter = '{{'; - $this->smartyBC->right_delimiter = '}}'; - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content)); - /* Disabled due to bug in PHP easiest illustrated by: - http://bugs.php.net/bug.php?id=50654 - - 1); - -echo << - $this->smartyBC->left_delimiter = '{{'; - $this->smartyBC->right_delimiter = '}}'; - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $this->smartyBC->security = false; - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals("11", $content); -*/ - } - - public function testEmbeddedHEREDOC() - { - $str = <<< STR - 3); -\$b = Array("aa\"?>" => 4); - -echo "{\$a[<<"]}" -EOT - ]}"; -?> -STR; - // " Fix emacs highlighting which chokes on preceding open quote - $this->smartyBC->left_delimiter = '{{'; - $this->smartyBC->right_delimiter = '}}'; - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content)); - - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $this->smartyBC->disableSecurity(); - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals("3", $content); - } - - public function testEmbeddedNOWDOC() - { - $str = <<< STR -" => 3); - -echo "{\$a[<<<'EOT' -aa"?> -EOT - ]}"; -?> -STR; - // " Fix emacs highlighting which chokes on preceding open quote - $this->smartyBC->left_delimiter = '{{'; - $this->smartyBC->right_delimiter = '}}'; - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content)); - - if (version_compare(PHP_VERSION, '5.3.0') < 0) { - return; - } - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $this->smartyBC->disableSecurity(); - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals("3", $content); - } - - public function testEndTagInNOWDOC() - { - $str = <<< STR - bb -LALA; -echo <<<'LALA2' -LALA2;1+1;?> -LALA2 -; -?> -STR; - - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content)); - - if (version_compare(PHP_VERSION, '5.3.0') < 0) { - return; - } - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $this->smartyBC->disableSecurity(); - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals("aa ?> bbLALA2;1+1;?>", $content); - } - - public function testNewlineHEREDOC() - { - $sprintf_str = ""; - foreach (Array("\n", "\r\n") as $newline_chars) { - $str = sprintf($sprintf_str, $newline_chars); - - $this->smartyBC->php_handling = Smarty::PHP_PASSTHRU; - $this->smartyBC->enableSecurity(); - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - // For some reason $content doesn't preserve newline format. Not a big problem, I think. - $this->assertEquals(preg_replace("/\r\n/", "\n", $str), - preg_replace("/\r\n/", "\n", $content) - ); - - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $this->smartyBC->disableSecurity(); - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals("a", $content); - } - } - - public function testNewlineNOWDOC() - { - $sprintf_str = ""; - foreach (Array("\n", "\r\n") as $newline_chars) { - $str = sprintf($sprintf_str, $newline_chars); - - $this->smartyBC->php_handling = Smarty::PHP_PASSTHRU; - $this->smartyBC->enableSecurity(); - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - // For some reason $content doesn't preserve newline format. Not a big problem, I think. - $this->assertEquals(preg_replace("/\r\n/", "\n", $str), - preg_replace("/\r\n/", "\n", $content) - ); - - if (version_compare(PHP_VERSION, '5.3.0') >= 0) { - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $this->smartyBC->disableSecurity(); - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals("a", $content); - } - } - } - - public function testEndTagInComment() - { - $str = <<< STR -dd "' <<< EOT -*/ -echo 1+1; -?> -STR; - - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals(str_replace("\r", '', $str), str_replace("\r", '', $content)); - - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $this->smartyBC->disableSecurity(); - $tpl = $this->smartyBC->createTemplate("eval:$str"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals('2', $content); - } -} diff --git a/tests/UnitTests/TemplateSource/TagTests/Php/CompilePhpTest.php b/tests/UnitTests/TemplateSource/TagTests/Php/CompilePhpTest.php index 9e396eec..bcfc8311 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Php/CompilePhpTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Php/CompilePhpTest.php @@ -19,6 +19,8 @@ class CompilePhpTest extends PHPUnit_Smarty $this->setUpSmarty(__DIR__); $this->smartyBC->disableSecurity(); $this->smarty->disableSecurity(); + $this->smarty->setCompileId($this->getName()); + $this->smartyBC->setCompileId($this->getName()); } public function testInit() @@ -30,7 +32,7 @@ class CompilePhpTest extends PHPUnit_Smarty * test tag * PHP_REMOVE */ -public function testPHP_REMOVEphp() +public function testPHP_REMOVE_php() { $this->smarty->setPhpHandling(Smarty::PHP_REMOVE); $content = $this->smarty->fetch("string:ae"); @@ -41,22 +43,17 @@ public function testPHP_REMOVEphp() * test <%...%> tag * PHP_REMOVE */ - public function testPHP_REMOVEasp() + public function testPHP_REMOVE_asp() { - if (!ini_get('asp_tags')) { - $this->markTestSkipped('asp tags disabled in php.ini'); - } $this->smarty->setPhpHandling(Smarty::PHP_REMOVE); $content = $this->smarty->fetch("string:a<% echo 'hello world';%>e"); $this->assertEquals("a echo 'hello world';e", $content, 'remove <% %>'); - - } /** * test tag * PHP_REMOVE */ - public function testPHP_REMOVEscript() + public function testPHP_REMOVE_script() { $this->smarty->setPhpHandling(Smarty::PHP_REMOVE); $content = $this->smarty->fetch("string:ae"); @@ -66,7 +63,7 @@ public function testPHP_REMOVEphp() * test tag * PHP_PASSTHRU */ - public function testPHP_PASSTHRUphp() + public function testPHP_PASSTHRU_php() { $this->smarty->setPhpHandling(Smarty::PHP_PASSTHRU); $content = $this->smarty->fetch("string:pape"); @@ -76,30 +73,27 @@ public function testPHP_REMOVEphp() * test <%...%> tag * PHP_PASSTHRU */ - public function testPHP_PASSTHRUasp() + public function testPHP_PASSTHRU_asp() { - if (!ini_get('asp_tags')) { - $this->markTestSkipped('asp tags disabled in php.ini'); - } $this->smarty->setPhpHandling(Smarty::PHP_PASSTHRU); - $content = $this->smarty->fetch("string:pa<% echo 'hello world';%>pe"); + $content = $this->smarty->fetch("string:pa<% echo 'hello world';%>pe"); $this->assertEquals("pa<% echo 'hello world';%>pe", $content, 'passthru <% %>'); } /** * test tag * PHP_PASSTHRU */ - public function testPHP_PASSTHRUscript() + public function testPHP_PASSTHRU_script() { $this->smarty->setPhpHandling(Smarty::PHP_PASSTHRU); $content = $this->smarty->fetch("string:pape"); - $this->assertEquals("pape", $content, "passthru pe", $content, "passthru tag * PHP_QUOTE */ - public function testPHP_QUOTEscript() + public function testPHP_QUOTE_script() { $this->smarty->setPhpHandling(Smarty::PHP_QUOTE); $content = $this->smarty->fetch("string:qaqe"); @@ -132,7 +123,7 @@ public function testPHP_REMOVEphp() * test tag * PHP_ALLOW */ - public function testPHP_ALLOWphp() + public function testPHP_ALLOW_php() { $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); $content = $this->smartyBC->fetch("string:aa ae"); @@ -141,20 +132,21 @@ public function testPHP_REMOVEphp() * test <%...%> tag * PHP_ALLOW */ - public function testPHP_ALLOWasp() + public function testPHP_ALLOW_asp() { - if (!ini_get('asp_tags')) { - $this->markTestSkipped('asp tags disabled in php.ini'); - } $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); $content = $this->smartyBC->fetch("string:aa <% echo 'hello world';%> ae"); - $this->assertEquals('aa hello world ae', $content, 'allow <% %>'); + if (ini_get('asp_tags')) { + $this->assertEquals('aa hello world ae', $content, 'allow <% %>'); + } else { + $this->assertEquals("aa <% echo 'hello world';%> ae", $content, 'allow asp disabled <% %>'); + } } /** * test tag * PHP_ALLOW */ - public function testPHP_ALLOWscript() + public function testPHP_ALLOW_script() { $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); $content = $this->smartyBC->fetch("string:aa ae"); @@ -164,7 +156,7 @@ public function testPHP_REMOVEphp() * test tag * PHP_ALLOW */ - public function testPHP_ALLOW2() + public function testPHP_ALLOW_php2() { $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); $content = $this->smartyBC->fetch("string:aa ae"); @@ -174,38 +166,27 @@ public function testPHP_REMOVEphp() * test tag * PHP_ALLOW */ - public function testPHP_ALLOW3() + public function testPHP_ALLOW_php3() { $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); $content = $this->smartyBC->fetch("string:aa '; ?> ae"); $this->assertEquals('aa ?> ae', $content); } + /** + * test tag + * PHP_ALLOW + */ + public function testPHP_ALLOW_php4() + { + $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); + $content = $this->smartyBC->fetch("string:aa */ echo '?>'; ?> ae"); + $this->assertEquals('aa ?> ae', $content); + } - /** - * test {php}{/php} tag - * PHP_ALLOW - */ - public function testPHP_ALLOW5() - { - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $content = $this->smartyBC->fetch("string:aa {php} echo 'hallo'; {/php} ae"); - $this->assertEquals('aa hallo ae', $content); - } - /** - * test {php}{/php} tag - * PHP_ALLOW - */ - public function testPHP_ALLOW6() - { - $this->smartyBC->caching = 1; - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $content = $this->smartyBC->fetch("string:aa {php nocache} echo 'hallo'; {/php} ae"); - $this->assertEquals('aa hallo ae', $content); - } /** * @expectedException SmartyCompilerException - * @expectedExceptionMessage PHP in template not allowed + * @expectedExceptionMessage $smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it */ public function testPHP_ALLOW_error() @@ -213,26 +194,6 @@ public function testPHP_REMOVEphp() $this->smarty->setPhpHandling(Smarty::PHP_ALLOW); $content = $this->smarty->fetch("string:aa ae"); } - /** - * test tag - * default is PASSTHRU - */ - public function testPhpTag() - { - $tpl = $this->smartyBC->createTemplate("eval:"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals("", $content); - } - - // ALLOW - public function testPhpTagAllow() - { - $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); - $this->smartyBC->disableSecurity(); - $tpl = $this->smartyBC->createTemplate("eval:"); - $content = $this->smartyBC->fetch($tpl); - $this->assertEquals('hello world', $content); - } /** * test shorttag @@ -244,14 +205,114 @@ public function testPHP_REMOVEphp() $content = $this->smartyBC->fetch('eval:'); $this->assertEquals('', $content); } + /** - * PHP tag data provider + * test unmatched smartyBC->setPhpHandling(Smarty::PHP_ALLOW); + $content = $this->smartyBC->fetch('string:aa assertEquals('aa + * + */ + public function testUnmatched_php_close() + { + $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); + $content = $this->smartyBC->fetch('string:aa ?> ee'); + $this->assertEquals('aa ?> ee', $content); + } + /** + * test unmatched <% + * + */ + public function testUnmatched_asp() + { + $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); + $content = $this->smartyBC->fetch('string:aa <% ee'); + $this->assertEquals('aa <% ee', $content); + } + /** + * test unmatched %> + * + */ + public function testUnmatched_asp_close() + { + $this->smartyBC->setPhpHandling(Smarty::PHP_ALLOW); + $content = $this->smartyBC->fetch('string:aa %> ee'); + $this->assertEquals('aa %> ee', $content); + } + /** + * test unmatched