|
| 1 | +<?php |
| 2 | +// first class callables where introduced in PHP 8.1 |
| 3 | +if (PHP_VERSION_ID >= 80100) { |
| 4 | + |
| 5 | + /** |
| 6 | + * class for register modifier with (first class) callables tests |
| 7 | + * |
| 8 | + * @runTestsInSeparateProcess |
| 9 | + * @preserveGlobalState disabled |
| 10 | + * @backupStaticAttributes enabled |
| 11 | + */ |
| 12 | + class RegisterModifierFirstClassCallablesTest extends PHPUnit_Smarty |
| 13 | + { |
| 14 | + public function setUp(): void |
| 15 | + { |
| 16 | + $this->setUpSmarty(__DIR__); |
| 17 | + } |
| 18 | + |
| 19 | + |
| 20 | + public function testInit() |
| 21 | + { |
| 22 | + $this->cleanDirs(); |
| 23 | + } |
| 24 | + |
| 25 | + public function testRegisterFirstClassCallable() |
| 26 | + { |
| 27 | + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'testmodifier', eval('return strrev(...);')); |
| 28 | + $this->assertEquals('mosredna', $this->smarty->fetch('string:{"andersom"|testmodifier}')); |
| 29 | + } |
| 30 | + |
| 31 | + public function testRegisterFirstClassCallableSameName() |
| 32 | + { |
| 33 | + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'mymodifier', eval('return strrev(...);')); |
| 34 | + $this->assertEquals('mosredna', $this->smarty->fetch('string:{"andersom"|mymodifier}')); |
| 35 | + } |
| 36 | + |
| 37 | + public function testRegisterFirstClassCallableAsFunc() |
| 38 | + { |
| 39 | + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'kprint_r_out', eval('return strrev(...);')); |
| 40 | + $this->smarty->assign('myVar', 'andersom'); |
| 41 | + $this->assertEquals('mosredna', $this->smarty->fetch('string:{kprint_r_out($myVar)}')); |
| 42 | + } |
| 43 | + |
| 44 | + public function testRegisterFirstClassCallableSameNameAsPhpFunc() |
| 45 | + { |
| 46 | + $this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'mymodifierfcc', eval('return strrev(...);')); |
| 47 | + $this->assertEquals('mosredna', $this->smarty->fetch('string:{mymodifierfcc("andersom")}')); |
| 48 | + } |
| 49 | + |
| 50 | + } |
| 51 | +} |
| 52 | +function mymodifierfcc($a, $b, $c) |
| 53 | +{ |
| 54 | + return "$a function $b $c"; |
| 55 | +} |
0 commit comments