2025-02-13 23:20:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
2026-05-03 22:19:50 +02:00
|
|
|
/**
|
|
|
|
|
* class for register modifier with (first class) callables tests
|
|
|
|
|
*
|
|
|
|
|
* @runTestsInSeparateProcess
|
|
|
|
|
* @preserveGlobalState disabled
|
|
|
|
|
* @backupStaticAttributes enabled
|
|
|
|
|
*/
|
|
|
|
|
class RegisterModifierFirstClassCallablesTest extends PHPUnit_Smarty
|
|
|
|
|
{
|
|
|
|
|
public function setUp(): void
|
2025-02-13 23:20:05 +01:00
|
|
|
{
|
2026-05-03 22:19:50 +02:00
|
|
|
// First-class callable syntax (Closure::fromCallable shorthand) requires PHP 8.1+
|
|
|
|
|
if (PHP_VERSION_ID < 80100) {
|
|
|
|
|
$this->markTestSkipped('First-class callables require PHP >= 8.1');
|
2025-02-13 23:20:05 +01:00
|
|
|
}
|
2026-05-03 22:19:50 +02:00
|
|
|
$this->setUpSmarty(__DIR__);
|
2025-02-13 23:20:05 +01:00
|
|
|
}
|
2026-05-03 22:19:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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")}'));
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-13 23:20:05 +01:00
|
|
|
}
|
2026-05-03 22:19:50 +02:00
|
|
|
|
2025-02-13 23:20:05 +01:00
|
|
|
function mymodifierfcc($a, $b, $c)
|
|
|
|
|
{
|
|
|
|
|
return "$a function $b $c";
|
|
|
|
|
}
|