summaryrefslogtreecommitdiff
path: root/tests/UnitTests/SmartyMethodsTests/RegisterModifier/RegisterModifierFirstClassCallablesTest.php
blob: 50fdb9a00e10802d4a7c3b854095ce0214c3d8b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?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 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";
}