c7edfa251641d7b52a118af2ebbd179902683ae2
[yaffs-website] / vendor / twig / twig / test / Twig / Tests / Node / MacroTest.php
1 <?php
2
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 class Twig_Tests_Node_MacroTest extends Twig_Test_NodeTestCase
13 {
14     public function testConstructor()
15     {
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);
19
20         $this->assertEquals($body, $node->getNode('body'));
21         $this->assertEquals($arguments, $node->getNode('arguments'));
22         $this->assertEquals('foo', $node->getAttribute('name'));
23     }
24
25     public function getTests()
26     {
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),
31         ), array(), 1);
32         $node = new Twig_Node_Macro('foo', $body, $arguments, 1);
33
34         if (PHP_VERSION_ID >= 50600) {
35             $declaration = ', ...$__varargs__';
36             $varargs = '$__varargs__';
37         } else {
38             $declaration = '';
39             $varargs = 'func_num_args() > 2 ? array_slice(func_get_args(), 2) : array()';
40         }
41
42         return array(
43             array($node, <<<EOF
44 // line 1
45 public function getfoo(\$__foo__ = null, \$__bar__ = "Foo"$declaration)
46 {
47     \$context = \$this->env->mergeGlobals(array(
48         "foo" => \$__foo__,
49         "bar" => \$__bar__,
50         "varargs" => $varargs,
51     ));
52
53     \$blocks = array();
54
55     ob_start();
56     try {
57         echo "foo";
58     } catch (Exception \$e) {
59         ob_end_clean();
60
61         throw \$e;
62     } catch (Throwable \$e) {
63         ob_end_clean();
64
65         throw \$e;
66     }
67
68     return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());
69 }
70 EOF
71             ),
72         );
73     }
74 }