summaryrefslogtreecommitdiff
path: root/tests/UnitTests/Compile/FunctionCallCompilerTest.php
blob: 2eb0e5a1a2ad1a9e4c1a1a161a70987b2fdbaf4a (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
52
53
54
55
56
57
58
59
60
61
62
<?php

use Smarty\Compile\FunctionCallCompiler;
use Smarty\Compiler\Template;
use Smarty\FunctionHandler\AttributeFunctionHandlerInterface;
use Smarty\Smarty;

class FunctionCallCompilerTest extends PHPUnit\Framework\TestCase
{
	/**
	 * @inheritDoc
	 * Set up attribute compiler class
	 */
	protected function setUp(): void
	{
		$this->smarty = $this->createMock(Smarty::class);
		$this->template_compiler = $this->createMock(Template::class);
		$this->template_compiler
			->expects(self::once())
			->method('getSmarty')
			->willReturn($this->smarty);
	}

	public function testAttributeFunctionHandlerInterface(): void
	{
		$attribute_function_handler = $this->createMock(AttributeFunctionHandlerInterface::class);

		$attribute_function_handler
			->expects(self::once())
			->method('getSupportedAttributes')
			->willReturn([
				'required_attributes' => ['required'],
				'optional_attributes' => ['optional'],
				'shorttag_order' => ['short'],
				'option_flags' => ['option'],
			]);

		$args = [
			0 => 'short',
			1 => 'option',
			2 => [
				'optional' => 'optional',
			],
			3 => [
				'required' => 'required',
			],
		];

		$this->smarty
			->expects(self::once())
			->method('getFunctionHandler')
			->with('method')
			->willReturn($attribute_function_handler);

		$function_call_compiler = new FunctionCallCompiler();

		$this->assertEquals(
			$function_call_compiler->compile($args, $this->template_compiler, [], null, 'method'),
			'$_smarty_tpl->getSmarty()->getFunctionHandler(\'method\')->handle(array(\'short\'=>short,\'option\'=>1,\'optional\'=>optional,\'required\'=>required), $_smarty_tpl)'
		);
	}
}