From 7caf793eeb962947545cb33eeec91b3ecd594789 Mon Sep 17 00:00:00 2001 From: uwetews Date: Sat, 2 Jan 2016 00:48:20 +0100 Subject: [PATCH] add scope tests for {assign} --- .../TagTests/Assign/CompileAssignTest.php | 162 +++++++++++++++++- .../Assign/templates/001_oldFormat_2.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_oldFormat_1.tpl | 1 - .../Assign/templates/003_oldFormat_1.tpl | 1 - 16 files changed, 177 insertions(+), 10 deletions(-) delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_oldFormat_2.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_global_1.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_global_2.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_include.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_none_1.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_none_2.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_parent_1.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_parent_2.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root_1.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root_2.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_tpl_root_1.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_tpl_root_2.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/002_oldFormat_1.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_oldFormat_1.tpl diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/CompileAssignTest.php b/tests/UnitTests/TemplateSource/TagTests/Assign/CompileAssignTest.php index afe51b28..7e754101 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/CompileAssignTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/CompileAssignTest.php @@ -18,6 +18,8 @@ class CompileAssignTest extends PHPUnit_Smarty public function setUp() { $this->setUpSmarty(dirname(__FILE__)); + $this->smarty->addPluginsDir("./PHPunitplugins/"); + $this->smarty->registerFilter('pre', array($this, 'prefilterTest')); } public function testInit() @@ -34,9 +36,6 @@ class CompileAssignTest extends PHPUnit_Smarty public function testAssignOld_001() { $this->assertEquals("1", $this->smarty->fetch('001_oldFormat_1.tpl')); - $this->assertEquals("1", $this->smarty->fetch('001_oldFormat_2.tpl')); - $this->assertEquals("1", $this->smarty->fetch('002_oldFormat_1.tpl')); - $this->assertEquals("1", $this->smarty->fetch('003_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')); @@ -88,9 +87,9 @@ class CompileAssignTest extends PHPUnit_Smarty public function testAssignArrayAppend_002() { $this->smarty->assign('foo', 1); - $tpl = $this->smarty->createTemplate('002_newAppend_1.tpl', null, null, $this->smarty); + $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); + $tpl2 = $this->smarty->createTemplate('002_newAppend_2.tpl', null, null, $this->smarty, false); $this->assertEquals("1", $this->smarty->fetch($tpl2)); } @@ -103,9 +102,9 @@ class CompileAssignTest extends PHPUnit_Smarty public function testAssignArrayAppend_003() { $this->smarty->assign('foo', 1); - $tpl = $this->smarty->createTemplate('003_newAppend_1.tpl', null, null, $this->smarty); + $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); + $tpl2 = $this->smarty->createTemplate('003_newAppend_2.tpl', null, null, $this->smarty, false); $this->assertEquals("0112", $this->smarty->fetch($tpl2)); } @@ -119,4 +118,153 @@ class CompileAssignTest extends PHPUnit_Smarty { $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() + { + $this->smarty->assign('foo', 'smarty'); + $this->smarty->assignGlobal('foo', 'global'); + $data = $this->smarty->createData(); + $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()); + } + + /** + * test scope global + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testAssignGlobal_001() + { + $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 =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 + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testAssignGlobal_002() + { + $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()); + } } diff --git a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_oldFormat_2.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_oldFormat_2.tpl deleted file mode 100644 index f6be8cf9..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_oldFormat_2.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 new file mode 100644 index 00000000..a70a1fcd --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_global_1.tpl @@ -0,0 +1,2 @@ +{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 new file mode 100644 index 00000000..0e9db85b --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_global_2.tpl @@ -0,0 +1,2 @@ +{$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 new file mode 100644 index 00000000..4b81e464 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_include.tpl @@ -0,0 +1 @@ +{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 new file mode 100644 index 00000000..d8e101e5 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_none_1.tpl @@ -0,0 +1,2 @@ +{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 new file mode 100644 index 00000000..958cfd66 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_none_2.tpl @@ -0,0 +1,2 @@ +{$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 new file mode 100644 index 00000000..28bd40dc --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_parent_1.tpl @@ -0,0 +1,2 @@ +{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 new file mode 100644 index 00000000..a9f198f2 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_parent_2.tpl @@ -0,0 +1,2 @@ +{$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 new file mode 100644 index 00000000..7d59f8a8 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root.tpl @@ -0,0 +1 @@ +{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 new file mode 100644 index 00000000..a15e7d99 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root_1.tpl @@ -0,0 +1,2 @@ +{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 new file mode 100644 index 00000000..5a845101 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_root_2.tpl @@ -0,0 +1,2 @@ +{$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 new file mode 100644 index 00000000..fa59a8ac --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_tpl_root_1.tpl @@ -0,0 +1,2 @@ +{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 new file mode 100644 index 00000000..ba712a43 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/001_scope_tpl_root_2.tpl @@ -0,0 +1,2 @@ +{$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_oldFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/002_oldFormat_1.tpl deleted file mode 100644 index 664dc39a..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/002_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/003_oldFormat_1.tpl b/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_oldFormat_1.tpl deleted file mode 100644 index d9c17424..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Assign/templates/003_oldFormat_1.tpl +++ /dev/null @@ -1 +0,0 @@ -{assign var="foo" value=1}{$foo} \ No newline at end of file