From 48a954e2e5370401f13f24edb58397fa15ff9bb6 Mon Sep 17 00:00:00 2001 From: uwetews Date: Thu, 29 Sep 2016 03:44:49 +0200 Subject: [PATCH] Add test for Smarty::$extends_recursion property --- .../Extends/ExtendsResourceTest.php | 56 ++++++++++++++++++- .../Extends/templates/034_child.tpl | 3 + .../Extends/templates/034_grandchild.tpl | 3 + .../Extends/templates/034_parent.tpl | 4 ++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 tests/UnitTests/ResourceTests/Extends/templates/034_child.tpl create mode 100644 tests/UnitTests/ResourceTests/Extends/templates/034_grandchild.tpl create mode 100644 tests/UnitTests/ResourceTests/Extends/templates/034_parent.tpl diff --git a/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php b/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php index 631f7606..15b4bebe 100644 --- a/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php +++ b/tests/UnitTests/ResourceTests/Extends/ExtendsResourceTest.php @@ -225,7 +225,7 @@ class ExtendsResourceTest extends PHPUnit_Smarty /** * test relative includes in {block} * - * @run InSeparateProcess + * @runInSeparateProcess * @preserveGlobalState disabled * @dataProvider data */ @@ -266,6 +266,60 @@ class ExtendsResourceTest extends PHPUnit_Smarty array(true, true, 8, 7, 7, 'caching, merge - exits'), ); } + /** + * test relative includes in {block} + * + * @runInSeparateProcess + * @preserveGlobalState disabled + * @dataProvider data2 + */ + public function testCompileBlockExtendsRecursion_034($extends_recursion, $merge, $testNumber, $compileTestNumber, + $renderTestNumber, $testName) + { + if (!property_exists($this->smarty, 'extends_recursion')) { + $this->markTestSkipped('no extends_recursion'); + } else { + $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); + $this->smarty->assign('test', $testNumber); + $this->smarty->setExtendsRecursion($extends_recursion); + $this->smarty->setMergeCompiledIncludes($merge); + $cid = 0; + if ($merge) { + $cid = 1; + } + if ($extends_recursion) { + $cid += 2; + } + $this->smarty->setCompileId($cid); + $result = $this->smarty->fetch('extends:034_parent.tpl|034_grandchild.tpl'); + $this->assertContains('grandchild - grandchild', $result, $testName . ' - grand'); + $this->assertContains('parent - parent', $result, $testName . ' - grand'); + $this->assertContains($extends_recursion ? 'child - child' : 'child - parent', $result, + $testName . ' - grand'); + $this->assertContains("test:{$testNumber} compiled:{$compileTestNumber} rendered:{$renderTestNumber}", + $result, $testName . ' - fetch() failure'); + } + } + public function data2(){ + return array( + /* + * extends_recursion + * merging + * test nr + * result compile nr + * result render nr + * text + */ + array(false, false, 1, 1, 1, 'no EXTENDS; no merge - new'), + array(false, false, 2, 1, 2, 'no EXTENDS; no merge - exits'), + array(true, false, 3, 3, 3, 'EXTENDS; no merge - new'), + array(true, false, 4, 3, 4, 'EXTENDS; no merge - exits'), + array(false, true, 5, 5, 5, 'no EXTENDS; merge - new'), + array(false, true, 6, 5, 6, 'no EXTENDS; merge - exits'), + array(true, true, 7, 7, 7, 'EXTENDS; merge - new'), + array(true, true, 8, 7, 8, 'EXTENDS; merge - exits'), + ); + } } diff --git a/tests/UnitTests/ResourceTests/Extends/templates/034_child.tpl b/tests/UnitTests/ResourceTests/Extends/templates/034_child.tpl new file mode 100644 index 00000000..0ef80b8b --- /dev/null +++ b/tests/UnitTests/ResourceTests/Extends/templates/034_child.tpl @@ -0,0 +1,3 @@ +{block 'grandchild'}grandchild - child{/block} +{block 'child'}child - child{/block} + diff --git a/tests/UnitTests/ResourceTests/Extends/templates/034_grandchild.tpl b/tests/UnitTests/ResourceTests/Extends/templates/034_grandchild.tpl new file mode 100644 index 00000000..cd036c5b --- /dev/null +++ b/tests/UnitTests/ResourceTests/Extends/templates/034_grandchild.tpl @@ -0,0 +1,3 @@ +{extends '034_child.tpl'} +{block 'grandchild'}grandchild - grandchild{/block} + diff --git a/tests/UnitTests/ResourceTests/Extends/templates/034_parent.tpl b/tests/UnitTests/ResourceTests/Extends/templates/034_parent.tpl new file mode 100644 index 00000000..d57c39ee --- /dev/null +++ b/tests/UnitTests/ResourceTests/Extends/templates/034_parent.tpl @@ -0,0 +1,4 @@ +test:{$test nocache} compiled:# rendered:{$test} +{block 'grandchild'}grandchild - parent{/block} +{block 'child'}child - parent{/block} +{block 'parent'}parent - parent{/block}