update scope tests

This commit is contained in:
uwetews
2016-02-09 01:40:34 +01:00
parent e0d4e4b1fa
commit ac5070ea87
69 changed files with 707 additions and 521 deletions

View File

@@ -10,7 +10,7 @@
* class for append tags tests * class for append tags tests
* *
* @runTestsInSeparateProcess * @runTestsInSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled
* @backupStaticAttributes enabled * @backupStaticAttributes enabled
*/ */
class CompileAppendTest extends PHPUnit_Smarty class CompileAppendTest extends PHPUnit_Smarty
@@ -18,24 +18,103 @@ class CompileAppendTest extends PHPUnit_Smarty
public function setUp() public function setUp()
{ {
$this->setUpSmarty(dirname(__FILE__)); $this->setUpSmarty(dirname(__FILE__));
$this->smarty->addPluginsDir("../../../__shared/PHPunitplugins/");
$this->smarty->addTemplateDir("../../../__shared/templates/");
$this->smarty->addTemplateDir("./templates_tmp");
} }
public function testInit() public function testInit()
{ {
$this->cleanDirs(); $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); $i = 0;
$this->assertEquals("12", $this->smarty->fetch('eval:{append var=foo value=2}{foreach $foo as $bar}{$bar}{/foreach}')); /*
* 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 ++,
),
);
}
} }

View File

@@ -15,11 +15,13 @@
*/ */
class CompileAssignTest extends PHPUnit_Smarty class CompileAssignTest extends PHPUnit_Smarty
{ {
public function setUp() public function setUp()
{ {
$this->setUpSmarty(dirname(__FILE__)); $this->setUpSmarty(dirname(__FILE__));
$this->smarty->addPluginsDir("./PHPunitplugins/"); $this->smarty->addPluginsDir("../../../__shared/PHPunitplugins/");
$this->smarty->registerFilter('pre', array($this, 'prefilterTest')); $this->smarty->addTemplateDir("../../../__shared/templates/");
$this->smarty->addTemplateDir("./templates_tmp");
} }
public function testInit() 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 * @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')); $file = "testAssign_{$testNumber}.tpl";
$this->assertEquals("bar", $this->smarty->fetch('004_oldFormat_1.tpl')); $this->makeTemplateFile($file, $code);
$this->assertEquals("3", $this->smarty->fetch('005_oldFormat_1.tpl')); $this->smarty->assignGlobal('file', $file);
$this->assertEquals("3", $this->smarty->fetch('006_oldFormat_1.tpl')); $this->smarty->assign('bar', 'buh');
$this->assertEquals("3", $this->smarty->fetch('007_oldFormat_1.tpl')); $this->assertEquals($this->strip($result), $this->strip($this->smarty->fetch($file)), "testAssign - {$code} - {$testName}");
$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')); * 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 * @preserveGlobalState disabled
* @dataProvider dataTestScope
*/ */
public function testAssignNew_001() public function testScope($code, $useSmarty, $result, $testName, $testNumber)
{
$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()
{ {
$file = "testScope_{$testNumber}.tpl";
$this->makeTemplateFile($file, $code . '{checkvar var=foo}');
$this->smarty->assignGlobal('file', $file);
$this->smarty->assign('foo', 'smarty'); $this->smarty->assign('foo', 'smarty');
$this->smarty->assignGlobal('foo', 'global'); $this->smarty->assignGlobal('foo', 'global');
$data = $this->smarty->createData(); $data = $this->smarty->createData($useSmarty ? $this->smarty : null);
$data->assign('foo', 'data'); $data->assign('foo', 'data');
$data->assign('include', '001_scope_root_1.tpl'); $this->assertEquals($this->strip('#' . $file . $result), $this->strip($this->smarty->fetch('scope_tag.tpl', $data)), "test - {$code} - {$testName}");
$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 provider für testscope
$data->assign('foo', 'data'); */
$data->assign('include', '001_scope_root_2.tpl'); public function dataTestScope()
$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()); $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 * @runInSeparateProcess
* @preserveGlobalState disabled * @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'); $this->smarty->assignGlobal('foo', 'global');
$data = $this->smarty->createData($this->smarty); $this->assertEquals($this->strip($result), $this->strip($this->smarty->fetch($file)), "test - {$file} {$var}");
$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());
} }
/** /*
* test scope global * Data provider für testscopenocache
* */
* @runInSeparateProcess public function dataTestScopeNocache()
* @preserveGlobalState disabled
*/
public function testAssignGlobal_002()
{ {
$this->smarty->assign('foo', 'smarty'); /*
$this->smarty->assign('include', '001_scope_global_1.tpl'); * variable value
$this->smarty->assignGlobal('foo', 'global'); * result
$data = $this->smarty->createData($this->smarty); */
$tpl = $this->smarty->createTemplate('001_scope_root.tpl', null, null, $data, false); return array(
$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", array(
$tpl->fetch()); 'b1', 'test_scope_assignbar.tpl',
$this->smarty->assign('include', '001_scope_global_2.tpl'); '#test_scope_assignbar.tpl:$foo=\'b1\'#Smarty:$foo=\'smarty\'#global:$foo=\'b1\'',
$this->smarty->assign('foo', 'smarty'); ), array(
$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", 'b2', 'test_scope_assignbar.tpl',
$tpl->fetch()); '#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\'',
),
);
} }
} }

View File

@@ -1,44 +0,0 @@
<?php
/**
* Smarty plugin for testing scopes
*
* @package Smarty
* @subpackage PHPunitPlugin
*/
/**
* Smarty {checkvar}
*
* @param array $params parameter array
* @param object $template template object
*
* @return string
*/
function smarty_function_checkvar($params, $template)
{
$output = '';
$var = $params['var'];
$ptr = $template;
while ($ptr) {
if ($ptr instanceof Smarty_Internal_Template) {
$output .= "template {$ptr->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;
}

View File

@@ -1 +0,0 @@
{$foo =1}{$foo[] = 2}{foreach $foo as $x}{$x@key}{$x}{/foreach}

View File

@@ -1 +0,0 @@
{assign var=foo value=1}{$foo}

View File

@@ -1,2 +0,0 @@
{assign var=foo value='new global' scope=global}
{checkvar var=foo}

View File

@@ -1,2 +0,0 @@
{$foo='new global' scope=global}
{checkvar var=foo}

View File

@@ -1,2 +0,0 @@
{assign var=foo value='none'}
{checkvar var=foo}

View File

@@ -1,2 +0,0 @@
{$foo='none'}
{checkvar var=foo}

View File

@@ -1,2 +0,0 @@
{assign var=foo value='parent' scope=parent}
{checkvar var=foo}

View File

@@ -1,2 +0,0 @@
{$foo='parent' scope=parent}
{checkvar var=foo}

View File

@@ -1 +0,0 @@
{include '001_scope_include.tpl'}

View File

@@ -1,2 +0,0 @@
{assign var=foo value='root' scope=root}
{checkvar var=foo}

View File

@@ -1,2 +0,0 @@
{$foo='root' scope=root}
{checkvar var=foo}

View File

@@ -1,2 +0,0 @@
{assign var=foo value='tpl_root' scope=tpl_root}
{checkvar var=foo}

View File

@@ -1,2 +0,0 @@
{$foo='tpl_root' scope=tpl_root}
{checkvar var=foo}

View File

@@ -1 +0,0 @@
{$foo[]=2}{foreach $foo as $x}{$x@key}{$x}{/foreach}

View File

@@ -1 +0,0 @@
{$foo[]=2 scope=root}{foreach $foo as $x}{$x@key}{$x}{/foreach}

View File

@@ -1 +0,0 @@
{foreach $foo as $x}{$x@key}{$x}{/foreach}

View File

@@ -1 +0,0 @@
{$foo=strlen('bar')}{$foo}

View File

@@ -1 +0,0 @@
{$foo['a'][4]=1}{$foo['a'][4]}

View File

@@ -1 +0,0 @@
{assign var=foo value=bar}{$foo}

View File

@@ -1 +0,0 @@
{$foo='bar'|strlen}{$foo}

View File

@@ -1 +0,0 @@
{assign var=foo value=1+2}{$foo}

View File

@@ -1 +0,0 @@
{$foo=[9,8,7,6]}{foreach $foo as $x}{$x}{/foreach}

View File

@@ -1 +0,0 @@
{assign var=foo value=strlen('bar')}{$foo}

View File

@@ -1 +0,0 @@
{$foo=['a'=>9,'b'=>8,'c'=>7,'d'=>6]}{foreach $foo as $x}{$x@key}{$x}{/foreach}

View File

@@ -1 +0,0 @@
{assign var=foo value='bar'|strlen}{$foo}

View File

@@ -1 +0,0 @@
{assign var=foo value=[9,8,7,6]}{foreach $foo as $x}{$x}{/foreach}

View File

@@ -1 +0,0 @@
{assign var=foo value=['a'=>9,'b'=>8,'c'=>7,'d'=>6]}{foreach $foo as $x}{$x@key}{$x}{/foreach}

View File

@@ -1 +0,0 @@
{assign foo value=1}{$foo}

View File

@@ -0,0 +1 @@
{$foo = $bar scope=global}{checkvar var=foo nocache}

View File

@@ -0,0 +1 @@
{$foo = $buh scope=global nocache}{checkvar var=foo nocache}

View File

@@ -10,7 +10,7 @@
* class for config variable tests * class for config variable tests
* *
* @runTestsInSeparateProcess * @runTestsInSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled
* @backupStaticAttributes enabled * @backupStaticAttributes enabled
*/ */
class CompileConfigLoadTest extends PHPUnit_Smarty class CompileConfigLoadTest extends PHPUnit_Smarty
@@ -23,22 +23,28 @@ class CompileConfigLoadTest extends PHPUnit_Smarty
public function setUp() public function setUp()
{ {
$this->setUpSmarty(dirname(__FILE__)); $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() public function testInit()
{ {
$this->cleanDirs(); $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() public function testConfigVariableSection2TemplateShorttags()
{ {
$this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('eval:{config_load \'test.conf\' \'section2\'}{#title#} {#sec1#} {#sec2#}')); $this->assertEquals("Welcome to Smarty! Global Section1 Hello Section2", $this->smarty->fetch('002_section2.tpl'));
}
/**
* 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'));
} }
/** /**
@@ -155,4 +135,95 @@ class CompileConfigLoadTest extends PHPUnit_Smarty
{ {
$this->smarty->fetch('eval:{config_load file=\'test_error.conf\'}'); $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 ++,
),
);
}
} }

View File

@@ -0,0 +1 @@
foo = data

View File

@@ -0,0 +1 @@
foo = smarty

View File

@@ -0,0 +1 @@
foo = newvar

View File

@@ -0,0 +1 @@
{config_load file='test.conf' section='section2'}{#title#} {#sec1#} {#sec2#}

View File

@@ -0,0 +1 @@
{config_load 'test.conf' 'section2'}{#title#} {#sec1#} {#sec2#}

View File

@@ -10,130 +10,128 @@
* class for {if} tag tests * class for {if} tag tests
* *
* @runTestsInSeparateProcess * @runTestsInSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled
* @backupStaticAttributes enabled * @backupStaticAttributes enabled
*/ */
class CompileIfTest extends PHPUnit_Smarty class CompileIfTest extends PHPUnit_Smarty
{ {
public function setUp() public function setUp()
{ {
$this->setUpSmarty(dirname(__FILE__)); $this->setUpSmarty(dirname(__FILE__));
$this->smarty->addPluginsDir("../../../__shared/PHPunitplugins/");
$this->smarty->addTemplateDir("../../../__shared/templates/");
$this->smarty->addTemplateDir("./templates_tmp");
} }
public function testInit() public function testInit()
{ {
$this->cleanDirs(); $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}'); $file = "testIf_{$testNumber}.tpl";
$this->assertEquals("yes", $this->smarty->fetch($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}'); $i = 1;
$this->assertEquals("yes", $this->smarty->fetch($tpl)); /*
* 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}'); if (!isset($file)) {
$this->assertEquals("no", $this->smarty->fetch($tpl)); $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}'); $i = 1;
$this->assertEquals("yes1", $this->smarty->fetch($tpl)); /*
} * var
* value
public function testIf4() * Code
{ * result
$tpl = $this->smarty->createTemplate('eval:{if 2<1}yes{elseif 6<5}yes1{else}no{/if}'); * test name
$this->assertEquals("no", $this->smarty->fetch($tpl)); */
} 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'),
public function testIfTrue() array('foo', false, false, 'no', '', $i ++, 'testIfNoCache_Var1.tpl'),
{ array('foo', false, false, 'no', '', $i ++, 'testIfNoCache_Var1.tpl'),
$tpl = $this->smarty->createTemplate('eval:{if true}yes{else}no{/if}'); array('foo', true, '{$bar=$foo}{if $bar}yes{else}no{/if}', 'yes', '', $i ++, 'testIfNoCache_Var2.tpl'),
$this->assertEquals("yes", $this->smarty->fetch($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'),
public function testIfFalse() 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'),
$tpl = $this->smarty->createTemplate('eval:{if false}yes{else}no{/if}'); array('foo', 0, false, 'no0', '', $i ++, 'testIfNoCache_Var3.tpl'),
$this->assertEquals("no", $this->smarty->fetch($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'),
public function testIfNot1() array('bar', 0, false, 'yes3', '', $i ++, 'testIfNoCache_Var4.tpl'),
{ array('bar', 0, false, 'yes3', '', $i ++, 'testIfNoCache_Var4.tpl'),
$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));
} }
public function testIfGT2() public function testIfGT2()

View File

@@ -18,6 +18,8 @@ class CompileIncludeTest extends PHPUnit_Smarty
public function setUp() public function setUp()
{ {
$this->setUpSmarty(dirname(__FILE__)); $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 * test spacing
* *
* @rrunInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled
* @dataProvider includeProviderCaching * @dataProvider includeProviderCaching
*/ */
public function testSpacing_001($merge, $caching, $text) public function testSpacing_001($merge, $caching, $text)
@@ -82,6 +85,8 @@ class CompileIncludeTest extends PHPUnit_Smarty
/** /**
* test standard output * test standard output
* *
* @runInSeparateProcess
* @preserveGlobalState disabled
* @dataProvider includeProvider * @dataProvider includeProvider
*/ */
public function testIncludeStandard_001($merge, $text) public function testIncludeStandard_001($merge, $text)
@@ -95,6 +100,8 @@ class CompileIncludeTest extends PHPUnit_Smarty
/** /**
* test standard output nocache var * test standard output nocache var
* *
* @runInSeparateProcess
* @preserveGlobalState disabled
* @dataProvider includeProvider * @dataProvider includeProvider
*/ */
public function testIncludeStandardNocacheVar($merge, $text) public function testIncludeStandardNocacheVar($merge, $text)
@@ -110,6 +117,8 @@ class CompileIncludeTest extends PHPUnit_Smarty
/** /**
* Test that assign attribute does not create standard output * Test that assign attribute does not create standard output
* *
* @runInSeparateProcess
* @preserveGlobalState disabled
* @dataProvider includeProvider * @dataProvider includeProvider
*/ */
public function testIncludeAssign1($merge, $text) public function testIncludeAssign1($merge, $text)
@@ -122,6 +131,8 @@ class CompileIncludeTest extends PHPUnit_Smarty
/** /**
* Test that assign attribute does load variable * Test that assign attribute does load variable
* *
* @runInSeparateProcess
* @preserveGlobalState disabled
* @dataProvider includeProvider * @dataProvider includeProvider
*/ */
public function testIncludeAssign2($merge, $text) public function testIncludeAssign2($merge, $text)
@@ -134,6 +145,8 @@ class CompileIncludeTest extends PHPUnit_Smarty
/** /**
* Test passing local vars eval * Test passing local vars eval
* *
* @runInSeparateProcess
* @preserveGlobalState disabled
* @dataProvider includeProvider * @dataProvider includeProvider
*/ */
public function testIncludePassVars($merge, $text) public function testIncludePassVars($merge, $text)
@@ -147,6 +160,8 @@ class CompileIncludeTest extends PHPUnit_Smarty
/** /**
* Test passing local vars include * Test passing local vars include
* *
* @runInSeparateProcess
* @preserveGlobalState disabled
* @dataProvider includeProvider * @dataProvider includeProvider
*/ */
public function testIncludePassVars2($merge, $text) public function testIncludePassVars2($merge, $text)
@@ -156,81 +171,70 @@ class CompileIncludeTest extends PHPUnit_Smarty
$this->assertEquals("12", $this->smarty->fetch($tpl), $text); $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); if ($testNumber) {
$this->smarty->assign('foo', 1); $file = "testScope_{$testNumber}.tpl";
$tpl = $this->smarty->createTemplate('test_include_parent_scope.tpl', null, null, $this->smarty, false); $this->makeTemplateFile($file, $code);
$content = $this->smarty->fetch($tpl); $this->smarty->assignGlobal('file', $file);
$content2 = $this->smarty->fetch('eval: root value {$foo}'); }
$this->assertContains('before include 1', $content, 'before include 1 ' . $text); $this->smarty->assign('foo', 'smarty');
$this->assertContains('in include 2', $content . 'in include 2 ' . $text); $this->smarty->assignGlobal('foo', 'global');
$this->assertContains('after include 2', $content, 'after include 2 ' . $text); $data = $this->smarty->createData($useSmarty ? $this->smarty : null);
$this->assertContains('root value 1', $content2, 'root value 1 ' . $text); $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 * Data provider for testscope
*
* @dataProvider includeProvider
*/ */
public function testIncludeRootScope($merge, $text) public function dataTestScope()
{ {
$this->smarty->setMergeCompiledIncludes($merge); $i = 1;
$this->smarty->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE)); return array(/*
$this->smarty->assign('foo', 1); * Code
$tpl = $this->smarty->createTemplate('test_include_root_scope.tpl'); * use Smarty object
$content = $this->smarty->fetch($tpl); * result
$content2 = $this->smarty->fetch('eval: smarty value {$foo}'); * test name
$this->assertNotContains('before include 1', $content, 'before include 1 ' . $text); */
$this->assertContains('in include 2', $content . 'in include 2 ' . $text); 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++),
$this->assertContains('after include 2', $content, 'after include 2 ' . $text); 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++),
$this->assertContains('smarty value 1', $content2, 'smarty value 1 ' . $text); 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 * Test recursive includes
* *
* @runInSeparateProcess
* @preserveGlobalState disabled
* @dataProvider includeProvider * @dataProvider includeProvider
*/ */
public function testRecursiveIncludes1($merge, $text) public function testRecursiveIncludes1($merge, $text)
@@ -245,6 +249,8 @@ class CompileIncludeTest extends PHPUnit_Smarty
/** /**
* Test recursive includes 2 * Test recursive includes 2
* *
* @runInSeparateProcess
* @preserveGlobalState disabled
* @dataProvider includeProvider * @dataProvider includeProvider
*/ */
public function testRecursiveIncludes2($merge, $text) public function testRecursiveIncludes2($merge, $text)

View File

@@ -1 +0,0 @@
before include {$foo} {include file='test_include_local_scope_sub.tpl'} after include {$foo}

View File

@@ -1 +0,0 @@
before include {$foo} {include file='test_include_local_scope_sub.tpl' scope = parent} after include {$foo}

View File

@@ -1 +0,0 @@
before include {$foo} {include file='test_include_local_scope_sub.tpl' scope = root} after include {$foo}

View File

@@ -0,0 +1 @@
{include $file}

View File

@@ -0,0 +1 @@
{$foo = 'newvar'}{checkvar var=foo}

View File

@@ -0,0 +1 @@
{pluginassign var=foo value='newvar'}{checkvar var=foo}

View File

@@ -25,12 +25,12 @@ class CompileFunctionTest extends PHPUnit_Smarty
{ {
$this->cleanDirs(); $this->cleanDirs();
} }
/** /**
* @runInSeparateProcess * @runInSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled
* @dataProvider functionProvider * @dataProvider functionProvider
* test simple function call tag * test simple function call tag
* *
*/ */
public function testSimpleFunction_001($text) public function testSimpleFunction_001($text)
{ {
@@ -38,6 +38,19 @@ class CompileFunctionTest extends PHPUnit_Smarty
$this->smarty->assign('default', 2); $this->smarty->assign('default', 2);
$this->assertEquals("default param default 1 2 1", $this->smarty->fetch('test_template_function_001.tpl'), $text); $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 * @runInSeparateProcess
@@ -69,7 +82,7 @@ class CompileFunctionTest extends PHPUnit_Smarty
/** /**
* @runInSeparateProcess * @run InSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled
* @dataProvider functionProvider * @dataProvider functionProvider
* test simple function call tag cached no cache default variable * test simple function call tag cached no cache default variable

View File

@@ -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}

View File

@@ -9,7 +9,7 @@
/** /**
* class for {while} tag tests * class for {while} tag tests
* *
* @runTestsInSeparateProcess * @not runTestsInSeparateProcess
* @preserveGlobalState disabled * @preserveGlobalState disabled
* @backupStaticAttributes enabled * @backupStaticAttributes enabled
*/ */
@@ -30,7 +30,7 @@ class CompileWhileTest extends PHPUnit_Smarty
*/ */
public function testWhileCondition() 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)); $this->assertEquals("0123456789", $this->smarty->fetch($tpl));
} }
@@ -39,7 +39,7 @@ class CompileWhileTest extends PHPUnit_Smarty
*/ */
public function testWhileStatement() 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)); $this->assertEquals("4321", $this->smarty->fetch($tpl));
} }
} }

View File

@@ -0,0 +1,45 @@
<?php
/**
* Smarty plugin for testing scopes in config vars
*
* @package Smarty
* @subpackage PHPunitPlugin
*/
/**
* Smarty {checkconfigvar}
*
* @param array $params parameter array
* @param object $template template object
*
* @return string
*/
function smarty_function_checkconfigvar($params, $template)
{
$output = '';
$types = array('template', 'data', 'smarty');
if (isset($params['types'])) {
$types = (array)$params['types'];
}
$var = $params['var'];
$ptr = $template;
while ($ptr) {
if (in_array('template', $types) && $ptr instanceof Smarty_Internal_Template) {
$output .= "#{$ptr->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;
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* Smarty plugin for testing scopes
*
* @package Smarty
* @subpackage PHPunitPlugin
*/
/**
* Smarty {checkvar}
*
* @param array $params parameter array
* @param object $template template object
*
* @return string
*/
function smarty_function_checkvar($params, $template)
{
$output = '';
$types = array('template', 'data', 'smarty', 'global');
if (isset($params['types'])) {
$types = (array)$params['types'];
}
$var = $params['var'];
$ptr = $template;
while ($ptr) {
if (in_array('template', $types) && $ptr instanceof Smarty_Internal_Template) {
$output .= "#{$ptr->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;
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* Smarty plugin for assign
*
* @package Smarty
* @subpackage PHPunitPlugin
*/
/**
* Smarty {pluginassign}
*
* @param array $params parameter array
* @param object $template template object
*
* @return string
*/
function smarty_function_pluginassign($params, $template)
{
$template->assign($params[ 'var' ], $params[ 'value' ]);
return '';
}

View File

@@ -0,0 +1 @@
{include $file}

View File

@@ -0,0 +1 @@
{include $file caching}

View File

@@ -0,0 +1 @@
{include $file}

View File

@@ -0,0 +1 @@
{include 'scope_include.tpl'}