From d5c98592412937ff07238210fe50a73e998730f6 Mon Sep 17 00:00:00 2001 From: uwetews Date: Sat, 29 Aug 2015 14:23:14 +0200 Subject: [PATCH] Update tests --- tests/PHPUnit_Smarty.php | 2 - .../OutputFilterTrimWhitespaceTest.php | 5 ++ .../PluginTests/PluginChainedLoadTest.php | 5 ++ .../ResourceExtendsAllPluginTest.php | 2 +- .../Extends/ExtendsResourceTest.php | 81 ++++++++++++++--- .../Extends/templates/003_parent.tpl | 1 + .../Extends/templates/004_parent.tpl | 1 + .../Extends/templates/040_parent.tpl | 3 +- .../BockExtend/CompileBlockExtendsTest.php | 90 +++++++++++++++++-- .../BockExtend/templates/002_parent.tpl | 1 + .../BockExtend/templates/008_child_plugin.tpl | 2 +- .../BockExtend/templates/012_child.tpl | 2 +- .../BockExtend/templates/013_child.tpl | 2 +- .../BockExtend/templates/026_child.tpl | 2 + .../BockExtend/templates/028_parent.tpl | 1 + .../PluginModifierCountSentencesTest.php | 5 ++ 16 files changed, 179 insertions(+), 26 deletions(-) create mode 100644 tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/026_child.tpl diff --git a/tests/PHPUnit_Smarty.php b/tests/PHPUnit_Smarty.php index f16ee302..3d9b33c2 100644 --- a/tests/PHPUnit_Smarty.php +++ b/tests/PHPUnit_Smarty.php @@ -132,9 +132,7 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase if (individualFolders != 'true') { if (!isset($s_dir[$dir])) { $this->cleanDir($dir . '/templates_c'); - file_put_contents($dir . '/templates_c/dummy.txt', ' '); $this->cleanDir($dir . '/cache'); - file_put_contents($dir . '/cache/dummy.txt', ' '); $s_dir[$dir] = true; } $dir = __DIR__; diff --git a/tests/UnitTests/A_Core/PluginTests/OutputFilterTrimWhitespaceTest.php b/tests/UnitTests/A_Core/PluginTests/OutputFilterTrimWhitespaceTest.php index f36e2718..bc067ff9 100644 --- a/tests/UnitTests/A_Core/PluginTests/OutputFilterTrimWhitespaceTest.php +++ b/tests/UnitTests/A_Core/PluginTests/OutputFilterTrimWhitespaceTest.php @@ -19,6 +19,11 @@ class OutputFilterTrimWhitespaceTest extends PHPUnit_Smarty $this->smarty->loadFilter('output', 'trimwhitespace'); } + public function testInit() + { + $this->cleanDirs(); + } + public function testWhitespace() { $expected = diff --git a/tests/UnitTests/A_Core/PluginTests/PluginChainedLoadTest.php b/tests/UnitTests/A_Core/PluginTests/PluginChainedLoadTest.php index a3ae089b..4b5b12b0 100644 --- a/tests/UnitTests/A_Core/PluginTests/PluginChainedLoadTest.php +++ b/tests/UnitTests/A_Core/PluginTests/PluginChainedLoadTest.php @@ -18,6 +18,11 @@ class PluginChainedLoadTest extends PHPUnit_Smarty $this->setUpSmarty(__DIR__); } + public function testInit() + { + $this->cleanDirs(); + } + public function testPluginChainedLoad() { $this->smarty->addPluginsDir(__DIR__ . "/PHPunitplugins/"); diff --git a/tests/UnitTests/ResourceTests/Custom/DemoPluginExtendsAll/ResourceExtendsAllPluginTest.php b/tests/UnitTests/ResourceTests/Custom/DemoPluginExtendsAll/ResourceExtendsAllPluginTest.php index 37578418..aaeb2bf8 100644 --- a/tests/UnitTests/ResourceTests/Custom/DemoPluginExtendsAll/ResourceExtendsAllPluginTest.php +++ b/tests/UnitTests/ResourceTests/Custom/DemoPluginExtendsAll/ResourceExtendsAllPluginTest.php @@ -34,7 +34,7 @@ class ResourceExtendsAllPluginTest extends PHPUnit_Smarty './templates_4', )); - $expected = "templates\n\n templates_3\n templates\n\ntemplates_4"; + $expected = "templates\n templates_3\n templates\n\ntemplates_4"; $this->assertEquals($expected, $this->smarty->fetch('extendsall:extendsall.tpl')); } diff --git a/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php b/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php index 292f0d22..c152207d 100644 --- a/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php +++ b/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php @@ -23,29 +23,70 @@ class ExtendsResourceTest extends PHPUnit_Smarty { $this->cleanDirs(); } + + public function compiledPrefilter($text, Smarty_Internal_Template $tpl) + { + return str_replace('#', $tpl->_getVariable('test'), $text); + } + /** * test child/parent template chain with prepend + * @dataProvider data */ - public function testCompileBlockChildPrepend_003() + public function testCompileBlockChildPrepend_003($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName) { + $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); + $this->smarty->assign('test', $testNumber); + $this->smarty->caching = $caching; + $this->smarty->inheritance_merge_compiled_includes = $merge; + if ($merge) { + $this->smarty->compile_id = 1; + } $result = $this->smarty->fetch('extends:003_parent.tpl|003_child_prepend.tpl'); - $this->assertContains("prepend - Default Title", $result); + $this->assertContains("prepend - Default Title", $result, $testName . ' - content'); + $this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure'); } /** * test child/parent template chain with apppend + * @dataProvider data */ - public function testCompileBlockChildAppend_004() + public function testCompileBlockChildAppend_004($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName) { - $this->smarty->merge_compiled_includes = true; + $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); + $this->smarty->assign('test', $testNumber); + $this->smarty->caching = $caching; + $this->smarty->inheritance_merge_compiled_includes = $merge; + if ($merge) { + $this->smarty->compile_id = 1; + } $result = $this->smarty->fetch('extends:004_parent.tpl|004_child_append.tpl'); - $this->assertContains("Default Title - append", $result); + $this->assertContains("Default Title - append", $result, $testName . ' - content'); + $this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure'); } + + /** + * test child/parent template chain with apppend + * @dataProvider data + */ + public function testCompileBlockAssignInChild_040($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName) + { + $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); + $this->smarty->assign('test', $testNumber); + $this->smarty->caching = $caching; + $this->smarty->inheritance_merge_compiled_includes = $merge; + if ($merge) { + $this->smarty->compile_id = 1; + } + $result = $this->smarty->fetch('extends:040_parent.tpl|040_child.tpl'); + $this->assertContains("var-bar-var", $result, $testName . ' - content'); + $this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure'); + } + /** * 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'); @@ -124,14 +165,26 @@ class ExtendsResourceTest extends PHPUnit_Smarty $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); + + public function data(){ + return array( + /* + * caching + * merging + * test nr + * result compile nr + * result render nr + * text + */ + array(false, false, 1, 1, 1, 'no caching, no merge - new'), + array(false, false, 2, 1, 2, 'no caching, no merge - exits'), + array(true, false, 3, 3, 3, 'caching, no merge - new'), + array(true, false, 4, 3, 3, 'caching, no merge - exits'), + array(false, true, 5, 5, 5, 'no caching, merge - new'), + array(false, true, 6, 5, 6, 'no caching, merge - exits'), + array(true, true, 7, 7, 7, 'caching, merge - new'), + array(true, true, 8, 7, 7, 'caching, merge - exits'), + ); } } diff --git a/tests/UnitTests/ResourceTests/Extends/templates/003_parent.tpl b/tests/UnitTests/ResourceTests/Extends/templates/003_parent.tpl index e007864b..afcf7d7c 100644 --- a/tests/UnitTests/ResourceTests/Extends/templates/003_parent.tpl +++ b/tests/UnitTests/ResourceTests/Extends/templates/003_parent.tpl @@ -1 +1,2 @@ +test:{$test nocache} compiled:# rendered:{$test} {block name='title'}Default Title{/block} diff --git a/tests/UnitTests/ResourceTests/Extends/templates/004_parent.tpl b/tests/UnitTests/ResourceTests/Extends/templates/004_parent.tpl index e007864b..afcf7d7c 100644 --- a/tests/UnitTests/ResourceTests/Extends/templates/004_parent.tpl +++ b/tests/UnitTests/ResourceTests/Extends/templates/004_parent.tpl @@ -1 +1,2 @@ +test:{$test nocache} compiled:# rendered:{$test} {block name='title'}Default Title{/block} diff --git a/tests/UnitTests/ResourceTests/Extends/templates/040_parent.tpl b/tests/UnitTests/ResourceTests/Extends/templates/040_parent.tpl index 901a2b09..85d2795a 100644 --- a/tests/UnitTests/ResourceTests/Extends/templates/040_parent.tpl +++ b/tests/UnitTests/ResourceTests/Extends/templates/040_parent.tpl @@ -1 +1,2 @@ -{block name='test'}-{$foo}-{/block} +test:{$test nocache} compiled:# rendered:{$test} +{block name='test'}var-{$foo}-var{/block} diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php b/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php index f507c358..4f14b4d0 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php @@ -19,6 +19,11 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty } + public function compiledPrefilter($text, Smarty_Internal_Template $tpl) + { + return str_replace('#', $tpl->_getVariable('test'), $text); + } + public function testInit() { $this->cleanDirs(); @@ -50,11 +55,20 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test child/parent template chain + * @dataProvider data */ - public function testCompileBlockChild_002() + public function testCompileBlockChild_002($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName) { + $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); + $this->smarty->assign('test', $testNumber); + $this->smarty->caching = $caching; + $this->smarty->merge_compiled_includes = $merge; + if ($merge) { + $this->smarty->compile_id = 1; + } $result = $this->smarty->fetch('002_child.tpl'); - $this->assertContains('Page Title', $result); + $this->assertContains('Page Title', $result, $testName . ' - content'); + $this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure'); } /** @@ -104,13 +118,16 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test child/parent template chain loading plugin + * @run SeparateProcess + * @preserveGlobalState disabled */ public function testCompileBlockChildPlugin_008() { $result = $this->smarty->fetch('008_child_plugin.tpl'); - $this->assertContains('escaped <text>', $result); + $this->assertContains('escaped <text> 1', $result); } + /** * test parent template with nested blocks */ @@ -350,16 +367,79 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty */ public function testSmartyBlockParentOutsideBlock_026() { - $this->smarty->fetch('026_parent.tpl'); + $this->smarty->fetch('026_child.tpl'); } /** * @expectedException SmartyCompilerException - * @expectedExceptionMessage illegal {$smarty.block.parent} in parent template + * @expectedExceptionMessage tag {$smarty.block.parent} used in parent template * test {$this->smarty.block.parent} in parent template */ public function testSmartyBlockParentInParent_027() { $result = $this->smarty->fetch('027_parent.tpl'); } + + + /** + * test child/parent template chain + * @dataProvider data + */ + public function testSmartyBlockVariablePartentInclude_28($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName) + { + $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); + $this->smarty->assign('test', $testNumber); + $this->smarty->caching = $caching; + $this->smarty->merge_compiled_includes = $merge; + $this->smarty->compile_id = 10; + if ($merge) { + $this->smarty->compile_id = 11; + } + $this->smarty->assign('foo', '028_parent_include1.tpl'); + $result = $this->smarty->fetch('028_child.tpl'); + $this->assertContains('b1-include-1--b1', $result, $testName . ' - content'); + $this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure'); + } + + /** + * test child/parent template chain + * @dataProvider data + */ + public function testSmartyBlockVariablePartentInclude_282($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName) + { + $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); + $this->smarty->assign('test', $testNumber); + $this->smarty->caching = $caching; + $this->smarty->merge_compiled_includes = $merge; + if ($merge) { + $this->smarty->compile_id = 1; + } + $this->smarty->assign('foo', '028_parent_include2.tpl'); + $result = $this->smarty->fetch('028_child.tpl'); + $this->assertContains('b1-child-i2-include-2--b1', $result, $testName . ' - content'); + $this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure'); + } + + + + public function data(){ + return array( + /* + * caching + * merging + * test nr + * result compile nr + * result render nr + * text + */ + array(false, false, 1, 1, 1, 'no caching, no merge - new'), + array(false, false, 2, 1, 2, 'no caching, no merge - exits'), + array(true, false, 3, 3, 3, 'caching, no merge - new'), + array(true, false, 4, 3, 3, 'caching, no merge - exits'), + array(false, true, 5, 5, 5, 'no caching, merge - new'), + array(false, true, 6, 5, 6, 'no caching, merge - exits'), + array(true, true, 7, 7, 7, 'caching, merge - new'), + array(true, true, 8, 7, 7, 'caching, merge - exits'), + ); + } } diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/002_parent.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/002_parent.tpl index e007864b..afcf7d7c 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/002_parent.tpl +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/002_parent.tpl @@ -1 +1,2 @@ +test:{$test nocache} compiled:# rendered:{$test} {block name='title'}Default Title{/block} diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/008_child_plugin.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/008_child_plugin.tpl index c846670a..54f67d6c 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/008_child_plugin.tpl +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/008_child_plugin.tpl @@ -1,2 +1,2 @@ {extends file='008_parent.tpl'} -{block name='title'}{'escaped '|escape}{/block} +{block name='title'}{'escaped '|escape} {counter start=1}{/block} diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/012_child.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/012_child.tpl index bac2cf93..939195b3 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/012_child.tpl +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/012_child.tpl @@ -1,2 +1,2 @@ -{extends file='002_parent.tpl'} +{extends file='012_parent.tpl'} {block name='title'}Page Title{/block} diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/013_child.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/013_child.tpl index bac2cf93..c90c1024 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/013_child.tpl +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/013_child.tpl @@ -1,2 +1,2 @@ -{extends file='002_parent.tpl'} +{extends file='013_parent.tpl'} {block name='title'}Page Title{/block} diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/026_child.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/026_child.tpl new file mode 100644 index 00000000..88cbbe41 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/026_child.tpl @@ -0,0 +1,2 @@ +{extends '026_parent.tpl'} +{$smarty.block.parent}{block 'b1'}{/block} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/028_parent.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/028_parent.tpl index ab2e31ff..1d8cee2f 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/028_parent.tpl +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/028_parent.tpl @@ -1 +1,2 @@ +test:{$test nocache} compiled:# rendered:{$test} {block 'b1'}b1-{include $foo}-b1{/block} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountSentencesTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountSentencesTest.php index 3dfef9c3..db3f6cb7 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountSentencesTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginModifier/PluginModifierCountSentencesTest.php @@ -18,6 +18,11 @@ class PluginModifierCountSentencesTest extends PHPUnit_Smarty $this->setUpSmarty(__DIR__); } + public function testInit() + { + $this->cleanDirs(); + } + public function testDefault() { $tpl = $this->smarty->createTemplate('string:{"hello world."|count_sentences}');