From ac5070ea8747885914d7fd1c093e6958b6faaf84 Mon Sep 17 00:00:00 2001 From: uwetews Date: Tue, 9 Feb 2016 01:40:34 +0100 Subject: [PATCH] update scope tests --- .../TagTests/Append/CompileAppendTest.php | 95 +++- .../TagTests/Assign/CompileAssignTest.php | 412 +++++++++--------- .../PHPunitplugins/function.checkvar.php | 44 -- .../Assign/templates/001_newAppend_1.tpl | 1 - .../Assign/templates/001_newFormat_1.tpl | 1 - .../Assign/templates/001_newFormat_2.tpl | 1 - .../Assign/templates/001_newFormat_3.tpl | 1 - .../Assign/templates/001_oldFormat_1.tpl | 1 - .../Assign/templates/001_scope_global_1.tpl | 2 - .../Assign/templates/001_scope_global_2.tpl | 2 - .../Assign/templates/001_scope_include.tpl | 1 - .../Assign/templates/001_scope_none_1.tpl | 2 - .../Assign/templates/001_scope_none_2.tpl | 2 - .../Assign/templates/001_scope_parent_1.tpl | 2 - .../Assign/templates/001_scope_parent_2.tpl | 2 - .../Assign/templates/001_scope_root.tpl | 1 - .../Assign/templates/001_scope_root_1.tpl | 2 - .../Assign/templates/001_scope_root_2.tpl | 2 - .../Assign/templates/001_scope_tpl_root_1.tpl | 2 - .../Assign/templates/001_scope_tpl_root_2.tpl | 2 - .../Assign/templates/002_newAppend_1.tpl | 1 - .../Assign/templates/002_newAppend_2.tpl | 1 - .../Assign/templates/002_newFormat_1.tpl | 1 - .../Assign/templates/003_newAppend_1.tpl | 1 - .../Assign/templates/003_newAppend_2.tpl | 1 - .../Assign/templates/003_newFormat_1.tpl | 1 - .../Assign/templates/003_newFormat_2.tpl | 1 - .../Assign/templates/003_newFormat_3.tpl | 1 - .../Assign/templates/004_newFormat_1.tpl | 1 - .../Assign/templates/004_newNested_1.tpl | 1 - .../Assign/templates/004_oldFormat_1.tpl | 1 - .../Assign/templates/005_newFormat_1.tpl | 1 - .../Assign/templates/005_oldFormat_1.tpl | 1 - .../Assign/templates/006_newFormat_1.tpl | 1 - .../Assign/templates/006_oldFormat_1.tpl | 1 - .../Assign/templates/007_newFormat_1.tpl | 1 - .../Assign/templates/007_oldFormat_1.tpl | 1 - .../Assign/templates/008_oldFormat_1.tpl | 1 - .../Assign/templates/009_oldFormat_1.tpl | 1 - .../Assign/templates/010_oldFormat_1.tpl | 1 - .../Assign/templates/011_oldFormat_1.tpl | 1 - .../Assign/templates/test_scope_assignbar.tpl | 1 + .../templates/test_scope_assignnocache.tpl | 1 + .../ConfigLoad/CompileConfigLoadTest.php | 137 ++++-- .../TagTests/ConfigLoad/cache/dummy.txt | 0 .../TagTests/ConfigLoad/configs/data.conf | 1 + .../TagTests/ConfigLoad/configs/smarty.conf | 1 + .../TagTests/ConfigLoad/configs/template.conf | 1 + .../ConfigLoad/templates/001_section2.tpl | 1 + .../ConfigLoad/templates/002_section2.tpl | 1 + .../TagTests/If/CompileIfTest.php | 198 +++++---- .../TagTests/Include/CompileIncludeTest.php | 128 +++--- .../templates/test_include_local_scope.tpl | 1 - .../test_include_local_scope_sub.tpl | 1 - .../templates/test_include_parent_scope.tpl | 1 - .../templates/test_include_root_scope.tpl | 1 - .../TagTests/Include/templates/test_scope.tpl | 1 + .../Include/templates/test_scope_assign.tpl | 1 + .../templates/test_scope_pluginassign.tpl | 1 + .../TemplateFunction/CompileFunctionTest.php | 25 +- .../test_template_function_assign_001.tpl | 1 + .../TagTests/While/CompileWhileTest.php | 6 +- .../function.checkconfigvar.php | 45 ++ .../PHPunitplugins/function.checkvar.php | 50 +++ .../PHPunitplugins/function.pluginassign.php | 21 + .../UnitTests/__shared/templates/run_code.tpl | 1 + .../__shared/templates/run_code_caching.tpl | 1 + .../__shared/templates/scope_include.tpl | 1 + .../__shared/templates/scope_tag.tpl | 1 + 69 files changed, 707 insertions(+), 521 deletions(-) delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/PHPunitplugins/function.checkvar.php delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newAppend_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newFormat_2.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newFormat_3.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_oldFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_global_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_global_2.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_include.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_none_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_none_2.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_parent_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_parent_2.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root_2.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_tpl_root_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_tpl_root_2.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/002_newAppend_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/002_newAppend_2.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/002_newFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newAppend_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newAppend_2.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newFormat_2.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newFormat_3.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/004_newFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/004_newNested_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/004_oldFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/005_newFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/005_oldFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/006_newFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/006_oldFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/007_newFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/007_oldFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/008_oldFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/009_oldFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/010_oldFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/011_oldFormat_1.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/test_scope_assignbar.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/test_scope_assignnocache.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/ConfigLoad/cache/dummy.txt create mode 100644 tests/UnitTests/TemplateSource/TagTests/ConfigLoad/configs/data.conf create mode 100644 tests/UnitTests/TemplateSource/TagTests/ConfigLoad/configs/smarty.conf create mode 100644 tests/UnitTests/TemplateSource/TagTests/ConfigLoad/configs/template.conf create mode 100644 tests/UnitTests/TemplateSource/TagTests/ConfigLoad/templates/001_section2.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/ConfigLoad/templates/002_section2.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_local_scope.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_local_scope_sub.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_parent_scope.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_root_scope.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Include/templates/test_scope.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Include/templates/test_scope_assign.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Include/templates/test_scope_pluginassign.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/test_template_function_assign_001.tpl create mode 100644 tests/UnitTests/__shared/PHPunitplugins/function.checkconfigvar.php create mode 100644 tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php create mode 100644 tests/UnitTests/__shared/PHPunitplugins/function.pluginassign.php create mode 100644 tests/UnitTests/__shared/templates/run_code.tpl create mode 100644 tests/UnitTests/__shared/templates/run_code_caching.tpl create mode 100644 tests/UnitTests/__shared/templates/scope_include.tpl create mode 100644 tests/UnitTests/__shared/templates/scope_tag.tpl diff --git a/tests/UnitTests/TemplateSource/TagTests/Append/CompileAppendTest.php b/tests/UnitTests/TemplateSource/TagTests/Append/CompileAppendTest.php index 95b722cf..b4c30721 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Append/CompileAppendTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Append/CompileAppendTest.php @@ -10,7 +10,7 @@ * class for append tags tests * * @runTestsInSeparateProcess - * @preserveGlobalState disabled + * @preserveGlobalState disabled * @backupStaticAttributes enabled */ class CompileAppendTest extends PHPUnit_Smarty @@ -18,24 +18,103 @@ class CompileAppendTest extends PHPUnit_Smarty public function setUp() { $this->setUpSmarty(dirname(__FILE__)); + $this->smarty->addPluginsDir("../../../__shared/PHPunitplugins/"); + $this->smarty->addTemplateDir("../../../__shared/templates/"); + $this->smarty->addTemplateDir("./templates_tmp"); } - public function testInit() { $this->cleanDirs(); } + /** - * test aappand tag + * Test {append} tags + * + * @not runInSeparateProcess + * @preserveGlobalState disabled + * @dataProvider dataTestAppend */ - public function testAppend1() + public function testAppend($code, $result, $testName, $testNumber) { - $this->assertEquals("12", $this->smarty->fetch('eval:{$foo=1}{append var=foo value=2}{foreach $foo as $bar}{$bar}{/foreach}')); + $file = "testAppend_{$testNumber}.tpl"; + $this->makeTemplateFile($file, $code); + $this->smarty->assignGlobal('file', $file); + $this->assertEquals($this->strip($result), $this->strip($this->smarty->fetch($file)), "testAppend - {$code} - {$testName}"); } - public function testAppend2() + /* + * Data provider für testAppend + */ + public function dataTestAppend() { - $this->smarty->assign('foo', 1); - $this->assertEquals("12", $this->smarty->fetch('eval:{append var=foo value=2}{foreach $foo as $bar}{$bar}{/foreach}')); + $i = 0; + /* + * Code + * result + * test name + */ + return array(// old format + array('{$foo=1}{append var=foo value=2}{$foo|var_export:true}', 'array(0=>1,1=>2,)', '', $i ++), + array('{append var=foo value=2}{$foo|var_export:true}', 'array(0=>2,)', '', $i ++), + array('{append foo value=3}{$foo|var_export:true}', 'array(0=>3,)', '', $i ++), + array('{append foo 5}{$foo|var_export:true}', 'array(0=>5,)', '', $i ++), // new format + array('{$foo[]=2}{$foo|var_export:true}', 'array(0=>2,)', '', $i ++), + ); } + + /** + * Test scope + * + * @run InSeparateProcess + * @preserveGlobalState disabled + * @dataProvider dataTestScope + */ + public function testScope($code, $useSmarty, $result, $testName, $testNumber) + { + $file = "testScope_{$testNumber}.tpl"; + $this->makeTemplateFile($file, $code . '{checkvar var=foo}'); + $this->smarty->assignGlobal('file', $file); + $this->smarty->assign('foo', 'smarty'); + $this->smarty->assignGlobal('foo', 'global'); + $data1 = $this->smarty->createData($useSmarty ? $this->smarty : null); + $data = $this->smarty->createData($data1); + $data1->assign('foo', 'data1'); + $data->assign('foo', 'data'); + $this->assertEquals($this->strip($result), $this->strip($this->smarty->fetch('scope_tag.tpl', $data)), "test - {$code} - {$testName}"); + } + + /* + * Data provider für testscope + */ + public function dataTestScope() + { + $i = 0; + /* + * Code + * use Smarty object + * result + * test name + */ + return array( + array( + '{$foo[] = \'newvar\' scope=tpl_root}', true, + '#testScope_0.tpl:$foo=array(0=>\'data\',1=>\'newvar\',)#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=array(0=>\'data\',1=>\'newvar\',)#data:$foo=\'data\'#data:$foo=\'data1\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{$foo[] = \'newvar\' scope=tpl_root bubble_up}', true, + '#testScope_1.tpl:$foo=array(0=>\'data\',1=>\'newvar\',)#scope_include.tpl:$foo=array(0=>\'data\',1=>\'newvar\',)#scope_tag.tpl:$foo=array(0=>\'data\',1=>\'newvar\',)#data:$foo=\'data\'#data:$foo=\'data1\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{append var=foo value=\'newvar\' scope=tpl_root}', true, + '#testScope_2.tpl:$foo=array(0=>\'data\',1=>\'newvar\',)#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=array(0=>\'data\',1=>\'newvar\',)#data:$foo=\'data\'#data:$foo=\'data1\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{append var=foo value=\'newvar\' scope=tpl_root bubble_up}', true, + '#testScope_3.tpl:$foo=array(0=>\'data\',1=>\'newvar\',)#scope_include.tpl:$foo=array(0=>\'data\',1=>\'newvar\',)#scope_tag.tpl:$foo=array(0=>\'data\',1=>\'newvar\',)#data:$foo=\'data\'#data:$foo=\'data1\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), + ); + } + } diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/CompileAssignTest.php b/tests/UnitTests/TemplateSource/TagTests/Assign/CompileAssignTest.php index 7e754101..d5143be5 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/CompileAssignTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/CompileAssignTest.php @@ -15,11 +15,13 @@ */ class CompileAssignTest extends PHPUnit_Smarty { + public function setUp() { $this->setUpSmarty(dirname(__FILE__)); - $this->smarty->addPluginsDir("./PHPunitplugins/"); - $this->smarty->registerFilter('pre', array($this, 'prefilterTest')); + $this->smarty->addPluginsDir("../../../__shared/PHPunitplugins/"); + $this->smarty->addTemplateDir("../../../__shared/templates/"); + $this->smarty->addTemplateDir("./templates_tmp"); } public function testInit() @@ -28,243 +30,225 @@ class CompileAssignTest extends PHPUnit_Smarty } /** - * test old style of assign tag + * Test assign tags * - * @runInSeparateProcess + * @not runInSeparateProcess * @preserveGlobalState disabled + * @dataProvider dataTestAssign */ - public function testAssignOld_001() + public function testAssign($code, $result, $testName, $testNumber) { - $this->assertEquals("1", $this->smarty->fetch('001_oldFormat_1.tpl')); - $this->assertEquals("bar", $this->smarty->fetch('004_oldFormat_1.tpl')); - $this->assertEquals("3", $this->smarty->fetch('005_oldFormat_1.tpl')); - $this->assertEquals("3", $this->smarty->fetch('006_oldFormat_1.tpl')); - $this->assertEquals("3", $this->smarty->fetch('007_oldFormat_1.tpl')); - $this->assertEquals("9876", $this->smarty->fetch('008_oldFormat_1.tpl')); - $this->assertEquals("a9b8c7d6", $this->smarty->fetch('009_oldFormat_1.tpl')); - $this->assertEquals("1", $this->smarty->fetch('010_oldFormat_1.tpl')); - $this->assertEquals("1", $this->smarty->fetch('011_oldFormat_1.tpl')); + $file = "testAssign_{$testNumber}.tpl"; + $this->makeTemplateFile($file, $code); + $this->smarty->assignGlobal('file', $file); + $this->smarty->assign('bar', 'buh'); + $this->assertEquals($this->strip($result), $this->strip($this->smarty->fetch($file)), "testAssign - {$code} - {$testName}"); + } + + /* + * Data provider für testAssign + */ + public function dataTestAssign() + { + $i = 1; + /* + * Code + * result + * test name + */ + return array(// old format + array('{assign var=foo value=1}{$foo}', '1', '', $i ++), + array('{assign var=\'foo\' value=2}{$foo}', '2', '', $i ++), + array('{assign var="foo" value=3}{$foo}', '3', '', $i ++), + array('{assign var=foo value=$bar}{$foo}', 'buh', '', $i ++), + array('{assign var=$bar value=11}{$buh}', '11', '', $i ++), + array('{assign var=foo value=bar}{$foo}', 'bar', '', $i ++), + array('{assign var=foo value=1+2}{$foo}', '3', '', $i ++), + array('{assign var=foo value=strlen(\'barbuh\')}{$foo}', '6', '', $i ++), + array('{assign var=foo value=\'barr\'|strlen}{$foo}', '4', '', $i ++), + array('{assign var=foo value=[9,8,7,6]}{$foo|var_export:true}', 'array(0=>9,1=>8,2=>7,3=>6,)', '', $i ++), + array( + '{assign var=foo value=[\'a\'=>9,\'b\'=>8,\'c\'=>7,\'d\'=>6]}{$foo|var_export:true}', + 'array(\'a\'=>9,\'b\'=>8,\'c\'=>7,\'d\'=>6,)', '', $i ++, + ), array('{assign foo value=1}{$foo}', '1', '', $i ++), array('{assign foo 1}{$foo}', '1', '', $i ++), + // new format + array('{$foo=1}{$foo}', '1', '', $i ++), array('{$foo =2}{$foo}', '2', '', $i ++), + array('{$foo=bar}{$foo}', 'bar', '', $i ++), array('{$foo=1+2}{$foo}', '3', '', $i ++), + array('{$foo = 1+3}{$foo}', '4', '', $i ++), array('{$foo = 1 + 4}{$foo}', '5', '', $i ++), + array('{$foo=strlen(\'bar\')}{$foo}', '3', '', $i ++), array('{$foo=\'bar\'|strlen}{$foo}', '3', '', $i ++), + array('{$foo[\'a\'][4]=1}{$foo[\'a\'][4]}', '1', '', $i ++), + array('{$foo=[9,8,7,6]}{$foo|var_export:true}', 'array(0=>9,1=>8,2=>7,3=>6,)', '', $i ++), array( + '{$foo=[\'a\'=>9,\'b\'=>8,\'c\'=>7,\'d\'=>6]}{$foo|var_export:true}', + 'array(\'a\'=>9,\'b\'=>8,\'c\'=>7,\'d\'=>6,)', '', $i ++, + ), + ); } /** - * test new style of assign tag + * Test scope * - * @runInSeparateProcess + * @not runInSeparateProcess * @preserveGlobalState disabled + * @dataProvider dataTestScope */ - public function testAssignNew_001() - { - $this->assertEquals("1", $this->smarty->fetch('001_newFormat_1.tpl')); - $this->assertEquals("2", $this->smarty->fetch('001_newFormat_2.tpl')); - $this->assertEquals("3", $this->smarty->fetch('001_newFormat_3.tpl')); - $this->assertEquals("bar", $this->smarty->fetch('002_newFormat_1.tpl')); - $this->assertEquals("3", $this->smarty->fetch('003_newFormat_1.tpl')); - $this->assertEquals("4", $this->smarty->fetch('003_newFormat_2.tpl')); - $this->assertEquals("5", $this->smarty->fetch('003_newFormat_3.tpl')); - $this->assertEquals("3", $this->smarty->fetch('004_newFormat_1.tpl')); - $this->assertEquals("3", $this->smarty->fetch('005_newFormat_1.tpl')); - $this->assertEquals("9876", $this->smarty->fetch('006_newFormat_1.tpl')); - $this->assertEquals("a9b8c7d6", $this->smarty->fetch('007_newFormat_1.tpl')); - } - - /** - * test array append - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testAssignArrayAppend_001() - { - $this->assertEquals("0112", $this->smarty->fetch('001_newAppend_1.tpl')); - } - - /** - * test array append 2 - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testAssignArrayAppend_002() - { - $this->smarty->assign('foo', 1); - $tpl = $this->smarty->createTemplate('002_newAppend_1.tpl', null, null, $this->smarty, false); - $this->assertEquals("0112", $this->smarty->fetch($tpl)); - $tpl2 = $this->smarty->createTemplate('002_newAppend_2.tpl', null, null, $this->smarty, false); - $this->assertEquals("1", $this->smarty->fetch($tpl2)); - } - - /** - * test array append 3 - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testAssignArrayAppend_003() - { - $this->smarty->assign('foo', 1); - $tpl = $this->smarty->createTemplate('003_newAppend_1.tpl', null, null, $this->smarty, false); - $this->assertEquals("0112", $this->smarty->fetch($tpl)); - $tpl2 = $this->smarty->createTemplate('003_newAppend_2.tpl', null, null, $this->smarty, false); - $this->assertEquals("0112", $this->smarty->fetch($tpl2)); - } - - /** - * test nested array - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testAssignNestedArray_004() - { - $this->assertEquals("1", $this->smarty->fetch('004_newNested_1.tpl')); - } - - /** - * test no scope - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testAssignNone_001() - { - $this->smarty->assign('foo', 'smarty'); - $this->smarty->assign('include', '001_scope_none_1.tpl'); - $this->smarty->assignGlobal('foo', 'global'); - $data = $this->smarty->createData($this->smarty); - $data->assign('foo', 'data'); - $tpl = $this->smarty->createTemplate('001_scope_root.tpl', $data); - $this->assertContains("template 001_scope_none_1.tpl:var =none\ntemplate 001_scope_include.tpl:var =data\ntemplate 001_scope_root.tpl:var =data\ndata:var =data\nSmarty:var =smarty\nglobal:var =global\n", - $tpl->fetch()); - $this->smarty->assign('include', '001_scope_none_2.tpl'); - $this->assertContains("template 001_scope_none_2.tpl:var =none\ntemplate 001_scope_include.tpl:var =data\ntemplate 001_scope_root.tpl:var =data\ndata:var =data\nSmarty:var =smarty\nglobal:var =global\n", - $tpl->fetch()); - } - - /** - * test scope parent - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testAssignParent_001() - { - $this->smarty->assign('foo', 'smarty'); - $this->smarty->assign('include', '001_scope_parent_1.tpl'); - $this->smarty->assignGlobal('foo', 'global'); - $data = $this->smarty->createData($this->smarty); - $data->assign('foo', 'data'); - $tpl = $this->smarty->createTemplate('001_scope_root.tpl', null, null, $data, false); - $this->assertContains("template 001_scope_parent_1.tpl:var =parent\ntemplate 001_scope_include.tpl:var =parent\ntemplate 001_scope_root.tpl:var =data\ndata:var =data\nSmarty:var =smarty\nglobal:var =global\n", - $tpl->fetch()); - $this->smarty->assign('include', '001_scope_parent_2.tpl'); - $this->assertContains("template 001_scope_parent_2.tpl:var =parent\ntemplate 001_scope_include.tpl:var =parent\ntemplate 001_scope_root.tpl:var =data\ndata:var =data\nSmarty:var =smarty\nglobal:var =global\n", - $tpl->fetch()); - } - - /** - * test scope tpl_root - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testAssignTplRoot_001() - { - $this->smarty->assign('foo', 'smarty'); - $this->smarty->assign('include', '001_scope_tpl_root_1.tpl'); - $this->smarty->assignGlobal('foo', 'global'); - $data = $this->smarty->createData($this->smarty); - $data->assign('foo', 'data'); - $tpl = $this->smarty->createTemplate('001_scope_root.tpl', null, null, $data, false); - $this->assertContains("template 001_scope_tpl_root_1.tpl:var =tpl_root\ntemplate 001_scope_include.tpl:var =tpl_root\ntemplate 001_scope_root.tpl:var =tpl_root\ndata:var =data\nSmarty:var =smarty\nglobal:var =global\n", - $tpl->fetch()); - $this->smarty->assign('include', '001_scope_tpl_root_2.tpl'); - $this->assertContains("template 001_scope_tpl_root_2.tpl:var =tpl_root\ntemplate 001_scope_include.tpl:var =tpl_root\ntemplate 001_scope_root.tpl:var =tpl_root\ndata:var =data\nSmarty:var =smarty\nglobal:var =global\n", - $tpl->fetch()); - } - - /** - * test scope root - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testAssignRoot_001() - { - $this->smarty->assign('foo', 'smarty'); - $this->smarty->assign('include', '001_scope_root_1.tpl'); - $this->smarty->assignGlobal('foo', 'global'); - $data = $this->smarty->createData($this->smarty); - $data->assign('foo', 'data'); - $tpl = $this->smarty->createTemplate('001_scope_root.tpl', null, null, $data, false); - $this->assertContains("template 001_scope_root_1.tpl:var =root\ntemplate 001_scope_include.tpl:var =root\ntemplate 001_scope_root.tpl:var =root\ndata:var =root\nSmarty:var =root\nglobal:var =global\n", - $tpl->fetch()); - $this->smarty->assign('include', '001_scope_root_2.tpl'); - $this->smarty->assign('foo', 'smarty'); - $data->assign('foo', 'data'); - $this->assertContains("template 001_scope_root_2.tpl:var =root\ntemplate 001_scope_include.tpl:var =root\ntemplate 001_scope_root.tpl:var =root\ndata:var =root\nSmarty:var =root\nglobal:var =global\n", - $tpl->fetch()); - } - - /** - * test scope root data object - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testAssignRoot_002() + public function testScope($code, $useSmarty, $result, $testName, $testNumber) { + $file = "testScope_{$testNumber}.tpl"; + $this->makeTemplateFile($file, $code . '{checkvar var=foo}'); + $this->smarty->assignGlobal('file', $file); $this->smarty->assign('foo', 'smarty'); $this->smarty->assignGlobal('foo', 'global'); - $data = $this->smarty->createData(); + $data = $this->smarty->createData($useSmarty ? $this->smarty : null); $data->assign('foo', 'data'); - $data->assign('include', '001_scope_root_1.tpl'); - $tpl = $this->smarty->createTemplate('001_scope_root.tpl', null, null, $data, false); - $this->assertContains("template 001_scope_root_1.tpl:var =root\ntemplate 001_scope_include.tpl:var =root\ntemplate 001_scope_root.tpl:var =root\ndata:var =root\nSmarty:var =smarty\nglobal:var =global\n", - $tpl->fetch()); - $this->smarty->assign('foo', 'smarty'); - $data->assign('foo', 'data'); - $data->assign('include', '001_scope_root_2.tpl'); - $this->assertContains("template 001_scope_root_2.tpl:var =root\ntemplate 001_scope_include.tpl:var =root\ntemplate 001_scope_root.tpl:var =root\ndata:var =root\nSmarty:var =smarty\nglobal:var =global\n", - $tpl->fetch()); + $this->assertEquals($this->strip('#' . $file . $result), $this->strip($this->smarty->fetch('scope_tag.tpl', $data)), "test - {$code} - {$testName}"); + } + + /* + * Data provider für testscope + */ + public function dataTestScope() + { + $i = 1; + /* + * Code + * use Smarty object + * result + * test name + */ + return array( + array( + '{$foo = \'newvar\'}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{assign var=foo value=\'newvar\'}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{$foo = \'newvar\' bubble_up}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{$foo = \'newvar\' scope=local}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{$foo = \'newvar\' scope=local bubble_up}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{assign var=foo value=\'newvar\' bubble_up}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{assign var=foo value=\'newvar\' scope=local}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{assign var=foo value=\'newvar\' scope=local bubble_up}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{$foo = \'newvar\' scope=parent}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'newvar\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{$foo = \'newvar\' scope=parent bubble_up}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'newvar\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{assign var=foo value=\'newvar\' scope=parent}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'newvar\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{assign var=foo value=\'newvar\' scope=parent bubble_up}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'newvar\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{$foo = \'newvar\' scope=tpl_root}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'newvar\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{$foo = \'newvar\' scope=tpl_root bubble_up}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'newvar\'#scope_tag.tpl:$foo=\'newvar\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{$foo = \'newvar\' scope=global}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'newvar\'', + '', $i ++, + ), array( + '{$foo = \'newvar\' scope=global bubble_up}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'newvar\'#scope_tag.tpl:$foo=\'newvar\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'newvar\'', + '', $i ++, + ), array( + '{$foo = \'newvar\' scope=root}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'newvar\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{$foo = \'newvar\' scope=root bubble_up}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'newvar\'#scope_tag.tpl:$foo=\'newvar\'#data:$foo=\'newvar\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{$foo = \'newvar\' scope=root}', false, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'newvar\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + 'no smarty', $i ++, + ), array( + '{$foo = \'newvar\' scope=root bubble_up}', false, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'newvar\'#scope_tag.tpl:$foo=\'newvar\'#data:$foo=\'newvar\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', + 'no smarty', $i ++, + ), array( + '{$foo = \'newvar\' scope=smarty}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'newvar\'#global:$foo=\'global\'', + '', $i ++, + ), array( + '{$foo = \'newvar\' scope=smarty bubble_up}', false, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'newvar\'#scope_tag.tpl:$foo=\'newvar\'#data:$foo=\'data\'#Smarty:$foo=\'newvar\'#global:$foo=\'global\'', + 'no smarty', $i ++, + ), + ); } /** - * test scope global + * Test scope nocache * * @runInSeparateProcess * @preserveGlobalState disabled + * @dataProvider dataTestScopeNocache */ - public function testAssignGlobal_001() + public function testScopeNocache($var, $file, $result) { - $this->smarty->assign('include', '001_scope_global_1.tpl'); + $this->smarty->setCaching(true); + $this->smarty->assign('bar', $var, true); + $this->smarty->assign('buh', $var); + $this->smarty->assign('foo', 'smarty'); $this->smarty->assignGlobal('foo', 'global'); - $data = $this->smarty->createData($this->smarty); - $tpl = $this->smarty->createTemplate('001_scope_root.tpl', null, null, $data, false); - $this->assertContains("template 001_scope_global_1.tpl:var =new global\ntemplate 001_scope_include.tpl:var =new global\ntemplate 001_scope_root.tpl:var =new global\ndata:var =null\nSmarty:var =null\nglobal:var =new global\n", - $tpl->fetch()); - $this->smarty->assign('include', '001_scope_global_2.tpl'); - $this->assertContains("template 001_scope_global_2.tpl:var =new global\ntemplate 001_scope_include.tpl:var =new global\ntemplate 001_scope_root.tpl:var =new global\ndata:var =null\nSmarty:var =null\nglobal:var =new global\n", - $tpl->fetch()); + $this->assertEquals($this->strip($result), $this->strip($this->smarty->fetch($file)), "test - {$file} {$var}"); } - /** - * test scope global - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testAssignGlobal_002() + /* + * Data provider für testscopenocache + */ + public function dataTestScopeNocache() { - $this->smarty->assign('foo', 'smarty'); - $this->smarty->assign('include', '001_scope_global_1.tpl'); - $this->smarty->assignGlobal('foo', 'global'); - $data = $this->smarty->createData($this->smarty); - $tpl = $this->smarty->createTemplate('001_scope_root.tpl', null, null, $data, false); - $this->assertContains("template 001_scope_global_1.tpl:var =new global\ntemplate 001_scope_include.tpl:var =smarty\ntemplate 001_scope_root.tpl:var =smarty\ndata:var =null\nSmarty:var =smarty\nglobal:var =new global\n", - $tpl->fetch()); - $this->smarty->assign('include', '001_scope_global_2.tpl'); - $this->smarty->assign('foo', 'smarty'); - $this->assertContains("template 001_scope_global_2.tpl:var =new global\ntemplate 001_scope_include.tpl:var =smarty\ntemplate 001_scope_root.tpl:var =smarty\ndata:var =null\nSmarty:var =smarty\nglobal:var =new global\n", - $tpl->fetch()); + /* + * variable value + * result + */ + return array( + array( + 'b1', 'test_scope_assignbar.tpl', + '#test_scope_assignbar.tpl:$foo=\'b1\'#Smarty:$foo=\'smarty\'#global:$foo=\'b1\'', + ), array( + 'b2', 'test_scope_assignbar.tpl', + '#test_scope_assignbar.tpl:$foo=\'b2\'#Smarty:$foo=\'smarty\'#global:$foo=\'b2\'', + ), array( + 'b1', 'test_scope_assignnocache.tpl', + '#test_scope_assignnocache.tpl:$foo=\'b1\'#Smarty:$foo=\'smarty\'#global:$foo=\'b1\'', + ), array( + 'b2', 'test_scope_assignnocache.tpl', + '#test_scope_assignnocache.tpl:$foo=\'b2\'#Smarty:$foo=\'smarty\'#global:$foo=\'b2\'', + ), + ); } + } diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/PHPunitplugins/function.checkvar.php b/tests/UnitTests/TemplateSource/TagTests/Assign/PHPunitplugins/function.checkvar.php deleted file mode 100644 index 08375bc7..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/PHPunitplugins/function.checkvar.php +++ /dev/null @@ -1,44 +0,0 @@ -source->name}:var ="; - $output .= isset($ptr->tpl_vars[$var]) ? $ptr->tpl_vars[$var] : 'null'; - $output .= "\n"; - $ptr = $ptr->parent; - } elseif ($ptr instanceof Smarty_Data) { - $output .= "data:var ="; - $output .= isset($ptr->tpl_vars[$var]) ? $ptr->tpl_vars[$var] : 'null'; - $output .= "\n"; - $ptr = $ptr->parent; - } else { - $ptr = null; - } - } - $output .= "Smarty:var ="; - $output .= isset($template->smarty->tpl_vars[$var]) ? $template->smarty->tpl_vars[$var] : 'null'; - $output .= "\n"; - $output .= "global:var ="; - $output .= isset(Smarty::$global_tpl_vars[$var]) ? Smarty::$global_tpl_vars[$var] : 'null'; - $output .= "\n"; - return $output; -} diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newAppend_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newAppend_1.tpl deleted file mode 100644 index 43e31b2a..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newAppend_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo =1}{$foo[] = 2}{foreach $foo as $x}{$x@key}{$x}{/foreach} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newFormat_1.tpl deleted file mode 100644 index 0ee311a2..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo=1}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newFormat_2.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newFormat_2.tpl deleted file mode 100644 index d5761571..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newFormat_2.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo =2}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newFormat_3.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newFormat_3.tpl deleted file mode 100644 index 9276e367..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_newFormat_3.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo = 3}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_oldFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_oldFormat_1.tpl deleted file mode 100644 index 321fb2e6..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_oldFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{assign var=foo value=1}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_global_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_global_1.tpl deleted file mode 100644 index a70a1fcd..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_global_1.tpl +++ /dev/null @@ -1,2 +0,0 @@ -{assign var=foo value='new global' scope=global} -{checkvar var=foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_global_2.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_global_2.tpl deleted file mode 100644 index 0e9db85b..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_global_2.tpl +++ /dev/null @@ -1,2 +0,0 @@ -{$foo='new global' scope=global} -{checkvar var=foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_include.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_include.tpl deleted file mode 100644 index 4b81e464..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_include.tpl +++ /dev/null @@ -1 +0,0 @@ -{include $include} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_none_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_none_1.tpl deleted file mode 100644 index d8e101e5..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_none_1.tpl +++ /dev/null @@ -1,2 +0,0 @@ -{assign var=foo value='none'} -{checkvar var=foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_none_2.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_none_2.tpl deleted file mode 100644 index 958cfd66..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_none_2.tpl +++ /dev/null @@ -1,2 +0,0 @@ -{$foo='none'} -{checkvar var=foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_parent_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_parent_1.tpl deleted file mode 100644 index 28bd40dc..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_parent_1.tpl +++ /dev/null @@ -1,2 +0,0 @@ -{assign var=foo value='parent' scope=parent} -{checkvar var=foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_parent_2.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_parent_2.tpl deleted file mode 100644 index a9f198f2..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_parent_2.tpl +++ /dev/null @@ -1,2 +0,0 @@ -{$foo='parent' scope=parent} -{checkvar var=foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root.tpl deleted file mode 100644 index 7d59f8a8..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root.tpl +++ /dev/null @@ -1 +0,0 @@ -{include '001_scope_include.tpl'} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root_1.tpl deleted file mode 100644 index a15e7d99..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root_1.tpl +++ /dev/null @@ -1,2 +0,0 @@ -{assign var=foo value='root' scope=root} -{checkvar var=foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root_2.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root_2.tpl deleted file mode 100644 index 5a845101..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root_2.tpl +++ /dev/null @@ -1,2 +0,0 @@ -{$foo='root' scope=root} -{checkvar var=foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_tpl_root_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_tpl_root_1.tpl deleted file mode 100644 index fa59a8ac..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_tpl_root_1.tpl +++ /dev/null @@ -1,2 +0,0 @@ -{assign var=foo value='tpl_root' scope=tpl_root} -{checkvar var=foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_tpl_root_2.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_tpl_root_2.tpl deleted file mode 100644 index ba712a43..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_tpl_root_2.tpl +++ /dev/null @@ -1,2 +0,0 @@ -{$foo='tpl_root' scope=tpl_root} -{checkvar var=foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/002_newAppend_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/002_newAppend_1.tpl deleted file mode 100644 index 78697686..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/002_newAppend_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo[]=2}{foreach $foo as $x}{$x@key}{$x}{/foreach} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/002_newAppend_2.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/002_newAppend_2.tpl deleted file mode 100644 index b9490d3b..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/002_newAppend_2.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/002_newFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/002_newFormat_1.tpl deleted file mode 100644 index 9c263d95..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/002_newFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo=bar}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newAppend_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newAppend_1.tpl deleted file mode 100644 index ad7f4f21..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newAppend_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo[]=2 scope=root}{foreach $foo as $x}{$x@key}{$x}{/foreach} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newAppend_2.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newAppend_2.tpl deleted file mode 100644 index 9eb699c4..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newAppend_2.tpl +++ /dev/null @@ -1 +0,0 @@ -{foreach $foo as $x}{$x@key}{$x}{/foreach} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newFormat_1.tpl deleted file mode 100644 index c35cb280..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo=1+2}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newFormat_2.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newFormat_2.tpl deleted file mode 100644 index 58de845c..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newFormat_2.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo = 1+3}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newFormat_3.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newFormat_3.tpl deleted file mode 100644 index 25c81854..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_newFormat_3.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo = 1 + 4}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/004_newFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/004_newFormat_1.tpl deleted file mode 100644 index 0828c476..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/004_newFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo=strlen('bar')}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/004_newNested_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/004_newNested_1.tpl deleted file mode 100644 index 050ed256..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/004_newNested_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo['a'][4]=1}{$foo['a'][4]} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/004_oldFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/004_oldFormat_1.tpl deleted file mode 100644 index d9bf25e0..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/004_oldFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{assign var=foo value=bar}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/005_newFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/005_newFormat_1.tpl deleted file mode 100644 index 720cfb5b..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/005_newFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo='bar'|strlen}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/005_oldFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/005_oldFormat_1.tpl deleted file mode 100644 index a051ab92..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/005_oldFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{assign var=foo value=1+2}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/006_newFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/006_newFormat_1.tpl deleted file mode 100644 index b40e90ee..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/006_newFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo=[9,8,7,6]}{foreach $foo as $x}{$x}{/foreach} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/006_oldFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/006_oldFormat_1.tpl deleted file mode 100644 index aa72c139..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/006_oldFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{assign var=foo value=strlen('bar')}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/007_newFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/007_newFormat_1.tpl deleted file mode 100644 index 0a361946..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/007_newFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo=['a'=>9,'b'=>8,'c'=>7,'d'=>6]}{foreach $foo as $x}{$x@key}{$x}{/foreach} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/007_oldFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/007_oldFormat_1.tpl deleted file mode 100644 index 373921dc..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/007_oldFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{assign var=foo value='bar'|strlen}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/008_oldFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/008_oldFormat_1.tpl deleted file mode 100644 index 1f31d6e4..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/008_oldFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{assign var=foo value=[9,8,7,6]}{foreach $foo as $x}{$x}{/foreach} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/009_oldFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/009_oldFormat_1.tpl deleted file mode 100644 index 2322059d..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/009_oldFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{assign var=foo value=['a'=>9,'b'=>8,'c'=>7,'d'=>6]}{foreach $foo as $x}{$x@key}{$x}{/foreach} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/010_oldFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/010_oldFormat_1.tpl deleted file mode 100644 index d70c8539..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/010_oldFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{assign foo value=1}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/011_oldFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/011_oldFormat_1.tpl deleted file mode 100644 index cdc17140..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/011_oldFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{assign foo 1}{$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/test_scope_assignbar.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/test_scope_assignbar.tpl new file mode 100644 index 00000000..c0be3a40 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/test_scope_assignbar.tpl @@ -0,0 +1 @@ +{$foo = $bar scope=global}{checkvar var=foo nocache} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/test_scope_assignnocache.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/test_scope_assignnocache.tpl new file mode 100644 index 00000000..4bde90af --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/test_scope_assignnocache.tpl @@ -0,0 +1 @@ +{$foo = $buh scope=global nocache}{checkvar var=foo nocache} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/CompileConfigLoadTest.php b/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/CompileConfigLoadTest.php index 4f3dd6d8..7d192c35 100644 --- a/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/CompileConfigLoadTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/CompileConfigLoadTest.php @@ -10,7 +10,7 @@ * class for config variable tests * * @runTestsInSeparateProcess - * @preserveGlobalState disabled + * @preserveGlobalState disabled * @backupStaticAttributes enabled */ class CompileConfigLoadTest extends PHPUnit_Smarty @@ -23,22 +23,28 @@ class CompileConfigLoadTest extends PHPUnit_Smarty public function setUp() { $this->setUpSmarty(dirname(__FILE__)); + $this->smarty->addPluginsDir("../../../__shared/PHPunitplugins/"); + $this->smarty->addTemplateDir("../../../__shared/templates/"); + $this->smarty->addTemplateDir("./templates_tmp"); } /** - * empty templat_c and cache folders + * empty template_c and cache folders */ public function testInit() { $this->cleanDirs(); } - /** - * test {load_config} loading section2 + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + * + * test {load_config} loading section2 */ - public function testConfigVariableSection2Template() + public function testConfigVariableSection2Template_001() { - $this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('eval:{config_load file=\'test.conf\' section=\'section2\'}{#title#} {#sec1#} {#sec2#}')); + $this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('001_section2.tpl')); } /** @@ -49,33 +55,7 @@ class CompileConfigLoadTest extends PHPUnit_Smarty */ public function testConfigVariableSection2TemplateShorttags() { - $this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('eval:{config_load \'test.conf\' \'section2\'}{#title#} {#sec1#} {#sec2#}')); - } - - /** - * test config varibales loading local - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testConfigVariableLocal() - { - $this->assertEquals("Welcome to Smarty!", $this->smarty->fetch('eval:{config_load file=\'test.conf\' scope=\'local\'}{#title#}')); - // global must be empty - $this->assertEquals("", $this->smarty->getConfigVars('title')); - } - - /** - * test config varibales loading parent - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testConfigVariableParent() - { - $this->assertEquals("Welcome to Smarty!", $this->smarty->fetch('eval:{config_load file=\'test.conf\' scope=\'parent\'}{#title#}')); - // global is parent must not be empty - $this->assertEquals("Welcome to Smarty!", $this->smarty->getConfigVars('title')); + $this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('002_section2.tpl')); } /** @@ -155,4 +135,95 @@ class CompileConfigLoadTest extends PHPUnit_Smarty { $this->smarty->fetch('eval:{config_load file=\'test_error.conf\'}'); } + + /** + * Test scope + * + * @not runInSeparateProcess + * @preserveGlobalState disabled + * @dataProvider dataTestScope + */ + public function testScope($code, $useSmarty, $result, $testName, $testNumber) + { + $file = "testScope_{$testNumber}.tpl"; + $this->makeTemplateFile($file, $code . '{checkconfigvar var=foo}'); + $this->smarty->assignGlobal('file', $file); + $this->smarty->configLoad('smarty.conf'); + $data = $this->smarty->createData($useSmarty ? $this->smarty : null); + $data->configLoad('data.conf'); + $this->assertEquals($this->strip('#' . $file . $result), $this->strip($this->smarty->fetch('scope_tag.tpl', $data)), "test - {$code} - {$testName}"); + } + + /* + * Data provider für testscope + */ + public function dataTestScope() + { + $i = 1; + /* + * Code + * use Smarty object + * result + * test name + */ + return array( + array( + '{config_load \'template.conf\'}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'', + '', $i ++, + ), array( + '{config_load \'template.conf\' bubble_up}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'', + '', $i ++, + ), array( + '{config_load \'template.conf\' scope=local}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'', + '', $i ++, + ), array( + '{config_load \'template.conf\' scope=local bubble_up}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'', + '', $i ++, + ), array( + '{config_load \'template.conf\' scope=parent}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'newvar\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'', + '', $i ++, + ), array( + '{config_load \'template.conf\' scope=parent bubble_up}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'newvar\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'', + '', $i ++, + ), array( + '{config_load \'template.conf\' scope=tpl_root}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'newvar\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'', + '', $i ++, + ), array( + '{config_load \'template.conf\' scope=tpl_root bubble_up}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'newvar\'#scope_tag.tpl:$foo=\'newvar\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'', + '', $i ++, + ), array( + '{config_load \'template.conf\' scope=root}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'newvar\'#Smarty:$foo=\'smarty\'', + '', $i ++, + ), array( + '{config_load \'template.conf\' scope=root bubble_up}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'newvar\'#scope_tag.tpl:$foo=\'newvar\'#data:$foo=\'newvar\'#Smarty:$foo=\'smarty\'', + '', $i ++, + ), array( + '{config_load \'template.conf\' scope=root}', false, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'newvar\'#Smarty:$foo=\'smarty\'', + 'no smarty', $i ++, + ), array( + '{config_load \'template.conf\' scope=root bubble_up}', false, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'newvar\'#scope_tag.tpl:$foo=\'newvar\'#data:$foo=\'newvar\'#Smarty:$foo=\'smarty\'', + 'no smarty', $i ++, + ), array( + '{config_load \'template.conf\' scope=smarty}', true, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'data\'#scope_tag.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'newvar\'', + '', $i ++, + ), array( + '{config_load \'template.conf\' scope=smarty bubble_up}', false, + ':$foo=\'newvar\'#scope_include.tpl:$foo=\'newvar\'#scope_tag.tpl:$foo=\'newvar\'#data:$foo=\'data\'#Smarty:$foo=\'newvar\'', + 'no smarty', $i ++, + ), + ); + } } diff --git a/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/cache/dummy.txt b/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/cache/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/configs/data.conf b/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/configs/data.conf new file mode 100644 index 00000000..c9349c71 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/configs/data.conf @@ -0,0 +1 @@ +foo = data diff --git a/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/configs/smarty.conf b/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/configs/smarty.conf new file mode 100644 index 00000000..d65d1fd0 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/configs/smarty.conf @@ -0,0 +1 @@ +foo = smarty diff --git a/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/configs/template.conf b/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/configs/template.conf new file mode 100644 index 00000000..303000d4 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/configs/template.conf @@ -0,0 +1 @@ +foo = newvar diff --git a/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/templates/001_section2.tpl b/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/templates/001_section2.tpl new file mode 100644 index 00000000..c8c7baf9 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/templates/001_section2.tpl @@ -0,0 +1 @@ +{config_load file='test.conf' section='section2'}{#title#} {#sec1#} {#sec2#} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/templates/002_section2.tpl b/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/templates/002_section2.tpl new file mode 100644 index 00000000..3de3b450 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/ConfigLoad/templates/002_section2.tpl @@ -0,0 +1 @@ +{config_load 'test.conf' 'section2'}{#title#} {#sec1#} {#sec2#} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/If/CompileIfTest.php b/tests/UnitTests/TemplateSource/TagTests/If/CompileIfTest.php index 9c05859d..1c1f8826 100644 --- a/tests/UnitTests/TemplateSource/TagTests/If/CompileIfTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/If/CompileIfTest.php @@ -10,130 +10,128 @@ * class for {if} tag tests * * @runTestsInSeparateProcess - * @preserveGlobalState disabled + * @preserveGlobalState disabled * @backupStaticAttributes enabled -*/ + */ class CompileIfTest extends PHPUnit_Smarty { public function setUp() { $this->setUpSmarty(dirname(__FILE__)); + $this->smarty->addPluginsDir("../../../__shared/PHPunitplugins/"); + $this->smarty->addTemplateDir("../../../__shared/templates/"); + $this->smarty->addTemplateDir("./templates_tmp"); } - public function testInit() { $this->cleanDirs(); } + /** - * test {if} tag + * Test if tags + * + * @not runInSeparateProcess + * @preserveGlobalState disabled + * @dataProvider dataTestIf */ - public function testIf1() + public function testIf($code, $result, $testName, $testNumber) { - $tpl = $this->smarty->createTemplate('eval:{if 0<1}yes{/if}'); - $this->assertEquals("yes", $this->smarty->fetch($tpl)); + $file = "testIf_{$testNumber}.tpl"; + $this->makeTemplateFile($file, $code); + $this->smarty->assignGlobal('file', $file); + $this->smarty->assign('bar', 'buh'); + $this->assertEquals($this->strip($result), $this->strip($this->smarty->fetch($file)), + "testIf - {$code} - {$testName}"); } - public function testElseif1() + /* + * Data provider für testIf + */ + public function dataTestIf() { - $tpl = $this->smarty->createTemplate('eval:{if false}false{elseif 0<1}yes{/if}'); - $this->assertEquals("yes", $this->smarty->fetch($tpl)); + $i = 1; + /* + * Code + * result + * test name + */ + return array(array('{if 0<1}yes{/if}', 'yes', '', $i ++), + array('{if false}false{elseif 0<1}yes{/if}', 'yes', '', $i ++), + array('{if 2<1}yes{else}no{/if}', 'no', '', $i ++), + array('{if 2<1}yes{elseif 4<5}yes1{else}no{/if}', 'yes1', '', $i ++), + array('{if 2<1}yes{elseif 6<5}yes1{else}no{/if}', 'no', '', $i ++), + array('{if true}yes{else}no{/if}', 'yes', '', $i ++), array('{if false}yes{else}no{/if}', 'no', '', $i ++), + array('{if !(1<2)}yes{else}no{/if}', 'no', '', $i ++), + array('{if not (true)}yes{else}no{/if}', 'no', '', $i ++), + array('{if 1 == 1}yes{else}no{/if}', 'yes', '', $i ++), + array('{if 1 EQ 1}yes{else}no{/if}', 'yes', '', $i ++), + array('{if 1 eq 1}yes{else}no{/if}', 'yes', '', $i ++), + array('{$foo=true}{if $foo===true}yes{else}no{/if}', 'yes', '', $i ++), + array('{$foo=true}{if $foo!==true}yes{else}no{/if}', 'no', '', $i ++), + array('{if 1 > 0}yes{else}no{/if}', 'yes', '', $i ++), + array('{if $x=1}yes{else}no{/if}{$x}', 'yes1', '', $i ++), + array('{$x=0}{if $x++}yes{else}no{/if} {$x}', 'no1', '', $i ++), + array('{$x=[1,2]}{if $x[] = 7}{$x|var_export:true}{else}no{/if}', 'array(0=>1,1=>2,2=>7,)', '', $i ++), + array('{$x=[1,2]}{if $x[][\'a\'] = 7}{$x|var_export:true}{else}no{/if}', + 'array(0=>1,1=>2,2=>array(\'a\'=>7,),)', '', $i ++ + ), + ); } - public function testIf2() + /** + * Test if nocache tags + * + * @runInSeparateProcess + * @preserveGlobalState disabled + * @dataProvider dataTestIfNocache + */ + public function testIfNocache($var, $value, $code, $result, $testName, $testNumber, $file = null) { - $tpl = $this->smarty->createTemplate('eval:{if 2<1}yes{else}no{/if}'); - $this->assertEquals("no", $this->smarty->fetch($tpl)); + if (!isset($file)) { + $file = "testIfNoCache_{$testNumber}.tpl"; + } + if ($code) { + $this->makeTemplateFile($file, $code); + } + $this->smarty->setCaching(true); + $this->smarty->assign('file', $file, true); + $this->smarty->assign($var, $value, true); + $this->smarty->assign($var . '2', $value); + $this->assertEquals($this->strip($result), $this->strip($this->smarty->fetch('run_code_caching.tpl')), + "testIfNocahe - {$code} - {$testName}"); } - public function testIf3() + /* + * Data provider für testIfNocache + */ + public function dataTestIfNocache() { - $tpl = $this->smarty->createTemplate('eval:{if 2<1}yes{elseif 4<5}yes1{else}no{/if}'); - $this->assertEquals("yes1", $this->smarty->fetch($tpl)); - } - - public function testIf4() - { - $tpl = $this->smarty->createTemplate('eval:{if 2<1}yes{elseif 6<5}yes1{else}no{/if}'); - $this->assertEquals("no", $this->smarty->fetch($tpl)); - } - - public function testIfTrue() - { - $tpl = $this->smarty->createTemplate('eval:{if true}yes{else}no{/if}'); - $this->assertEquals("yes", $this->smarty->fetch($tpl)); - } - - public function testIfFalse() - { - $tpl = $this->smarty->createTemplate('eval:{if false}yes{else}no{/if}'); - $this->assertEquals("no", $this->smarty->fetch($tpl)); - } - - public function testIfNot1() - { - $tpl = $this->smarty->createTemplate('eval:{if !(1<2)}yes{else}no{/if}'); - $this->assertEquals("no", $this->smarty->fetch($tpl)); - } - - public function testIfNot2() - { - $tpl = $this->smarty->createTemplate('eval:{if not (true)}yes{else}no{/if}'); - $this->assertEquals("no", $this->smarty->fetch($tpl)); - } - - public function testIfEQ1() - { - $tpl = $this->smarty->createTemplate('eval:{if 1 == 1}yes{else}no{/if}'); - $this->assertEquals("yes", $this->smarty->fetch($tpl)); - } - - public function testIfEQ2() - { - $tpl = $this->smarty->createTemplate('eval:{if 1==1}yes{else}no{/if}'); - $this->assertEquals("yes", $this->smarty->fetch($tpl)); - } - - public function testIfEQ3() - { - $tpl = $this->smarty->createTemplate('eval:{if 1 EQ 1}yes{else}no{/if}'); - $this->assertEquals("yes", $this->smarty->fetch($tpl)); - } - - public function testIfEQ4() - { - $tpl = $this->smarty->createTemplate('eval:{if 1 eq 1}yes{else}no{/if}'); - $this->assertEquals("yes", $this->smarty->fetch($tpl)); - } - - public function testIfIdentity1() - { - $tpl = $this->smarty->createTemplate('eval:{$foo=true}{if $foo===true}yes{else}no{/if}'); - $this->assertEquals("yes", $this->smarty->fetch($tpl)); - } - - public function testIfIdentity2() - { - $tpl = $this->smarty->createTemplate('eval:{$foo=true}{if $foo === true}yes{else}no{/if}'); - $this->assertEquals("yes", $this->smarty->fetch($tpl)); - } - - public function testIfNotIdentity1() - { - $tpl = $this->smarty->createTemplate('eval:{$foo=true}{if $foo!==true}yes{else}no{/if}'); - $this->assertEquals("no", $this->smarty->fetch($tpl)); - } - - public function testIfNotIdentity2() - { - $tpl = $this->smarty->createTemplate('eval:{$foo=true}{if $foo !== true}yes{else}no{/if}'); - $this->assertEquals("no", $this->smarty->fetch($tpl)); - } - - public function testIfGT1() - { - $tpl = $this->smarty->createTemplate('eval:{if 1 > 0}yes{else}no{/if}'); - $this->assertEquals("yes", $this->smarty->fetch($tpl)); + $i = 1; + /* + * var + * value + * Code + * result + * test name + */ + return array(array('foo', true, '{if $foo}yes{else}no{/if}', 'yes', '', $i ++, 'testIfNoCache_Var1.tpl'), + array('foo', true, false, 'yes', '', $i ++, 'testIfNoCache_Var1.tpl'), + array('foo', false, false, 'no', '', $i ++, 'testIfNoCache_Var1.tpl'), + array('foo', false, false, 'no', '', $i ++, 'testIfNoCache_Var1.tpl'), + array('foo', true, '{$bar=$foo}{if $bar}yes{else}no{/if}', 'yes', '', $i ++, 'testIfNoCache_Var2.tpl'), + array('foo', true, false, 'yes', '', $i ++, 'testIfNoCache_Var2.tpl'), + array('foo', false, false, 'no', '', $i ++, 'testIfNoCache_Var2.tpl'), + array('foo', false, false, 'no', '', $i ++, 'testIfNoCache_Var2.tpl'), + array('foo', 1, '{if $bar=$foo}yes{else}no{/if}{$bar}', 'yes1', '', $i ++, 'testIfNoCache_Var3.tpl'), + array('foo', 1, false, 'yes1', '', $i ++, 'testIfNoCache_Var3.tpl'), + array('foo', 0, false, 'no0', '', $i ++, 'testIfNoCache_Var3.tpl'), + array('foo', 0, false, 'no0', '', $i ++, 'testIfNoCache_Var3.tpl'), + array('bar', 4, '{if $bar2=$bar+3}yes{else}no{/if}{$bar2}', 'yes7', '', $i ++, 'testIfNoCache_Var4.tpl'), + array('bar', 4, false, 'yes7', '', $i ++, 'testIfNoCache_Var4.tpl'), + array('bar', 0, false, 'yes3', '', $i ++, 'testIfNoCache_Var4.tpl'), + array('bar', 0, false, 'yes3', '', $i ++, 'testIfNoCache_Var4.tpl'), + ); } public function testIfGT2() diff --git a/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php b/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php index e4468237..6ada592d 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Include/CompileIncludeTest.php @@ -18,6 +18,8 @@ class CompileIncludeTest extends PHPUnit_Smarty public function setUp() { $this->setUpSmarty(dirname(__FILE__)); + $this->smarty->addPluginsDir("../../../__shared/PHPunitplugins/"); + $this->smarty->addTemplateDir("./templates_tmp"); } @@ -29,7 +31,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * test spacing * - * @rrunInSeparateProcess + * @runInSeparateProcess + * @preserveGlobalState disabled * @dataProvider includeProviderCaching */ public function testSpacing_001($merge, $caching, $text) @@ -82,6 +85,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * test standard output * + * @runInSeparateProcess + * @preserveGlobalState disabled * @dataProvider includeProvider */ public function testIncludeStandard_001($merge, $text) @@ -95,6 +100,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * test standard output nocache var * + * @runInSeparateProcess + * @preserveGlobalState disabled * @dataProvider includeProvider */ public function testIncludeStandardNocacheVar($merge, $text) @@ -110,6 +117,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * Test that assign attribute does not create standard output * + * @runInSeparateProcess + * @preserveGlobalState disabled * @dataProvider includeProvider */ public function testIncludeAssign1($merge, $text) @@ -122,6 +131,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * Test that assign attribute does load variable * + * @runInSeparateProcess + * @preserveGlobalState disabled * @dataProvider includeProvider */ public function testIncludeAssign2($merge, $text) @@ -134,6 +145,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * Test passing local vars eval * + * @runInSeparateProcess + * @preserveGlobalState disabled * @dataProvider includeProvider */ public function testIncludePassVars($merge, $text) @@ -147,6 +160,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * Test passing local vars include * + * @runInSeparateProcess + * @preserveGlobalState disabled * @dataProvider includeProvider */ public function testIncludePassVars2($merge, $text) @@ -156,81 +171,70 @@ class CompileIncludeTest extends PHPUnit_Smarty $this->assertEquals("12", $this->smarty->fetch($tpl), $text); } - /** - * Test local scope - * - * @dataProvider includeProvider - */ - public function testIncludeLocalScope($merge, $text) - { - //$this->smarty->caching = true; - $this->smarty->setMergeCompiledIncludes($merge); - $this->smarty->assign('foo', 1); - $tpl = $this->smarty->createTemplate('test_include_local_scope.tpl', null, null, $this->smarty); - $content = $this->smarty->fetch($tpl); - $this->assertContains('before include 1', $content, 'before include 1 ' . $text); - $this->assertContains('in include 2', $content . 'in include 2 ' . $text); - $this->assertContains('after include 1', $content, 'after include 1 ' . $text); - } /** - * Test parent scope + * Test scope * - * @dataProvider includeProvider + * @run InSeparateProcess + * @preserveGlobalState disabled + * @dataProvider dataTestScope */ - public function testIncludeParentScope($merge, $text) + public function testScope($code, $useSmarty, $result, $testName, $testNumber = null) { - $this->smarty->setMergeCompiledIncludes($merge); - $this->smarty->assign('foo', 1); - $tpl = $this->smarty->createTemplate('test_include_parent_scope.tpl', null, null, $this->smarty, false); - $content = $this->smarty->fetch($tpl); - $content2 = $this->smarty->fetch('eval: root value {$foo}'); - $this->assertContains('before include 1', $content, 'before include 1 ' . $text); - $this->assertContains('in include 2', $content . 'in include 2 ' . $text); - $this->assertContains('after include 2', $content, 'after include 2 ' . $text); - $this->assertContains('root value 1', $content2, 'root value 1 ' . $text); + if ($testNumber) { + $file = "testScope_{$testNumber}.tpl"; + $this->makeTemplateFile($file, $code); + $this->smarty->assignGlobal('file', $file); + } + $this->smarty->assign('foo', 'smarty'); + $this->smarty->assignGlobal('foo', 'global'); + $data = $this->smarty->createData($useSmarty ? $this->smarty : null); + $data->assign('foo', 'data'); + if (!$useSmarty) { + $testName .= 'no smarty'; + } + $this->assertEquals($this->strip($result), $this->strip($this->smarty->fetch('test_scope.tpl', $data)), + "test - {$code} - {$testName}"); } - /** - * Test root scope - * - * @dataProvider includeProvider + /* + * Data provider for testscope */ - public function testIncludeRootScope($merge, $text) + public function dataTestScope() { - $this->smarty->setMergeCompiledIncludes($merge); - $this->smarty->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE)); - $this->smarty->assign('foo', 1); - $tpl = $this->smarty->createTemplate('test_include_root_scope.tpl'); - $content = $this->smarty->fetch($tpl); - $content2 = $this->smarty->fetch('eval: smarty value {$foo}'); - $this->assertNotContains('before include 1', $content, 'before include 1 ' . $text); - $this->assertContains('in include 2', $content . 'in include 2 ' . $text); - $this->assertContains('after include 2', $content, 'after include 2 ' . $text); - $this->assertContains('smarty value 1', $content2, 'smarty value 1 ' . $text); + $i = 1; + return array(/* + * Code + * use Smarty object + * result + * test name + */ + array('{include \'test_scope_assign.tpl\'}', true, '#test_scope_assign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'data\'#test_scope.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', '', $i++), + array('{include \'test_scope_assign.tpl\' bubble_up}', true, '#test_scope_assign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'data\'#test_scope.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', '', $i++), + array('{include \'test_scope_assign.tpl\' scope=parent}', true, '#test_scope_assign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'newvar\'#test_scope.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', '', $i++), + array('{include \'test_scope_assign.tpl\' scope=parent bubble_up}', true, '#test_scope_assign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'newvar\'#test_scope.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', '', $i++), + array('{include \'test_scope_assign.tpl\' scope=tpl_root}', true, '#test_scope_assign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'data\'#test_scope.tpl:$foo=\'newvar\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', '', $i++), + array('{include \'test_scope_assign.tpl\' scope=tpl_root bubble_up}', true, '#test_scope_assign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'newvar\'#test_scope.tpl:$foo=\'newvar\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', '', $i++), + array('{include \'test_scope_assign.tpl\' scope=root}', true, '#test_scope_assign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'data\'#test_scope.tpl:$foo=\'data\'#data:$foo=\'newvar\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', '', $i++), + array('{include \'test_scope_assign.tpl\' scope=root bubble_up}', true, '#test_scope_assign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'newvar\'#test_scope.tpl:$foo=\'newvar\'#data:$foo=\'newvar\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', '', $i++), + array('{include \'test_scope_assign.tpl\' scope=root}', false, '#test_scope_assign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'data\'#test_scope.tpl:$foo=\'data\'#data:$foo=\'newvar\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', '', $i++), + array('{include \'test_scope_assign.tpl\' scope=root bubble_up}', false, '#test_scope_assign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'newvar\'#test_scope.tpl:$foo=\'newvar\'#data:$foo=\'newvar\'#Smarty:$foo=\'smarty\'#global:$foo=\'global\'', '', $i++), + array('{include \'test_scope_assign.tpl\' scope=smarty}', true, '#test_scope_assign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'data\'#test_scope.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'newvar\'#global:$foo=\'global\'', '', $i++), + array('{include \'test_scope_assign.tpl\' scope=smarty bubble_up}', true, '#test_scope_assign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'newvar\'#test_scope.tpl:$foo=\'newvar\'#data:$foo=\'data\'#Smarty:$foo=\'newvar\'#global:$foo=\'global\'', '', $i++), + array('{include \'test_scope_assign.tpl\' scope=global}', true, '#test_scope_assign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'data\'#test_scope.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'newvar\'', '', $i++), + array('{include \'test_scope_assign.tpl\' scope=global bubble_up}', true, '#test_scope_assign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'newvar\'#test_scope.tpl:$foo=\'newvar\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'newvar\'', '', $i++), + array('{include \'test_scope_pluginassign.tpl\' scope=global}', true, '#test_scope_pluginassign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'data\'#test_scope.tpl:$foo=\'data\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'newvar\'', '', $i++), + array('{include \'test_scope_pluginassign.tpl\' scope=global bubble_up}', true, '#test_scope_pluginassign.tpl:$foo=\'newvar\'#testScope_'.$i.'.tpl:$foo=\'newvar\'#test_scope.tpl:$foo=\'newvar\'#data:$foo=\'data\'#Smarty:$foo=\'smarty\'#global:$foo=\'newvar\'', '', $i++), + ); } - /** - * Test root scope - * - * @dataProvider includeProvider - */ - public function testIncludeRootScope2($merge, $text) - { - $this->smarty->setMergeCompiledIncludes($merge); - $this->smarty->assign('foo', 1); - $tpl = $this->smarty->createTemplate('test_include_root_scope.tpl', null, null, $this->smarty); - $content = $this->smarty->fetch($tpl); - $content2 = $this->smarty->fetch('eval: smarty value {$foo}'); - $this->assertContains('before include 1', $content, 'before include 1 ' . $text); - $this->assertContains('in include 2', $content . 'in include 2 ' . $text); - $this->assertContains('after include 2', $content, 'after include 1 ' . $text); - $this->assertContains('smarty value 2', $content2, 'smarty value 2 ' . $text); - } + /** * Test recursive includes * + * @runInSeparateProcess + * @preserveGlobalState disabled * @dataProvider includeProvider */ public function testRecursiveIncludes1($merge, $text) @@ -245,6 +249,8 @@ class CompileIncludeTest extends PHPUnit_Smarty /** * Test recursive includes 2 * + * @runInSeparateProcess + * @preserveGlobalState disabled * @dataProvider includeProvider */ public function testRecursiveIncludes2($merge, $text) diff --git a/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_local_scope.tpl b/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_local_scope.tpl deleted file mode 100644 index e90ac4e1..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_local_scope.tpl +++ /dev/null @@ -1 +0,0 @@ -before include {$foo} {include file='test_include_local_scope_sub.tpl'} after include {$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_local_scope_sub.tpl b/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_local_scope_sub.tpl deleted file mode 100644 index 0e43de2d..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_local_scope_sub.tpl +++ /dev/null @@ -1 +0,0 @@ -{$foo=2} in include {$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_parent_scope.tpl b/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_parent_scope.tpl deleted file mode 100644 index e8e39131..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_parent_scope.tpl +++ /dev/null @@ -1 +0,0 @@ -before include {$foo} {include file='test_include_local_scope_sub.tpl' scope = parent} after include {$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_root_scope.tpl b/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_root_scope.tpl deleted file mode 100644 index 92f68120..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_include_root_scope.tpl +++ /dev/null @@ -1 +0,0 @@ -before include {$foo} {include file='test_include_local_scope_sub.tpl' scope = root} after include {$foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_scope.tpl b/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_scope.tpl new file mode 100644 index 00000000..bfb1e6cb --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_scope.tpl @@ -0,0 +1 @@ +{include $file} diff --git a/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_scope_assign.tpl b/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_scope_assign.tpl new file mode 100644 index 00000000..ae7268d8 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_scope_assign.tpl @@ -0,0 +1 @@ +{$foo = 'newvar'}{checkvar var=foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_scope_pluginassign.tpl b/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_scope_pluginassign.tpl new file mode 100644 index 00000000..e19a560a --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Include/templates/test_scope_pluginassign.tpl @@ -0,0 +1 @@ +{pluginassign var=foo value='newvar'}{checkvar var=foo} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php index 25982b4f..579f4eb9 100644 --- a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php @@ -25,12 +25,12 @@ class CompileFunctionTest extends PHPUnit_Smarty { $this->cleanDirs(); } - /** - * @runInSeparateProcess - * @preserveGlobalState disabled - * @dataProvider functionProvider + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + * @dataProvider functionProvider * test simple function call tag - * + * */ public function testSimpleFunction_001($text) { @@ -38,6 +38,19 @@ class CompileFunctionTest extends PHPUnit_Smarty $this->smarty->assign('default', 2); $this->assertEquals("default param default 1 2 1", $this->smarty->fetch('test_template_function_001.tpl'), $text); } + /** + * @run InSeparateProcess + * @preserveGlobalState disabled + * @dataProvider functionProvider + * test simple function call tag + * + */ + public function testSimpleFunctionAssign_001($text) + { + $this->smarty->assign('param', 1); + $this->smarty->assign('default', 2); + $this->assertEquals("default param default 1 2 1", $this->smarty->fetch('test_template_function_assign_001.tpl'), $text); + } /** * @runInSeparateProcess @@ -69,7 +82,7 @@ class CompileFunctionTest extends PHPUnit_Smarty /** - * @runInSeparateProcess + * @run InSeparateProcess * @preserveGlobalState disabled * @dataProvider functionProvider * test simple function call tag cached no cache default variable diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/test_template_function_assign_001.tpl b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/test_template_function_assign_001.tpl new file mode 100644 index 00000000..71ad75ca --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/test_template_function_assign_001.tpl @@ -0,0 +1 @@ +{function name=functest default='default'}{$default} {$param}{$foo = $param scope=local}{/function}{call name=functest param='param'} {call name=functest param=$param} {call name=functest param=$param default=$default} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/While/CompileWhileTest.php b/tests/UnitTests/TemplateSource/TagTests/While/CompileWhileTest.php index eeeb67a5..56b3792f 100644 --- a/tests/UnitTests/TemplateSource/TagTests/While/CompileWhileTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/While/CompileWhileTest.php @@ -9,7 +9,7 @@ /** * class for {while} tag tests * - * @runTestsInSeparateProcess + * @not runTestsInSeparateProcess * @preserveGlobalState disabled * @backupStaticAttributes enabled */ @@ -30,7 +30,7 @@ class CompileWhileTest extends PHPUnit_Smarty */ public function testWhileCondition() { - $tpl = $this->smarty->createTemplate('eval:{$x=0}{while $x<10}{$x}{$x=$x+1}{/while}'); + $tpl = $this->smarty->createTemplate('string:{$x=0}{while $x<10}{$x}{$x=$x+1}{/while}'); $this->assertEquals("0123456789", $this->smarty->fetch($tpl)); } @@ -39,7 +39,7 @@ class CompileWhileTest extends PHPUnit_Smarty */ public function testWhileStatement() { - $tpl = $this->smarty->createTemplate('eval:{$y=5}{while $y=$y-1}{$y}{/while}'); + $tpl = $this->smarty->createTemplate('string:{$y=5}{while $y=$y-1}{$y}{/while}'); $this->assertEquals("4321", $this->smarty->fetch($tpl)); } } diff --git a/tests/UnitTests/__shared/PHPunitplugins/function.checkconfigvar.php b/tests/UnitTests/__shared/PHPunitplugins/function.checkconfigvar.php new file mode 100644 index 00000000..c026793b --- /dev/null +++ b/tests/UnitTests/__shared/PHPunitplugins/function.checkconfigvar.php @@ -0,0 +1,45 @@ +source->name}:\${$var} ="; + $output .= isset($ptr->config_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->config_vars[$var], true)) : 'null'; + $ptr = $ptr->parent; + } elseif (in_array('data', $types) && $ptr instanceof Smarty_Data) { + $output .= "#data:\${$var} ="; + $output .= isset($ptr->config_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->config_vars[$var], true)) : 'null'; + $ptr = $ptr->parent; + } else { + $ptr = null; + } + } + if (in_array('smarty', $types)) { + $output .= "#Smarty:\${$var} ="; + $output .= isset($template->smarty->config_vars[ $var ]) ? + preg_replace('/\s/', '', var_export($template->smarty->config_vars[ $var ], true)) : 'null'; + } + return $output; +} diff --git a/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php b/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php new file mode 100644 index 00000000..762aaa0f --- /dev/null +++ b/tests/UnitTests/__shared/PHPunitplugins/function.checkvar.php @@ -0,0 +1,50 @@ +source->name}:\${$var} ="; + $output .= isset($ptr->tpl_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->tpl_vars[$var]->value, true)) : 'null'; + $ptr = $ptr->parent; + } elseif (in_array('data', $types) && $ptr instanceof Smarty_Data) { + $output .= "#data:\${$var} ="; + $output .= isset($ptr->tpl_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->tpl_vars[$var]->value, true)) : 'null'; + $ptr = $ptr->parent; + } else { + $ptr = null; + } + } + if (in_array('smarty', $types)) { + $output .= "#Smarty:\${$var} ="; + $output .= isset($template->smarty->tpl_vars[ $var ]) ? + preg_replace('/\s/', '', var_export($template->smarty->tpl_vars[ $var ]->value, true)) : 'null'; + } + if (in_array('global', $types)) { + $output .= "#global:\${$var} ="; + $output .= isset(Smarty::$global_tpl_vars[ $var ]) ? + preg_replace('/\s/', '', var_export(Smarty::$global_tpl_vars[ $var ]->value, true)) : 'null'; + } + return $output; +} diff --git a/tests/UnitTests/__shared/PHPunitplugins/function.pluginassign.php b/tests/UnitTests/__shared/PHPunitplugins/function.pluginassign.php new file mode 100644 index 00000000..111d9d05 --- /dev/null +++ b/tests/UnitTests/__shared/PHPunitplugins/function.pluginassign.php @@ -0,0 +1,21 @@ +assign($params[ 'var' ], $params[ 'value' ]); + return ''; +} diff --git a/tests/UnitTests/__shared/templates/run_code.tpl b/tests/UnitTests/__shared/templates/run_code.tpl new file mode 100644 index 00000000..f2db3620 --- /dev/null +++ b/tests/UnitTests/__shared/templates/run_code.tpl @@ -0,0 +1 @@ +{include $file} \ No newline at end of file diff --git a/tests/UnitTests/__shared/templates/run_code_caching.tpl b/tests/UnitTests/__shared/templates/run_code_caching.tpl new file mode 100644 index 00000000..421be584 --- /dev/null +++ b/tests/UnitTests/__shared/templates/run_code_caching.tpl @@ -0,0 +1 @@ +{include $file caching} \ No newline at end of file diff --git a/tests/UnitTests/__shared/templates/scope_include.tpl b/tests/UnitTests/__shared/templates/scope_include.tpl new file mode 100644 index 00000000..bfb1e6cb --- /dev/null +++ b/tests/UnitTests/__shared/templates/scope_include.tpl @@ -0,0 +1 @@ +{include $file} diff --git a/tests/UnitTests/__shared/templates/scope_tag.tpl b/tests/UnitTests/__shared/templates/scope_tag.tpl new file mode 100644 index 00000000..734ebb7b --- /dev/null +++ b/tests/UnitTests/__shared/templates/scope_tag.tpl @@ -0,0 +1 @@ +{include 'scope_include.tpl'} \ No newline at end of file