From 90a4a5c28e2ca798c1ee5f505175e0dbb2cc4cdb Mon Sep 17 00:00:00 2001 From: uwetews Date: Wed, 10 Feb 2016 21:05:36 +0100 Subject: [PATCH] add more tests for strip --- .../TagTests/Strip/CompileStripTest.php | 77 ++++++++----------- .../TagTests/Strip/cache/dummy.txt | 0 .../TagTests/Strip/templates/strip.tpl | 5 -- .../Strip/templates/strip_html_tag.tpl | 10 --- .../templates/strip_multi_line_html_tag.tpl | 9 --- .../strip_multi_line_textarea_html_tag.tpl | 8 -- .../templates/strip_with_no_output_tag.tpl | 3 - .../Strip/templates/strip_with_output_tag.tpl | 3 - .../PHPunitplugins/function.getvar.php | 24 ++++++ 9 files changed, 57 insertions(+), 82 deletions(-) delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Strip/cache/dummy.txt delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_html_tag.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_multi_line_html_tag.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_multi_line_textarea_html_tag.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_with_no_output_tag.tpl delete mode 100644 tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_with_output_tag.tpl create mode 100644 tests/UnitTests/__shared/PHPunitplugins/function.getvar.php diff --git a/tests/UnitTests/TemplateSource/TagTests/Strip/CompileStripTest.php b/tests/UnitTests/TemplateSource/TagTests/Strip/CompileStripTest.php index f943d08e..a34fca5a 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Strip/CompileStripTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Strip/CompileStripTest.php @@ -18,6 +18,8 @@ class CompileStripTest extends PHPUnit_Smarty public function setUp() { $this->setUpSmarty(dirname(__FILE__)); + $this->smarty->addPluginsDir("../../../__shared/PHPunitplugins/"); + $this->smarty->addTemplateDir("./templates_tmp"); } @@ -25,58 +27,45 @@ class CompileStripTest extends PHPUnit_Smarty { $this->cleanDirs(); } - /** - * test strip tag - */ - public function testStripTag() - { - $this->assertContains('foobar buh', $this->smarty->fetch('strip.tpl')); - } - /** - * test strip tag multi line html - */ - public function testStripMultiLineHtmlTag() - { - $this->assertContains('
[X]
foobar', $this->smarty->fetch('strip_multi_line_html_tag.tpl')); - } - /** - * test strip tag multi line html - */ - public function testStripHtmlTag() - { - $this->assertContains('', $this->smarty->fetch('strip_html_tag.tpl')); - } - /** - * test strip tag multi line html - */ - public function testStripMultiLineTextareaHtmlTag() - { - $this->assertContains(preg_replace('/[\r]/', '', ' foobar'), $this->smarty->fetch('strip_multi_line_textarea_html_tag.tpl')); - } /** - * test strip tag output tag + * Test {strip} tags * - * @runInSeparateProcess + * @not runInSeparateProcess * @preserveGlobalState disabled + * @dataProvider dataTestStrip */ - public function testStripOutputTag() + public function testStrip($code, $result, $testName, $testNumber) { - $this->assertEquals('

1 italic

', $this->smarty->fetch('strip_with_output_tag.tpl')); + $file = "testStrip_{$testNumber}.tpl"; + $this->makeTemplateFile($file, "{strip}\n" . $code); + $this->smarty->assignGlobal('file', $file); + $this->assertEquals($this->strip($result), $this->strip($this->smarty->fetch($file)), "testStrip - {$code} - {$testName}"); } - /** - * test strip tag no output tag - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testStripNoOutputTag() + /* + * Data provider für testStrip + */ + public function dataTestStrip() { - $this->assertEquals('

italic

', $this->smarty->fetch('strip_with_no_output_tag.tpl')); + $i = 0; + /* + * Code + * result + * test name + */ + return array( + array(" foo\n bar buh\n\n", 'foobar buh', '', $i ++), + array("\n
[X]
\n\n\n foo\n bar\n", '
[X]
foobar', '', $i ++), + array("\n \n", '', '', $i ++), + array("\n foo\n bar\n", " foobar", '', $i ++), + // variable in html tag + array("{\$foo=1}\n

{getvar var=foo} italic

\n", '

1 italic

', '', $i ++), + array("{\$foo=1}\n

{getvar var=foo assign=newvar} italic

\n", '

italic

', '', $i ++), + array("{\$text=\"Text\"}\n#{\$text}#\n", '#Text#', '', $i ++), + array("{\$text=\"Text\"}\n# {'Text'}\n", '# Text', '', $i ++), + + ); } + } diff --git a/tests/UnitTests/TemplateSource/TagTests/Strip/cache/dummy.txt b/tests/UnitTests/TemplateSource/TagTests/Strip/cache/dummy.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip.tpl b/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip.tpl deleted file mode 100644 index 8d835418..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip.tpl +++ /dev/null @@ -1,5 +0,0 @@ -{strip} - foo - bar buh - -{/strip} diff --git a/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_html_tag.tpl b/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_html_tag.tpl deleted file mode 100644 index b9479616..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_html_tag.tpl +++ /dev/null @@ -1,10 +0,0 @@ -{strip} - -{/strip} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_multi_line_html_tag.tpl b/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_multi_line_html_tag.tpl deleted file mode 100644 index 30115af4..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_multi_line_html_tag.tpl +++ /dev/null @@ -1,9 +0,0 @@ -{strip} -
[X]
- - - foo - bar -{/strip} diff --git a/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_multi_line_textarea_html_tag.tpl b/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_multi_line_textarea_html_tag.tpl deleted file mode 100644 index df392809..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_multi_line_textarea_html_tag.tpl +++ /dev/null @@ -1,8 +0,0 @@ -{strip} - foo - bar -{/strip} diff --git a/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_with_no_output_tag.tpl b/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_with_no_output_tag.tpl deleted file mode 100644 index 3a6fe026..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_with_no_output_tag.tpl +++ /dev/null @@ -1,3 +0,0 @@ -{strip} -

{counter assign=foo} italic

-{/strip} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_with_output_tag.tpl b/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_with_output_tag.tpl deleted file mode 100644 index b23240a6..00000000 --- a/tests/UnitTests/TemplateSource/TagTests/Strip/templates/strip_with_output_tag.tpl +++ /dev/null @@ -1,3 +0,0 @@ -{strip} -

{counter} italic

-{/strip} \ No newline at end of file diff --git a/tests/UnitTests/__shared/PHPunitplugins/function.getvar.php b/tests/UnitTests/__shared/PHPunitplugins/function.getvar.php new file mode 100644 index 00000000..2b78fbbb --- /dev/null +++ b/tests/UnitTests/__shared/PHPunitplugins/function.getvar.php @@ -0,0 +1,24 @@ +assign($params[ 'assign' ], $template->getTemplateVars($params[ 'var' ])); + } else { + return $template->getTemplateVars($params[ 'var' ]); + } +}