ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
MacroTest.php
Go to the documentation of this file.
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
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
45public 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}
70EOF
71 ),
72 );
73 }
74}
const EOF
How fgetc() reports an End Of File.
Definition: JSMin_lib.php:92
An exception for terminatinating execution or to throw for unit testing.
Marks a content as safe.
Definition: Markup.php:18
Represents a macro node.
Definition: Macro.php:18
Represents a text node.
Definition: Text.php:19
Represents a node in the AST.
Definition: Node.php:19