From 688151e06fbb49c3ccb3c02a4a81a445d976cf90 Mon Sep 17 00:00:00 2001 From: uwetews Date: Tue, 12 Jul 2016 00:25:14 +0200 Subject: [PATCH] Update capture test --- .../TagTests/Capture/CompileCaptureTest.php | 80 ++++++++----------- .../Capture/templates/009_capture.tpl | 3 +- .../Capture/templates/009_capture_include.tpl | 3 +- .../_Core/AutoEscape/cache/dummy.txt | 0 .../_Core/AutoEscape/templates_c/dummy.txt | 0 tests/UnitTests/_Core/Filter/cache/dummy.txt | 0 .../_Core/Filter/templates_c/dummy.txt | 0 .../_Core/GetterSetter/cache/dummy.txt | 0 .../_Core/GetterSetter/templates_c/dummy.txt | 0 .../_Core/LoadPlugin/cache/dummy.txt | 0 .../_Core/LoadPlugin/templates_c/dummy.txt | 0 .../_Core/MuteExpectedErrors/cache/dummy.txt | 0 .../MuteExpectedErrors/templates_c/dummy.txt | 0 .../_Core/PluginTests/Shared/cache/dummy.txt | 0 .../PluginTests/Shared/templates_c/dummy.txt | 0 .../_Core/PluginTests/cache/dummy.txt | 0 .../_Core/PluginTests/templates_c/dummy.txt | 0 .../UnitTests/_Core/SmartyBC/cache/dummy.txt | 0 .../_Core/SmartyBC/templates_c/dummy.txt | 0 19 files changed, 38 insertions(+), 48 deletions(-) delete mode 100644 tests/UnitTests/_Core/AutoEscape/cache/dummy.txt delete mode 100644 tests/UnitTests/_Core/AutoEscape/templates_c/dummy.txt delete mode 100644 tests/UnitTests/_Core/Filter/cache/dummy.txt delete mode 100644 tests/UnitTests/_Core/Filter/templates_c/dummy.txt delete mode 100644 tests/UnitTests/_Core/GetterSetter/cache/dummy.txt delete mode 100644 tests/UnitTests/_Core/GetterSetter/templates_c/dummy.txt delete mode 100644 tests/UnitTests/_Core/LoadPlugin/cache/dummy.txt delete mode 100644 tests/UnitTests/_Core/LoadPlugin/templates_c/dummy.txt delete mode 100644 tests/UnitTests/_Core/MuteExpectedErrors/cache/dummy.txt delete mode 100644 tests/UnitTests/_Core/MuteExpectedErrors/templates_c/dummy.txt delete mode 100644 tests/UnitTests/_Core/PluginTests/Shared/cache/dummy.txt delete mode 100644 tests/UnitTests/_Core/PluginTests/Shared/templates_c/dummy.txt delete mode 100644 tests/UnitTests/_Core/PluginTests/cache/dummy.txt delete mode 100644 tests/UnitTests/_Core/PluginTests/templates_c/dummy.txt delete mode 100644 tests/UnitTests/_Core/SmartyBC/cache/dummy.txt delete mode 100644 tests/UnitTests/_Core/SmartyBC/templates_c/dummy.txt diff --git a/tests/UnitTests/TemplateSource/TagTests/Capture/CompileCaptureTest.php b/tests/UnitTests/TemplateSource/TagTests/Capture/CompileCaptureTest.php index 12e9812a..9d4492d9 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Capture/CompileCaptureTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Capture/CompileCaptureTest.php @@ -18,6 +18,7 @@ class CompileCaptureTest extends PHPUnit_Smarty public function setUp() { $this->setUpSmarty(dirname(__FILE__)); + $this->smarty->addTemplateDir("./templates_tmp"); } @@ -25,65 +26,52 @@ class CompileCaptureTest extends PHPUnit_Smarty { $this->cleanDirs(); } + /** - * test capture tag + * Test capture tags + * + * @not runInSeparateProcess + * @preserveGlobalState disabled + * @dataProvider dataTestCapture */ - public function testCapture1() + public function testCapture($code, $result, $testName, $testNumber) { - $tpl = $this->smarty->createTemplate('eval:{capture assign=foo}hello world{/capture}'); - $this->assertEquals("", $this->smarty->fetch($tpl)); - } - - public function testCapture2() - { - $tpl = $this->smarty->createTemplate('eval:{assign var=foo value=bar}{capture assign=foo}hello world{/capture}{$foo}'); - $this->assertEquals("hello world", $this->smarty->fetch($tpl)); - } - - public function testCapture3() - { - $tpl = $this->smarty->createTemplate('eval:{capture name=foo}hello world{/capture}{$smarty.capture.foo}'); - $this->assertEquals("hello world", $this->smarty->fetch($tpl)); - } - - public function testCapture4() - { - $tpl = $this->smarty->createTemplate('eval:{capture name=foo assign=bar}hello world{/capture}{$smarty.capture.foo} {$bar}'); - $this->assertEquals("hello world hello world", $this->smarty->fetch($tpl)); - } - - public function testCapture5() - { - $tpl = $this->smarty->createTemplate('eval:{capture}hello world{/capture}{$smarty.capture.default}'); - $this->assertEquals("hello world", $this->smarty->fetch($tpl)); - } - - public function testCapture6() - { - $tpl = $this->smarty->createTemplate('eval:{capture short}hello shorttag{/capture}{$smarty.capture.short}'); - $this->assertEquals("hello shorttag", $this->smarty->fetch($tpl)); - } - - public function testCapture7() - { - $tpl = $this->smarty->createTemplate('eval:{capture append=foo}hello{/capture}bar{capture append=foo}world{/capture}{foreach $foo item} {$item@key} {$item}{/foreach}'); - $this->assertEquals("bar 0 hello 1 world", $this->smarty->fetch($tpl)); + $file = "testCapture{$testNumber}.tpl"; + $this->makeTemplateFile($file, $code); + $this->smarty->assignGlobal('file', $file); + $this->assertEquals($this->strip($result), $this->strip($this->smarty->fetch($file)), "testCapture - {$code} - {$testName}"); } /* - * The following test has been disabled. It fails only in PHPunit - */ - public function testCapture8() + * Data provider für testCapture + */ + public function dataTestCapture() { - $tpl = $this->smarty->createTemplate('eval:{capture assign=foo}hello {capture assign=bar}this is my {/capture}world{/capture}{$foo} {$bar}'); - $this->assertEquals("hello world this is my ", $this->smarty->fetch($tpl), 'This failure pops up only during PHPunit test ?????'); + $i = 1; + /* + * Code + * result + * test name + */ + return array(// old format + array('{assign var=foo value=bar}{capture assign=foo}hello world{/capture}{$foo}', 'hello world', '', $i ++), + array('{capture name=foo}hello world{/capture}{$smarty.capture.foo}', 'hello world', '', $i ++), + array('{capture name=foo assign=bar}hello world{/capture}{$smarty.capture.foo} {$bar}', 'hello world hello world', '', $i ++), + array('{capture}hello world{/capture}{$smarty.capture.default}', 'hello world', '', $i ++), + array('{capture short}hello shorttag{/capture}{$smarty.capture.short}', 'hello shorttag', '', $i ++), + array('{capture append=foo}hello{/capture}bar{capture append=foo}world{/capture}{foreach $foo item} {$item@key} {$item}{/foreach}', 'bar 0 hello 1 world', '', $i ++), + array('{capture assign=foo}hello {capture assign=bar}this is my {/capture}world{/capture}{$foo} {$bar}', 'hello world this is my ', '', $i ++), + array('{capture name=foo}hello world{/capture}{capture name=Foo}Smarty 3{/capture}{$smarty.capture.foo} {$smarty.capture.Foo}', 'hello world Smarty 3', '', $i ++), + ); } /* * Test that capture results are global */ public function testCapture9() { - $this->assertContains('-->hello world<--', $this->smarty->fetch('009_capture.tpl')); + $result = $this->smarty->fetch('009_capture.tpl'); + $this->assertContains('-->hello world<--', $result); + $this->assertContains('-->hello world2<--', $result); } public function testCompileCaptureNocache1() diff --git a/tests/UnitTests/TemplateSource/TagTests/Capture/templates/009_capture.tpl b/tests/UnitTests/TemplateSource/TagTests/Capture/templates/009_capture.tpl index 9526623d..00c7fecf 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Capture/templates/009_capture.tpl +++ b/tests/UnitTests/TemplateSource/TagTests/Capture/templates/009_capture.tpl @@ -1,2 +1,3 @@ {capture name='test'}hello world{/capture} -{include '009_capture_include.tpl'} \ No newline at end of file +{include '009_capture_include.tpl'} +-->{$smarty.capture.test2}<-- \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Capture/templates/009_capture_include.tpl b/tests/UnitTests/TemplateSource/TagTests/Capture/templates/009_capture_include.tpl index f88ac6a2..b37f029a 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Capture/templates/009_capture_include.tpl +++ b/tests/UnitTests/TemplateSource/TagTests/Capture/templates/009_capture_include.tpl @@ -1 +1,2 @@ --->{$smarty.capture.test}<-- \ No newline at end of file +-->{$smarty.capture.test}<-- +{capture name='test2'}hello world2{/capture} \ No newline at end of file diff --git a/tests/UnitTests/_Core/AutoEscape/cache/dummy.txt b/tests/UnitTests/_Core/AutoEscape/cache/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/_Core/AutoEscape/templates_c/dummy.txt b/tests/UnitTests/_Core/AutoEscape/templates_c/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/_Core/Filter/cache/dummy.txt b/tests/UnitTests/_Core/Filter/cache/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/_Core/Filter/templates_c/dummy.txt b/tests/UnitTests/_Core/Filter/templates_c/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/_Core/GetterSetter/cache/dummy.txt b/tests/UnitTests/_Core/GetterSetter/cache/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/_Core/GetterSetter/templates_c/dummy.txt b/tests/UnitTests/_Core/GetterSetter/templates_c/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/_Core/LoadPlugin/cache/dummy.txt b/tests/UnitTests/_Core/LoadPlugin/cache/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/_Core/LoadPlugin/templates_c/dummy.txt b/tests/UnitTests/_Core/LoadPlugin/templates_c/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/_Core/MuteExpectedErrors/cache/dummy.txt b/tests/UnitTests/_Core/MuteExpectedErrors/cache/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/_Core/MuteExpectedErrors/templates_c/dummy.txt b/tests/UnitTests/_Core/MuteExpectedErrors/templates_c/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/_Core/PluginTests/Shared/cache/dummy.txt b/tests/UnitTests/_Core/PluginTests/Shared/cache/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/_Core/PluginTests/Shared/templates_c/dummy.txt b/tests/UnitTests/_Core/PluginTests/Shared/templates_c/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/_Core/PluginTests/cache/dummy.txt b/tests/UnitTests/_Core/PluginTests/cache/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/_Core/PluginTests/templates_c/dummy.txt b/tests/UnitTests/_Core/PluginTests/templates_c/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/_Core/SmartyBC/cache/dummy.txt b/tests/UnitTests/_Core/SmartyBC/cache/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/_Core/SmartyBC/templates_c/dummy.txt b/tests/UnitTests/_Core/SmartyBC/templates_c/dummy.txt deleted file mode 100644 index e69de29b..00000000