summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Wisselink <s.wisselink@iwink.nl>2025-02-13 23:20:05 +0100
committerSimon Wisselink <s.wisselink@iwink.nl>2025-02-13 23:20:05 +0100
commita4b8466205416fd32199fcf6753f108cd5e5c9ed (patch)
tree3bf493c48c2aa9fa793f4571b9f3528cb36cfe43
parent5d1ea5806a10071fdb6af0fa945c8e3f58e033c4 (diff)
downloadsmarty-a4b8466205416fd32199fcf6753f108cd5e5c9ed.tar.gz
smarty-a4b8466205416fd32199fcf6753f108cd5e5c9ed.tar.bz2
smarty-a4b8466205416fd32199fcf6753f108cd5e5c9ed.zip
Added unit tests to prevent regressions of issue #1100 that was fixed in v4
-rw-r--r--tests/UnitTests/SmartyMethodsTests/RegisterModifier/RegisterModifierFirstClassCallablesTest.php55
-rw-r--r--tests/UnitTests/SmartyMethodsTests/RegisterModifier/RegisterModifierTest.php14
2 files changed, 69 insertions, 0 deletions
diff --git a/tests/UnitTests/SmartyMethodsTests/RegisterModifier/RegisterModifierFirstClassCallablesTest.php b/tests/UnitTests/SmartyMethodsTests/RegisterModifier/RegisterModifierFirstClassCallablesTest.php
new file mode 100644
index 00000000..18e3fa36
--- /dev/null
+++ b/tests/UnitTests/SmartyMethodsTests/RegisterModifier/RegisterModifierFirstClassCallablesTest.php
@@ -0,0 +1,55 @@
+<?php
+// first class callables where introduced in PHP 8.1
+if (PHP_VERSION_ID >= 80100) {
+
+ /**
+ * class for register modifier with (first class) callables tests
+ *
+ * @runTestsInSeparateProcess
+ * @preserveGlobalState disabled
+ * @backupStaticAttributes enabled
+ */
+ class RegisterModifierFirstClassCallablesTest extends PHPUnit_Smarty
+ {
+ public function setUp(): void
+ {
+ $this->setUpSmarty(__DIR__);
+ }
+
+
+ public function testInit()
+ {
+ $this->cleanDirs();
+ }
+
+ public function testRegisterFirstClassCallable()
+ {
+ $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'testmodifier', eval('return strrev(...);'));
+ $this->assertEquals('mosredna', $this->smarty->fetch('string:{"andersom"|testmodifier}'));
+ }
+
+ public function testRegisterFirstClassCallableSameName()
+ {
+ $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'mymodifier', eval('return strrev(...);'));
+ $this->assertEquals('mosredna', $this->smarty->fetch('string:{"andersom"|mymodifier}'));
+ }
+
+ public function testRegisterFirstClassCallableAsFunc()
+ {
+ $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'kprint_r_out', eval('return strrev(...);'));
+ $this->smarty->assign('myVar', 'andersom');
+ $this->assertEquals('mosredna', $this->smarty->fetch('string:{kprint_r_out($myVar)}'));
+ }
+
+ public function testRegisterFirstClassCallableSameNameAsPhpFunc()
+ {
+ $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'mymodifierfcc', eval('return strrev(...);'));
+ $this->assertEquals('mosredna', $this->smarty->fetch('string:{mymodifierfcc("andersom")}'));
+ }
+
+ }
+}
+function mymodifierfcc($a, $b, $c)
+{
+ return "$a function $b $c";
+}
diff --git a/tests/UnitTests/SmartyMethodsTests/RegisterModifier/RegisterModifierTest.php b/tests/UnitTests/SmartyMethodsTests/RegisterModifier/RegisterModifierTest.php
index 05ee7459..1d422d03 100644
--- a/tests/UnitTests/SmartyMethodsTests/RegisterModifier/RegisterModifierTest.php
+++ b/tests/UnitTests/SmartyMethodsTests/RegisterModifier/RegisterModifierTest.php
@@ -135,6 +135,20 @@ class RegisterModifierTest extends PHPUnit_Smarty
$this->assertEquals($expectedValue, $this->smarty->fetch('string:' . $template));
}
+ public function testRegisterNativePhpFuncAsString()
+ {
+ $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'strrev', 'strrev');
+ $this->smarty->assign('myVar', 'andersom');
+ $this->assertEquals('mosredna', $this->smarty->fetch('string:{strrev($myVar)}'));
+ }
+
+ public function testRegisterNativePhpFuncUnderDifferentName()
+ {
+ $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'k_xyz_a', 'strrev');
+ $this->smarty->assign('myVar', 'andersom');
+ $this->assertEquals('mosredna', $this->smarty->fetch('string:{k_xyz_a($myVar)}'));
+ }
+
}
class WildcardExtension extends \Smarty\Extension\Base {