From fe8598515ff26f8195327b9ad3b6e0f375c54eb8 Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Mon, 4 May 2015 03:07:10 +0200 Subject: [PATCH] 3.1.12 --- .../Compiler/Delimiter/DelimiterTest.php | 10 + .../ResourceTests/File/FileResourceTest.php | 273 ++++++++++++++++++ .../BockExtend/CompileBlockExtendsTest.php | 17 +- .../TagTests/_Attributes/AttributeTest.php | 53 ++-- .../TagTests/_Error/CompileErrorTest.php | 69 ++--- .../ValueTests/Modifier/ModifierTest.php | 4 +- .../LoadPlugin/DefaultPluginHandlerTest.php | 14 + 7 files changed, 356 insertions(+), 84 deletions(-) diff --git a/tests/UnitTests/Compiler/Delimiter/DelimiterTest.php b/tests/UnitTests/Compiler/Delimiter/DelimiterTest.php index 17a89c6f..2575c025 100644 --- a/tests/UnitTests/Compiler/Delimiter/DelimiterTest.php +++ b/tests/UnitTests/Compiler/Delimiter/DelimiterTest.php @@ -67,4 +67,14 @@ class DelimiterTest extends PHPUnit_Smarty $this->assertEquals("hello world", $this->smarty->fetch($tpl)); } + /** + * test {= =} delimiter for conficts with option flags + */ + public function testDelimiter5() + { + $this->smarty->left_delimiter = '{='; + $this->smarty->right_delimiter = '=}'; + $tpl = $this->smarty->createTemplate('eval:{=assign var=foo value="hello world" nocache=}{=$foo=}'); + $this->assertEquals("hello world", $this->smarty->fetch($tpl)); + } } diff --git a/tests/UnitTests/ResourceTests/File/FileResourceTest.php b/tests/UnitTests/ResourceTests/File/FileResourceTest.php index 89c42efe..49123fd1 100644 --- a/tests/UnitTests/ResourceTests/File/FileResourceTest.php +++ b/tests/UnitTests/ResourceTests/File/FileResourceTest.php @@ -235,6 +235,80 @@ class FileResourceTest extends PHPUnit_Smarty $this->fail('Exception for unknown relative filepath has not been raised.'); } + /** + * + * @run InSeparateProcess + * @preserveGlobalState disabled + * + */ + public function testRelativeFetch() + { + $this->smarty->setTemplateDir(array( + dirname(__FILE__) . '/does-not-exist/', + dirname(__FILE__) . '/templates/sub/', + )); + $this->smarty->security_policy = null; + $this->assertEquals('hello world', $this->smarty->fetch('./relative.tpl')); + } + + /** + * + * @run InSeparateProcess + * @preserveGlobalState disabled + * + */ + public function testRelativeFetch2() + { + $this->smarty->setTemplateDir(array( + dirname(__FILE__) . '/does-not-exist/', + dirname(__FILE__) . '/templates/sub/', + )); + $this->smarty->security_policy = null; + $this->assertEquals('hello world', $this->smarty->fetch('../helloworld.tpl')); + } + + /** + * + * @run InSeparateProcess + * @preserveGlobalState disabled + * + */ + public function testRelativeFetchCwd() + { + $cwd = getcwd(); + chdir(dirname(__FILE__) . '/templates/sub/'); + $dn = dirname(__FILE__); + $this->smarty->setCompileDir($dn . '/templates_c/'); + $this->smarty->setCacheDir($dn . '/cache/'); + $this->smarty->setTemplateDir(array( + dirname(__FILE__) . '/does-not-exist/', + )); + $this->smarty->security_policy = null; + $this->assertEquals('hello world', $this->smarty->fetch('./relative.tpl')); + chdir($cwd); + } + + /** + * + * @run InSeparateProcess + * @preserveGlobalState disabled + * + */ + public function testRelativeFetchCwd2() + { + $cwd = getcwd(); + chdir(dirname(__FILE__) . '/templates/sub/'); + $dn = dirname(__FILE__); + $this->smarty->setCompileDir($dn . '/templates_c/'); + $this->smarty->setCacheDir($dn . '/cache/'); + $this->smarty->setTemplateDir(array( + dirname(__FILE__) . '/does-not-exist/', + )); + $this->smarty->security_policy = null; + $this->assertEquals('hello world', $this->smarty->fetch('../helloworld.tpl')); + chdir($cwd); + } + protected function _relativeMap($map, $cwd = null) { foreach ($map as $file => $result) { @@ -274,4 +348,203 @@ class FileResourceTest extends PHPUnit_Smarty chdir($cwd); } } + + public function testRelativity() + { + $this->smarty->security_policy = null; + + $cwd = getcwd(); + $dn = dirname(__FILE__); + $this->smarty->setCompileDir($dn . '/templates_c/'); + $this->smarty->setCacheDir($dn . '/cache/'); + $this->smarty->setTemplateDir(array( + $dn . '/templates/relativity/theory/', + )); + + $map = array( + 'foo.tpl' => 'theory', + './foo.tpl' => 'theory', + '././foo.tpl' => 'theory', + '../foo.tpl' => 'relativity', + '.././foo.tpl' => 'relativity', + './../foo.tpl' => 'relativity', + 'einstein/foo.tpl' => 'einstein', + './einstein/foo.tpl' => 'einstein', + '../theory/einstein/foo.tpl' => 'einstein', + 'templates/relativity/relativity.tpl' => 'relativity', + './templates/relativity/relativity.tpl' => 'relativity', + ); + + $this->_relativeMap($map); + + $this->smarty->setTemplateDir(array( + 'templates/relativity/theory/', + )); + + $map = array( + 'foo.tpl' => 'theory', + './foo.tpl' => 'theory', + '././foo.tpl' => 'theory', + '../foo.tpl' => 'relativity', + '.././foo.tpl' => 'relativity', + './../foo.tpl' => 'relativity', + 'einstein/foo.tpl' => 'einstein', + './einstein/foo.tpl' => 'einstein', + '../theory/einstein/foo.tpl' => 'einstein', + 'templates/relativity/relativity.tpl' => 'relativity', + './templates/relativity/relativity.tpl' => 'relativity', + ); + + $this->_relativeMap($map); + } + + public function testRelativityCwd() + { + $this->smarty->security_policy = null; + + $cwd = getcwd(); + $dn = dirname(__FILE__); + + $this->smarty->setCompileDir($dn . '/templates_c/'); + $this->smarty->setCacheDir($dn . '/cache/'); + $this->smarty->setTemplateDir(array( + $dn . '/templates/', + )); + chdir($dn . '/templates/relativity/theory/'); + + $map = array( + 'foo.tpl' => 'theory', + './foo.tpl' => 'theory', + '././foo.tpl' => 'theory', + '../foo.tpl' => 'relativity', + '.././foo.tpl' => 'relativity', + './../foo.tpl' => 'relativity', + 'einstein/foo.tpl' => 'einstein', + './einstein/foo.tpl' => 'einstein', + '../theory/einstein/foo.tpl' => 'einstein', + ); + + $this->_relativeMap($map, $cwd); + } + + public function testRelativityPrecedence() + { + $this->smarty->security_policy = null; + + $cwd = getcwd(); + $dn = dirname(__FILE__); + + $this->smarty->setCompileDir($dn . '/templates_c/'); + $this->smarty->setCacheDir($dn . '/cache/'); + $this->smarty->setTemplateDir(array( + $dn . '/templates/relativity/theory/einstein/', + )); + + $map = array( + 'foo.tpl' => 'einstein', + './foo.tpl' => 'einstein', + '././foo.tpl' => 'einstein', + '../foo.tpl' => 'theory', + '.././foo.tpl' => 'theory', + './../foo.tpl' => 'theory', + '../../foo.tpl' => 'relativity', + ); + + chdir($dn . '/templates/relativity/theory/'); + $this->_relativeMap($map, $cwd); + + $map = array( + '../theory.tpl' => 'theory', + './theory.tpl' => 'theory', + '../../relativity.tpl' => 'relativity', + '../relativity.tpl' => 'relativity', + './einstein.tpl' => 'einstein', + 'einstein/einstein.tpl' => 'einstein', + './einstein/einstein.tpl' => 'einstein', + ); + + chdir($dn . '/templates/relativity/theory/'); + $this->_relativeMap($map, $cwd); + } + + public function testRelativityRelRel() + { + $this->smarty->security_policy = null; + + $cwd = getcwd(); + $dn = dirname(__FILE__); + + $this->smarty->setCompileDir($dn . '/templates_c/'); + $this->smarty->setCacheDir($dn . '/cache/'); + $this->smarty->setTemplateDir(array( + '../..', + )); + + $map = array( + 'foo.tpl' => 'relativity', + './foo.tpl' => 'relativity', + '././foo.tpl' => 'relativity', + ); + + chdir($dn . '/templates/relativity/theory/einstein'); + $this->_relativeMap($map, $cwd); + + $map = array( + 'relativity.tpl' => 'relativity', + './relativity.tpl' => 'relativity', + 'theory/theory.tpl' => 'theory', + './theory/theory.tpl' => 'theory', + ); + + chdir($dn . '/templates/relativity/theory/einstein/'); + $this->_relativeMap($map, $cwd); + + $map = array( + 'foo.tpl' => 'theory', + './foo.tpl' => 'theory', + 'theory.tpl' => 'theory', + './theory.tpl' => 'theory', + 'einstein/einstein.tpl' => 'einstein', + './einstein/einstein.tpl' => 'einstein', + '../theory/einstein/einstein.tpl' => 'einstein', + '../relativity.tpl' => 'relativity', + './../relativity.tpl' => 'relativity', + '.././relativity.tpl' => 'relativity', + ); + + $this->smarty->setTemplateDir(array( + '..', + )); + chdir($dn . '/templates/relativity/theory/einstein/'); + $this->_relativeMap($map, $cwd); + } + + public function testRelativityRelRel1() + { + $this->smarty->security_policy = null; + + $cwd = getcwd(); + $dn = dirname(__FILE__); + $this->smarty->setCompileDir($dn . '/templates_c/'); + $this->smarty->setCacheDir($dn . '/cache/'); + $this->smarty->setTemplateDir(array( + '..', + )); + + $map = array( + 'foo.tpl' => 'theory', + './foo.tpl' => 'theory', + 'theory.tpl' => 'theory', + './theory.tpl' => 'theory', + 'einstein/einstein.tpl' => 'einstein', + './einstein/einstein.tpl' => 'einstein', + '../theory/einstein/einstein.tpl' => 'einstein', + '../relativity.tpl' => 'relativity', + './../relativity.tpl' => 'relativity', + '.././relativity.tpl' => 'relativity', + ); + + chdir($dn . '/templates/relativity/theory/einstein/'); + $this->_relativeMap($map, $cwd); + } } diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php b/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php index 3492d5cd..74101d4d 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php @@ -202,6 +202,17 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty $this->assertNotContains('should be hidden', $result); } + /** + * test nested child block with hide and auto_literal = false + */ + public function testCompileBlockChildNestedHideAutoLiteralFalse_019() + { + $this->smarty->setAutoLiteral(false); + $result = $this->smarty->fetch('019_child_nested_hide_autoliteral.tpl'); + $this->assertContains('nested block', $result); + $this->assertNotContains('should be hidden', $result); + } + /** * test child/parent template chain starting in subtempates */ @@ -321,7 +332,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * @expectedException SmartyCompilerException - * @expectedExceptionMessage Syntax Error in template ".\templates\025_parent.tpl" + * @expectedExceptionMessage Syntax Error in template ".\templates\025_parent.tpl" * @expectedExceptionMessage {$smarty.block.child} used out of context * test {$this->smarty.block.child} outside {block] */ @@ -332,7 +343,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * @expectedException SmartyCompilerException - * @expectedExceptionMessage Syntax Error in template ".\templates\026_parent.tpl" + * @expectedExceptionMessage Syntax Error in template ".\templates\026_parent.tpl" * @expectedExceptionMessage $smarty.block is invalid * test {$this->smarty.block.parent} outside {block] */ @@ -343,7 +354,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * @expectedException SmartyCompilerException - * @expectedExceptionMessage Syntax Error in template ".\templates\027_parent.tpl" + * @expectedExceptionMessage Syntax Error in template ".\templates\027_parent.tpl" * @expectedExceptionMessage $smarty.block is invalid * test {$this->smarty.block.parent} in parent template */ diff --git a/tests/UnitTests/TemplateSource/TagTests/_Attributes/AttributeTest.php b/tests/UnitTests/TemplateSource/TagTests/_Attributes/AttributeTest.php index 9a2f0585..0ac1e2cb 100644 --- a/tests/UnitTests/TemplateSource/TagTests/_Attributes/AttributeTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/_Attributes/AttributeTest.php @@ -23,67 +23,48 @@ class AttributeTest extends PHPUnit_Smarty { $this->cleanDirs(); } + /** + * @expectedException SmartyCompilerException + * @expectedExceptionMessage Syntax Error in template "b8ecd121bbbc031241b1116a9db691a759eceadf" + * @expectedExceptionMessage missing "var" attribute * test required attribute */ public function testRequiredAttributeVar() { - try { - $this->smarty->fetch('string:{assign value=1}'); - } - catch (Exception $e) { - $this->assertContains('missing "var" attribute', $e->getMessage()); - - return; - } - $this->fail('Exception for required attribute "var" has not been raised.'); + $this->smarty->fetch('string:{assign value=1}'); } /** + * @expectedException SmartyCompilerException + * @expectedExceptionMessage Syntax Error in template "46d3649920e0043f055702ef3ceef0ecdc44b892" + * @expectedExceptionMessage unexpected "bar" attribute * test unexpected attribute */ public function testUnexpectedAttribute() { - try { - $this->smarty->fetch('string:{assign var=foo value=1 bar=2}'); - } - catch (Exception $e) { - $this->assertContains('unexpected "bar" attribute', $e->getMessage()); - - return; - } - $this->fail('Exception for unexpected attribute "bar" has not been raised.'); + $this->smarty->fetch('string:{assign var=foo value=1 bar=2}'); } /** + * @expectedException SmartyCompilerException + * @expectedExceptionMessage Syntax Error in template "d6c824b50e89d8fe12b393ae8ab68daeb7b6c240" + * @expectedExceptionMessage illegal value of option flag "nocache" * test illegal option value */ public function testIllegalOptionValue() { - try { - $this->smarty->fetch('string:{assign var=foo value=1 nocache=buh}'); - } - catch (Exception $e) { - $this->assertContains(htmlentities('illegal value of option flag'), $e->getMessage()); - - return; - } - $this->fail('Exception for illegal value of option flag has not been raised.'); + $this->smarty->fetch('string:{assign var=foo value=1 nocache=buh}'); } /** + * @expectedException SmartyCompilerException + * @expectedExceptionMessage Syntax Error in template "a119616ffa139e7b1145b1cd36adbff7bc9be7cf" + * @expectedExceptionMessage too many shorthand attributes * test too many shorthands */ public function testTooManyShorthands() { - try { - $this->smarty->fetch('string:{assign foo 1 2}'); - } - catch (Exception $e) { - $this->assertContains('too many shorthand attributes', $e->getMessage()); - - return; - } - $this->fail('Exception for too many shorthand attributes has not been raised.'); + $this->smarty->fetch('string:{assign foo 1 2}'); } } diff --git a/tests/UnitTests/TemplateSource/TagTests/_Error/CompileErrorTest.php b/tests/UnitTests/TemplateSource/TagTests/_Error/CompileErrorTest.php index a433d764..bbd63eab 100644 --- a/tests/UnitTests/TemplateSource/TagTests/_Error/CompileErrorTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/_Error/CompileErrorTest.php @@ -24,57 +24,40 @@ class CompileErrorTest extends PHPUnit_Smarty } /** + * @expectedException SmartyException + * @expectedExceptionMessage Unable to load template file 'no.tpl' in 'eval:{include file='no.tpl'}' * test none existing template file error */ public function testNoneExistingTemplateError() { - try { - $this->smarty->fetch('eval:{include file=\'no.tpl\'}'); - } - catch (Exception $e) { - $this->assertContains('Unable to load template', $e->getMessage()); - - return; - } - $this->fail('Exception for none existing template has not been raised.'); - } - - /** - * test unkown tag error - */ - public function testUnknownTagError() - { - try { - $this->smarty->fetch('eval:{unknown}'); - } - catch (Exception $e) { - $this->assertContains('unknown tag "unknown"', $e->getMessage()); - - return; - } - $this->fail('Exception for unknown Smarty tag has not been raised.'); - } - - /** - * test unclosed tag error - */ - public function testUnclosedTagError() - { - try { - $this->smarty->fetch('eval:{if true}'); - } - catch (Exception $e) { - $this->assertContains('unclosed {if} tag', $e->getMessage()); - - return; - } - $this->fail('Exception for unclosed Smarty tags has not been raised.'); + $this->smarty->fetch('eval:{include file=\'no.tpl\'}'); } /** * @expectedException SmartyCompilerException - * @expectedExceptionMessage Syntax Error in template "599a9cf0e3623a3206bd02a0f5c151d5f5f3f69e" - * @expectedExceptionMessage Unexpected "}" + * @expectedExceptionMessage Syntax Error in template "2510bcd51cbc69725f2c3d3484b2c70c00ddaeba" + * @expectedExceptionMessage unknown tag "unknown" + * test unkown tag error + */ + public function testUnknownTagError() + { + $this->smarty->fetch('eval:{unknown}'); + } + + /** + * @expectedException SmartyCompilerException + * @expectedExceptionMessage unclosed {if} tag + * test unclosed tag error + */ + public function testUnclosedTagError() + { + $this->smarty->fetch('eval:{if true}'); + } + + /** + * @expectedException SmartyCompilerException + * @expectedExceptionMessage Syntax Error in template "599a9cf0e3623a3206bd02a0f5c151d5f5f3f69e" + * @expectedExceptionMessage Unexpected "}" * test syntax error */ public function testSyntaxError() diff --git a/tests/UnitTests/TemplateSource/ValueTests/Modifier/ModifierTest.php b/tests/UnitTests/TemplateSource/ValueTests/Modifier/ModifierTest.php index fb656f99..969ec878 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/Modifier/ModifierTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/Modifier/ModifierTest.php @@ -166,8 +166,8 @@ class ModifierTest extends PHPUnit_Smarty /** * @expectedException SmartyCompilerException - * @expectedExceptionMessage Syntax Error in template "4d2e368c483a648d14bbd59592da92aff3b96a2f" - * @expectedExceptionMessage unknown modifier "unknown" + * @expectedExceptionMessage Syntax Error in template "4d2e368c483a648d14bbd59592da92aff3b96a2f" + * @expectedExceptionMessage unknown modifier "unknown" * test unknown modifier error */ public function testUnknownModifier() diff --git a/tests/UnitTests/_Core/LoadPlugin/DefaultPluginHandlerTest.php b/tests/UnitTests/_Core/LoadPlugin/DefaultPluginHandlerTest.php index 76d0cd18..b97fad03 100644 --- a/tests/UnitTests/_Core/LoadPlugin/DefaultPluginHandlerTest.php +++ b/tests/UnitTests/_Core/LoadPlugin/DefaultPluginHandlerTest.php @@ -71,6 +71,20 @@ class DefaultPluginHandlerTest extends PHPUnit_Smarty $this->smarty->assign('foo', 'bar'); $this->assertEquals("localmodifier bar", $this->smarty->fetch('test_default_modifier.tpl')); } + + public function testDefaultModifierStaticClassMethodCaching1() + { + $this->smarty->assign('foo', 'bar'); + $this->smarty->caching = 1; + $this->assertEquals("staticmodifier bar", $this->smarty->fetch('test_default_static_modifier.tpl')); + } + + public function testDefaultModifierStaticClassMethodCaching2() + { + $this->smarty->assign('foo', 'bar'); + $this->smarty->caching = 1; + $this->assertEquals("staticmodifier bar", $this->smarty->fetch('test_default_static_modifier.tpl')); + } } function my_plugin_handler($tag, $type, $template, &$callback, &$script, &$cachable)