From a341b00676d4355911d88327717302edde9d6fc7 Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Mon, 26 Mar 2018 22:26:49 +0200 Subject: [PATCH] new feature {parent} = {$smarty.block.parent} {child} = {$smarty.block.child} --- .../BockExtend/CompileBlockExtendsTest.php | 202 +++++++++++++++++- .../BockExtend/templates/034_1child.tpl | 2 + .../BockExtend/templates/034_2child.tpl | 2 + .../BockExtend/templates/034_3child.tpl | 2 + .../BockExtend/templates/034_4child.tpl | 2 + .../BockExtend/templates/034_child.tpl | 2 - .../BockExtend/templates/035_1parent.tpl | 2 + .../BockExtend/templates/035_2parent.tpl | 2 + .../BockExtend/templates/035_3parent.tpl | 2 + .../BockExtend/templates/035_4parent.tpl | 2 + .../BockExtend/templates/035_child.tpl | 2 +- .../BockExtend/templates/035_parent.tpl | 2 - .../BockExtend/templates/036_1_parent.tpl | 1 + .../BockExtend/templates/036_2_parent.tpl | 1 + .../BockExtend/templates/036_3_parent.tpl | 1 + 15 files changed, 211 insertions(+), 16 deletions(-) create mode 100644 tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_1child.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_2child.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_3child.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_4child.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_child.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_1parent.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_2parent.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_3parent.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_4parent.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_parent.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_1_parent.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_2_parent.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_3_parent.tpl diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php b/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php index df0108f2..52fe6ffe 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/CompileBlockExtendsTest.php @@ -245,7 +245,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * test child/parent template chain with {$this->smarty.block.child) * - * @runInSeparateProcess + * @run InSeparateProcess * @preserveGlobalState disabled * @dataProvider data */ @@ -752,7 +752,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * @expectedException SmartyCompilerException - * @expectedExceptionMessage '$smarty.block.child' used outside {block} tags + * @expectedExceptionMessage '{$smarty.block.child}' used outside {block} tags * test {$this->smarty.block.child} outside {block] */ public function testSmartyBlockChildOutsideBlock_025() @@ -762,7 +762,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * @expectedException SmartyCompilerException - * @expectedExceptionMessage '$smarty.block.parent' used outside {block} tags + * @expectedExceptionMessage '{$smarty.block.parent}' used outside {block} tags * test {$this->smarty.block.parent} outside {block] */ public function testSmartyBlockParentOutsideBlock_026() @@ -772,7 +772,7 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty /** * @expectedException SmartyException - * @expectedExceptionMessage illegal '$smarty.block.parent' + * @expectedExceptionMessage illegal '{$smarty.block.parent}' * test {$this->smarty.block.parent} in parent template */ public function testSmartyBlockParentInParent_027() @@ -873,15 +873,15 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty $this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure'); } - /** + /** * test grandchild/child/parent template chain with nested {$this->smarty.block.child} and {include nocache} * * @runInSeparateProcess * @preserveGlobalState disabled * @dataProvider data */ - public function testCompileBlockSmartyBlockParent_034($caching, $merge, $testNumber, $compileTestNumber, - $renderTestNumber, $testName) + public function testCompileBlockSmartyBlockParent_034_1($caching, $merge, $testNumber, $compileTestNumber, + $renderTestNumber, $testName) { $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); $this->smarty->assign('test', $testNumber); @@ -890,7 +890,73 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty if ($merge) { $this->smarty->setCompileId(1); } - $result = $this->smarty->fetch('034_child.tpl'); + $result = $this->smarty->fetch('034_1child.tpl'); + $this->assertContains('parent b1', $result, $testName . ' - content'); + $this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, + $testName . ' - fetch() failure'); + } + /** + * test grandchild/child/parent template chain with nested {$this->smarty.block.child} and {include nocache} + * + * @runInSeparateProcess + * @preserveGlobalState disabled + * @dataProvider data + */ + public function testCompileBlockSmartyBlockParent_034_2($caching, $merge, $testNumber, $compileTestNumber, + $renderTestNumber, $testName) + { + $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); + $this->smarty->assign('test', $testNumber); + $this->smarty->setCaching($caching); + $this->smarty->setMergeCompiledIncludes($merge); + if ($merge) { + $this->smarty->setCompileId(1); + } + $result = $this->smarty->fetch('034_2child.tpl'); + $this->assertContains('parent b1', $result, $testName . ' - content'); + $this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, + $testName . ' - fetch() failure'); + } + /** + * test grandchild/child/parent template chain with nested {$this->smarty.block.child} and {include nocache} + * + * @runInSeparateProcess + * @preserveGlobalState disabled + * @dataProvider data + */ + public function testCompileBlockSmartyBlockParent_034_3($caching, $merge, $testNumber, $compileTestNumber, + $renderTestNumber, $testName) + { + $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); + $this->smarty->assign('test', $testNumber); + $this->smarty->setCaching($caching); + $this->smarty->setMergeCompiledIncludes($merge); + if ($merge) { + $this->smarty->setCompileId(1); + } + $result = $this->smarty->fetch('034_3child.tpl'); + $this->assertContains('parent b1', $result, $testName . ' - content'); + $this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, + $testName . ' - fetch() failure'); + } + /** + * test grandchild/child/parent template chain with nested {$this->smarty.block.child} and {include nocache} + * + * @runInSeparateProcess + * @preserveGlobalState disabled + * @dataProvider data + */ + public function testCompileBlockSmartyBlockParent_034_4($caching, $merge, $testNumber, $compileTestNumber, + $renderTestNumber, $testName) + { + $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); + $this->smarty->assign('test', $testNumber); + $this->smarty->setCaching($caching); + $this->smarty->setMergeCompiledIncludes($merge); + if ($merge) { + $this->smarty->setCompileId(1); + } + $result = $this->smarty->fetch('034_4child.tpl'); $this->assertContains('parent b1', $result, $testName . ' - content'); $this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, $testName . ' - fetch() failure'); @@ -902,11 +968,12 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty * @preserveGlobalState disabled * @dataProvider data */ - public function testCompileBlockSmartyBlockChild_035($caching, $merge, $testNumber, $compileTestNumber, + public function testCompileBlockSmartyBlockChild_035_1($caching, $merge, $testNumber, $compileTestNumber, $renderTestNumber, $testName) { $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); $this->smarty->assign('test', $testNumber); + $this->smarty->assign('parenttpl', '035_1parent.tpl'); $this->smarty->assign('parent', 'parent', true); $this->smarty->assign('child', 'child', true); $this->smarty->setCaching($caching); @@ -921,6 +988,86 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty $testName . ' - fetch() failure'); } + /** + * test child/parent template chain with {$this->smarty.block.child) + * + * @runInSeparateProcess + * @preserveGlobalState disabled + * @dataProvider data + */ + public function testCompileBlockSmartyBlockChild_035_2($caching, $merge, $testNumber, $compileTestNumber, + $renderTestNumber, $testName) + { + $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); + $this->smarty->assign('test', $testNumber); + $this->smarty->assign('parenttpl', '035_2parent.tpl'); + $this->smarty->assign('parent', 'parent', true); + $this->smarty->assign('child', 'child', true); + $this->smarty->setCaching($caching); + $this->smarty->setMergeCompiledIncludes($merge); + if ($merge) { + $this->smarty->setCompileId(1); + } + $result = $this->smarty->fetch('035_child.tpl'); + $this->assertContains('(parent|b)content (child|b)content child b(child|/b) b(parent|/b)', $result, + $testName . ' - content'); + $this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, + $testName . ' - fetch() failure'); + } + /** + * test child/parent template chain with {$this->smarty.block.child) + * + * @runInSeparateProcess + * @preserveGlobalState disabled + * @dataProvider data + */ + public function testCompileBlockSmartyBlockChild_035_3($caching, $merge, $testNumber, $compileTestNumber, + $renderTestNumber, $testName) + { + $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); + $this->smarty->assign('test', $testNumber); + $this->smarty->assign('parenttpl', '035_3parent.tpl'); + $this->smarty->assign('parent', 'parent', true); + $this->smarty->assign('child', 'child', true); + $this->smarty->setCaching($caching); + $this->smarty->setMergeCompiledIncludes($merge); + if ($merge) { + $this->smarty->setCompileId(1); + } + $result = $this->smarty->fetch('035_child.tpl'); + $this->assertContains('(parent|b)content (child|b)content child b(child|/b) b(parent|/b)', $result, + $testName . ' - content'); + $this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, + $testName . ' - fetch() failure'); + } + /** + * test child/parent template chain with {$this->smarty.block.child) + * + * @runInSeparateProcess + * @preserveGlobalState disabled + * @dataProvider data + */ + public function testCompileBlockSmartyBlockChild_035_4($caching, $merge, $testNumber, $compileTestNumber, + $renderTestNumber, $testName) + { + $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); + $this->smarty->assign('test', $testNumber); + $this->smarty->assign('parenttpl', '035_4parent.tpl'); + $this->smarty->assign('parent', 'parent', true); + $this->smarty->assign('child', 'child', true); + $this->smarty->setCaching($caching); + $this->smarty->setMergeCompiledIncludes($merge); + if ($merge) { + $this->smarty->setCompileId(1); + } + $result = $this->smarty->fetch('035_child.tpl'); + $this->assertContains('(parent|b)content (child|b)content child b(child|/b) b(parent|/b)', $result, + $testName . ' - content'); + $this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", $result, + $testName . ' - fetch() failure'); + } + + public function data() { @@ -998,19 +1145,52 @@ class CompileBlockExtendsTest extends PHPUnit_Smarty * test smarty.block.foo * * @expectedException SmartyCompilerException - * @expectedExceptionMessage invalid '$smarty.block.foo' expected '$smarty.block.child' or '$smarty.block.parent' + * @expectedExceptionMessage $smarty.block is not defined */ public function testSmartyBlockWrongBlockName_036() { $this->smarty->fetch('036_parent.tpl'); } + /** + * + * test '{$smarty.block.parent}' + * + * @expectedException SmartyException + * @expectedExceptionMessage inheritance: illegal '{$smarty.block.parent}' used in child template + */ + public function testSmartyParentBlockCalledInParent_036_1() + { + $this->smarty->fetch('036_1_parent.tpl'); + } + /** + * + * test {block_parent} + * + * @expectedException SmartyException + * @expectedExceptionMessage inheritance: illegal '{block_parent}' used in child template + */ + public function testSmartyParentBlockCalledInParent_036_2() + { + $this->smarty->fetch('036_2_parent.tpl'); + } + /** + * + * test {block_parent} + * + * @expectedException SmartyException + * @expectedExceptionMessage inheritance: illegal '{parent}' used in child template + */ + public function testSmartyParentBlockCalledInParent_036_3() + { + $this->smarty->fetch('036_3_parent.tpl'); + } /** * * test smarty.block * * @expectedException SmartyCompilerException - * @expectedExceptionMessage invalid '$smarty.block' expected '$smarty.block.child' or '$smarty.block.parent' + * @expectedExceptionMessage $smarty.block is not defined */ public function testSmartyBlockMissigBlockName_037() { diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_1child.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_1child.tpl new file mode 100644 index 00000000..58501aec --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_1child.tpl @@ -0,0 +1,2 @@ +{extends '034_parent.tpl'} +{block 'b1'}{$smarty.block.parent}{/block} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_2child.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_2child.tpl new file mode 100644 index 00000000..07ff346b --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_2child.tpl @@ -0,0 +1,2 @@ +{extends '034_parent.tpl'} +{block 'b1'}{parent assign='foo'}{$foo}{/block} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_3child.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_3child.tpl new file mode 100644 index 00000000..a4e701b0 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_3child.tpl @@ -0,0 +1,2 @@ +{extends '034_parent.tpl'} +{block 'b1'}{parent}{/block} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_4child.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_4child.tpl new file mode 100644 index 00000000..431145fd --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_4child.tpl @@ -0,0 +1,2 @@ +{extends '034_parent.tpl'} +{block 'b1'}{block_parent}{/block} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_child.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_child.tpl deleted file mode 100644 index ebbb9b6d..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/034_child.tpl +++ /dev/null @@ -1,2 +0,0 @@ -{extends '034_parent.tpl'} -{block 'b1'}{$foo=$smarty.block.parent}{$foo}{/block} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_1parent.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_1parent.tpl new file mode 100644 index 00000000..9774ebb4 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_1parent.tpl @@ -0,0 +1,2 @@ +test:{$test nocache} compiled:# rendered:{$test} +{block name='b'}(parent|b)content {$smarty.block.child} b(parent|/b){/block} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_2parent.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_2parent.tpl new file mode 100644 index 00000000..06fed627 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_2parent.tpl @@ -0,0 +1,2 @@ +test:{$test nocache} compiled:# rendered:{$test} +{block name='b'}(parent|b)content {child assign='foo'}{$foo} b(parent|/b){/block} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_3parent.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_3parent.tpl new file mode 100644 index 00000000..1ada9dfa --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_3parent.tpl @@ -0,0 +1,2 @@ +test:{$test nocache} compiled:# rendered:{$test} +{block name='b'}(parent|b)content {child} b(parent|/b){/block} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_4parent.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_4parent.tpl new file mode 100644 index 00000000..9cea0612 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_4parent.tpl @@ -0,0 +1,2 @@ +test:{$test nocache} compiled:# rendered:{$test} +{block name='b'}(parent|b)content {block_child} b(parent|/b){/block} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_child.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_child.tpl index 494b114f..d0435049 100644 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_child.tpl +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_child.tpl @@ -1,2 +1,2 @@ -{extends file='035_parent.tpl'} +{extends file=$parenttpl} {block name='b'}(child|b)content {$child} b(child|/b){/block} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_parent.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_parent.tpl deleted file mode 100644 index 856269bb..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/035_parent.tpl +++ /dev/null @@ -1,2 +0,0 @@ -test:{$test nocache} compiled:# rendered:{$test} -{block name='b'}(parent|b)content {$foo=$smarty.block.child}{$foo} b(parent|/b){/block} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_1_parent.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_1_parent.tpl new file mode 100644 index 00000000..b1432cf2 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_1_parent.tpl @@ -0,0 +1 @@ +{block name='b'}{$smarty.block.parent}{/block} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_2_parent.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_2_parent.tpl new file mode 100644 index 00000000..f96cb679 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_2_parent.tpl @@ -0,0 +1 @@ +{block name='b'}{block_parent}{/block} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_3_parent.tpl b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_3_parent.tpl new file mode 100644 index 00000000..6c8516f2 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/BockExtend/templates/036_3_parent.tpl @@ -0,0 +1 @@ +{block name='b'}{parent}{/block} \ No newline at end of file