From ffc4415a4fc8ecdcb3039cfa9158794649b578b9 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Sun, 6 Oct 2024 22:01:17 +0200 Subject: [PATCH] Add unit tests for short hand template function definition and shorthand template function calls. --- .../TemplateFunction/CompileFunctionTest.php | 26 ++++++++++++++++++- .../TemplateFunction/templates/shorthand1.tpl | 2 ++ .../TemplateFunction/templates/shorthand2.tpl | 2 ++ .../TemplateFunction/templates/shorthand3.tpl | 2 ++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/shorthand1.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/shorthand2.tpl create mode 100644 tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/shorthand3.tpl diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php index 6d1da7f5..62747ba2 100644 --- a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php @@ -438,7 +438,31 @@ class CompileFunctionTest extends PHPUnit_Smarty */ public function testIllegalFunctionName() { $this->expectException(SmartyCompilerException::class); - $this->smarty->fetch('string:{function name=\'rce(){};echo "hi";function \'}{/function}'); + $this->smarty->fetch('string:{function name=\'rce(){};echo "hi";function \'}{/function}'); + } + + /** + * test shorthand function definition with regular call + */ + public function testShorthand1() + { + $this->assertEquals("gribus", $this->smarty->fetch('shorthand1.tpl')); + } + + /** + * test normal function definition with shorthand call + */ + public function testShorthand2() + { + $this->assertEquals("gribus", $this->smarty->fetch('shorthand2.tpl')); + } + + /** + * test shorthand function definition with shorthand call + */ + public function testShorthand3() + { + $this->assertEquals("gribus", $this->smarty->fetch('shorthand3.tpl')); } } diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/shorthand1.tpl b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/shorthand1.tpl new file mode 100644 index 00000000..1ca50d70 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/shorthand1.tpl @@ -0,0 +1,2 @@ +{function blah}gribus{/function} +{call name=blah} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/shorthand2.tpl b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/shorthand2.tpl new file mode 100644 index 00000000..2901a3d5 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/shorthand2.tpl @@ -0,0 +1,2 @@ +{function name=blah}gribus{/function} +{blah} \ No newline at end of file diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/shorthand3.tpl b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/shorthand3.tpl new file mode 100644 index 00000000..61be2255 --- /dev/null +++ b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/templates/shorthand3.tpl @@ -0,0 +1,2 @@ +{function blah}gribus{/function} +{blah} \ No newline at end of file