4 * This file is part of Twig.
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 class Twig_Tests_Node_MacroTest extends Twig_Test_NodeTestCase
14 public function testConstructor()
16 $body = new Twig_Node_Text('foo', 1);
17 $arguments = new Twig_Node(array(new Twig_Node_Expression_Name('foo', 1)), array(), 1);
18 $node = new Twig_Node_Macro('foo', $body, $arguments, 1);
20 $this->assertEquals($body, $node->getNode('body'));
21 $this->assertEquals($arguments, $node->getNode('arguments'));
22 $this->assertEquals('foo', $node->getAttribute('name'));
25 public function getTests()
27 $body = new Twig_Node_Text('foo', 1);
28 $arguments = new Twig_Node(array(
29 'foo' => new Twig_Node_Expression_Constant(null, 1),
30 'bar' => new Twig_Node_Expression_Constant('Foo', 1),
32 $node = new Twig_Node_Macro('foo', $body, $arguments, 1);
34 if (PHP_VERSION_ID >= 50600) {
35 $declaration = ', ...$__varargs__';
36 $varargs = '$__varargs__';
39 $varargs = 'func_num_args() > 2 ? array_slice(func_get_args(), 2) : array()';
45 public function getfoo(\$__foo__ = null, \$__bar__ = "Foo"$declaration)
47 \$context = \$this->env->mergeGlobals(array(
50 "varargs" => $varargs,
58 } catch (Exception \$e) {
62 } catch (Throwable \$e) {
68 return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());