From 0d8ddddc1b30881047a70870d665f132bb95ccbe Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Sun, 19 Nov 2017 10:50:49 +0100 Subject: [PATCH] Update spacing tests --- .../TemplateSource/Comments/CommentsTest.php | 95 ++++++++----------- .../SetFilter/CompileSetfilterTest.php | 10 -- .../_Issues/topic26878/NewlineSpacing.php | 69 ++++++++++++++ .../_Issues/topic26878/cache/dummy.txt | 1 + .../_Issues/topic26878/templates_c/dummy.txt | 1 + .../topic26878/templates_tmp/dummy.txt | 1 + 6 files changed, 113 insertions(+), 64 deletions(-) create mode 100644 tests/UnitTests/TemplateSource/_Issues/topic26878/NewlineSpacing.php create mode 100644 tests/UnitTests/TemplateSource/_Issues/topic26878/cache/dummy.txt create mode 100644 tests/UnitTests/TemplateSource/_Issues/topic26878/templates_c/dummy.txt create mode 100644 tests/UnitTests/TemplateSource/_Issues/topic26878/templates_tmp/dummy.txt diff --git a/tests/UnitTests/TemplateSource/Comments/CommentsTest.php b/tests/UnitTests/TemplateSource/Comments/CommentsTest.php index 3d9397b5..281b5aec 100644 --- a/tests/UnitTests/TemplateSource/Comments/CommentsTest.php +++ b/tests/UnitTests/TemplateSource/Comments/CommentsTest.php @@ -10,7 +10,7 @@ * class for security test * * @runTestsInSeparateProcess - * @preserveGlobalState disabled + * @preserveGlobalState disabled * @backupStaticAttributes enabled */ class CommentsTest extends PHPUnit_Smarty @@ -26,67 +26,54 @@ class CommentsTest extends PHPUnit_Smarty } /** - * test simple comments + * Test comments + * + * @preserveGlobalState disabled + * @dataProvider dataTestComments */ - public function testSimpleComment1() + public function testComments($code, $result, $testName, $testNumber) { - $tpl = $this->smarty->createTemplate("eval:{* this is a comment *}"); - $this->assertEquals("", $this->smarty->fetch($tpl)); + $name = empty($testName) ? $testNumber : $testName; + $file = "testComments_{$name}.tpl"; + $this->makeTemplateFile($file, $code); + $this->smarty->template_dir = './templates_tmp'; + $this->assertEquals($result, + $this->smarty->fetch($file), + $file); } - public function testSimpleComment2() + /* + * Data provider für testComments + */ + public function dataTestComments() { - $tpl = $this->smarty->createTemplate("eval:{* another \$foo comment *}"); - $this->assertEquals("", $this->smarty->fetch($tpl)); + $i = 1; + /* + * Code + * result + * test name + * test number + */ + return array(array('{* this is a comment *}', '', 'T1', $i++), + array('{* another $foo comment *}', '', 'T2', $i++), + array('{* another comment *}some in between{* another comment *}', 'some in between', + 'T3', $i++), + array("{* multi line \n comment *}", '', 'T4', $i++), + array('{* /* foo * / *}', '', 'T5', $i++), + array("A{* comment *}B\nC", "AB\nC", 'T6', $i++), + array("D{* comment *}\n{* comment *}E\nF", "DE\nF", 'T7', $i++), + array("G{* multi \nline *}H", "GH", 'T8', $i++), + array("I{* multi \nline *}\nJ", "IJ", 'T9', $i++), + array("=\n{* comment *}\n{* comment *}\n b\n{* comment *}\n{* comment *}\n=", "=\n b\n=", 'T10', $i++), + array("=\na\n{* comment 1 *}\n{* comment 2 *}\n{* comment 3 *}\nb\n=", "=\na\nb\n=", 'T11', $i++), + array("=\na\n{* comment 1 *}\n {* comment 2 *}\n{* comment 3 *}\nb\n=", "=\na\n b\n=", 'T12', $i++), + array("=\na\n{* comment 1 *}\n{* comment 2 *} \n{* comment 3 *}\nb\n=", "=\na\n \nb\n=", 'T13', $i++), + array("=\na\n{* comment 1 *}\n {* comment 2 *} \n{* comment 3 *}\nb\n=", "=\na\n \nb\n=", 'T14', $i++), + ); } - public function testSimpleComment3() - { - $tpl = $this->smarty->createTemplate("eval:{* another comment *}some in between{* another comment *}"); - $this->assertEquals("some in between", $this->smarty->fetch($tpl)); - } - - public function testSimpleComment4() - { - $tpl = $this->smarty->createTemplate("eval:{* multi line \n comment *}"); - $this->assertEquals("", $this->smarty->fetch($tpl)); - } - - public function testSimpleComment5() - { - $tpl = $this->smarty->createTemplate("eval:{* /* foo * / *}"); - $this->assertEquals("", $this->smarty->fetch($tpl)); - } - - /** - * test comment text combinations - */ - public function testTextComment1() - { - $tpl = $this->smarty->createTemplate("eval:A{* comment *}B\nC"); - $this->assertEquals("AB\nC", $this->smarty->fetch($tpl)); - } - - public function testTextComment2() - { - $tpl = $this->smarty->createTemplate("eval:D{* comment *}\n{* comment *}E\nF"); - $this->assertEquals("D\nE\nF", $this->smarty->fetch($tpl)); - } - - public function testTextComment3() - { - $tpl = $this->smarty->createTemplate("eval:G{* multi \nline *}H"); - $this->assertEquals("GH", $this->smarty->fetch($tpl)); - } - - public function testTextComment4() - { - $tpl = $this->smarty->createTemplate("eval:I{* multi \nline *}\nJ"); - $this->assertEquals("I\nJ", $this->smarty->fetch($tpl)); - } public function testTextComment5() { - $tpl = $this->smarty->createTemplate("longcomment.tpl"); - $this->assertEquals("I\nJ", $this->smarty->fetch($tpl)); + $this->assertEquals("IJ", $this->smarty->fetch("longcomment.tpl"), 'Comments longcomment.tpl'); } } diff --git a/tests/UnitTests/TemplateSource/TagTests/SetFilter/CompileSetfilterTest.php b/tests/UnitTests/TemplateSource/TagTests/SetFilter/CompileSetfilterTest.php index 82ab2086..21227faa 100644 --- a/tests/UnitTests/TemplateSource/TagTests/SetFilter/CompileSetfilterTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/SetFilter/CompileSetfilterTest.php @@ -35,14 +35,4 @@ class CompileSetfilterTest extends PHPUnit_Smarty $tpl->assign('foo', ''); $this->assertEquals(" <a@b.c> <a@b.c> ", $this->smarty->fetch($tpl)); } - /** - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function testNestedSetfilter2() - { - $tpl = $this->smarty->createTemplate('string:{$foo}{setfilter htmlspecialchars} {$foo}{setfilter escape:"mail"} {$foo}{/setfilter} {$foo}{/setfilter} {$foo}'); - $tpl->assign('foo', ''); - $this->assertEquals(" <a@b.c> <a@b.c> ", $this->smarty->fetch($tpl)); - } } diff --git a/tests/UnitTests/TemplateSource/_Issues/topic26878/NewlineSpacing.php b/tests/UnitTests/TemplateSource/_Issues/topic26878/NewlineSpacing.php new file mode 100644 index 00000000..6feac558 --- /dev/null +++ b/tests/UnitTests/TemplateSource/_Issues/topic26878/NewlineSpacing.php @@ -0,0 +1,69 @@ +setUpSmarty(dirname(__FILE__)); + } + + public function testInit() + { + $this->cleanDirs(); + } + + /** + * Test spacings + * + * @preserveGlobalState disabled + * @dataProvider dataTestSpacing + * @runInSeparateProcess + */ + public function testSpacing($code, $result, $testName, $testNumber) + { + $name = empty($testName) ? $testNumber : $testName; + $file = "Spacing_{$name}.tpl"; + $this->makeTemplateFile($file, $code); + $this->smarty->template_dir = './templates_tmp'; + $this->smarty->assign('file', $file); + $this->smarty->assign('foo', 'bar'); + $this->assertEquals($result, + $this->smarty->fetch($file), + $file); + } + + /* + * Data provider für testSpacing + */ + public function dataTestSpacing() + { + $i = 1; + /* + * Code + * result + * test name + * test number + */ + return array( + array("=====================\n{if true}\n{foreach from=array(1) item='i'}\n \n{/foreach}\n{/if}\n=====================", "=====================\n \n=====================", 'T1', $i++), + array("=====================\n{if true}\n{if true}\n \n{/if}\n{/if}\n=====================", "=====================\n \n=====================", 'T2', $i++), + array("=====================\n{* comment *}\n{* comment *}\n \n{* comment *}\n{* comment *}\n=====================", "=====================\n \n=====================", 'T3', $i++), + array("=====================\na\n{* comment 1 *}\n{* comment 2 *}\n{* comment 3 *}\nb\n=====================", "=====================\na\nb\n=====================", 'T4', $i++), + array("=====================\na\nb{if true}\nd\nf{/if}\nh\n=====================", "=====================\na\nbd\nfh\n=====================", 'T5', $i++), + ); + } + +} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/_Issues/topic26878/cache/dummy.txt b/tests/UnitTests/TemplateSource/_Issues/topic26878/cache/dummy.txt new file mode 100644 index 00000000..2995a4d0 --- /dev/null +++ b/tests/UnitTests/TemplateSource/_Issues/topic26878/cache/dummy.txt @@ -0,0 +1 @@ +dummy \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/_Issues/topic26878/templates_c/dummy.txt b/tests/UnitTests/TemplateSource/_Issues/topic26878/templates_c/dummy.txt new file mode 100644 index 00000000..2995a4d0 --- /dev/null +++ b/tests/UnitTests/TemplateSource/_Issues/topic26878/templates_c/dummy.txt @@ -0,0 +1 @@ +dummy \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/_Issues/topic26878/templates_tmp/dummy.txt b/tests/UnitTests/TemplateSource/_Issues/topic26878/templates_tmp/dummy.txt new file mode 100644 index 00000000..2995a4d0 --- /dev/null +++ b/tests/UnitTests/TemplateSource/_Issues/topic26878/templates_tmp/dummy.txt @@ -0,0 +1 @@ +dummy \ No newline at end of file