ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ModuleTest.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  $parent = new Twig_Node_Expression_Constant('layout.twig', 1);
18  $blocks = new Twig_Node();
19  $macros = new Twig_Node();
20  $traits = new Twig_Node();
21  $source = new Twig_Source('{{ foo }}', 'foo.twig');
22  $node = new Twig_Node_Module($body, $parent, $blocks, $macros, $traits, new Twig_Node(array()), $source);
23 
24  $this->assertEquals($body, $node->getNode('body'));
25  $this->assertEquals($blocks, $node->getNode('blocks'));
26  $this->assertEquals($macros, $node->getNode('macros'));
27  $this->assertEquals($parent, $node->getNode('parent'));
28  $this->assertEquals($source->getName(), $node->getTemplateName());
29  }
30 
31  public function getTests()
32  {
33  $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
34 
35  $tests = array();
36 
37  $body = new Twig_Node_Text('foo', 1);
38  $extends = null;
39  $blocks = new Twig_Node();
40  $macros = new Twig_Node();
41  $traits = new Twig_Node();
42  $source = new Twig_Source('{{ foo }}', 'foo.twig');
43 
44  $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $source);
45  $tests[] = array($node, <<<EOF
46 <?php
47 
48 /* foo.twig */
49 class __TwigTemplate_%x extends Twig_Template
50 {
51  public function __construct(Twig_Environment \$env)
52  {
53  parent::__construct(\$env);
54 
55  \$this->parent = false;
56 
57  \$this->blocks = array(
58  );
59  }
60 
61  protected function doDisplay(array \$context, array \$blocks = array())
62  {
63  // line 1
64  echo "foo";
65  }
66 
67  public function getTemplateName()
68  {
69  return "foo.twig";
70  }
71 
72  public function getDebugInfo()
73  {
74  return array ( 19 => 1,);
75  }
76 
78  public function getSource()
79  {
80  @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED);
81 
82  return \$this->getSourceContext()->getCode();
83  }
84 
85  public function getSourceContext()
86  {
87  return new Twig_Source("", "foo.twig", "");
88  }
89 }
90 EOF
91  , $twig, true);
92 
93  $import = new Twig_Node_Import(new Twig_Node_Expression_Constant('foo.twig', 1), new Twig_Node_Expression_AssignName('macro', 1), 2);
94 
95  $body = new Twig_Node(array($import));
96  $extends = new Twig_Node_Expression_Constant('layout.twig', 1);
97 
98  $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $source);
99  $tests[] = array($node, <<<EOF
100 <?php
101 
102 /* foo.twig */
103 class __TwigTemplate_%x extends Twig_Template
104 {
105  public function __construct(Twig_Environment \$env)
106  {
107  parent::__construct(\$env);
108 
109  // line 1
110  \$this->parent = \$this->loadTemplate("layout.twig", "foo.twig", 1);
111  \$this->blocks = array(
112  );
113  }
114 
115  protected function doGetParent(array \$context)
116  {
117  return "layout.twig";
118  }
119 
120  protected function doDisplay(array \$context, array \$blocks = array())
121  {
122  // line 2
123  \$context["macro"] = \$this->loadTemplate("foo.twig", "foo.twig", 2);
124  // line 1
125  \$this->parent->display(\$context, array_merge(\$this->blocks, \$blocks));
126  }
127 
128  public function getTemplateName()
129  {
130  return "foo.twig";
131  }
132 
133  public function isTraitable()
134  {
135  return false;
136  }
137 
138  public function getDebugInfo()
139  {
140  return array ( 26 => 1, 24 => 2, 11 => 1,);
141  }
142 
144  public function getSource()
145  {
146  @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED);
147 
148  return \$this->getSourceContext()->getCode();
149  }
150 
151  public function getSourceContext()
152  {
153  return new Twig_Source("", "foo.twig", "");
154  }
155 }
156 EOF
157  , $twig, true);
158 
159  $set = new Twig_Node_Set(false, new Twig_Node(array(new Twig_Node_Expression_AssignName('foo', 4))), new Twig_Node(array(new Twig_Node_Expression_Constant('foo', 4))), 4);
160  $body = new Twig_Node(array($set));
161  $extends = new Twig_Node_Expression_Conditional(
162  new Twig_Node_Expression_Constant(true, 2),
163  new Twig_Node_Expression_Constant('foo', 2),
164  new Twig_Node_Expression_Constant('foo', 2),
165  2
166  );
167 
168  $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('debug' => true));
169  $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $source);
170  $tests[] = array($node, <<<EOF
171 <?php
172 
173 /* foo.twig */
174 class __TwigTemplate_%x extends Twig_Template
175 {
176  protected function doGetParent(array \$context)
177  {
178  // line 2
179  return \$this->loadTemplate(((true) ? ("foo") : ("foo")), "foo.twig", 2);
180  }
181 
182  protected function doDisplay(array \$context, array \$blocks = array())
183  {
184  // line 4
185  \$context["foo"] = "foo";
186  // line 2
187  \$this->getParent(\$context)->display(\$context, array_merge(\$this->blocks, \$blocks));
188  }
189 
190  public function getTemplateName()
191  {
192  return "foo.twig";
193  }
194 
195  public function isTraitable()
196  {
197  return false;
198  }
199 
200  public function getDebugInfo()
201  {
202  return array ( 17 => 2, 15 => 4, 9 => 2,);
203  }
204 
206  public function getSource()
207  {
208  @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED);
209 
210  return \$this->getSourceContext()->getCode();
211  }
212 
213  public function getSourceContext()
214  {
215  return new Twig_Source("{{ foo }}", "foo.twig", "");
216  }
217 }
218 EOF
219  , $twig, true);
220 
221  return $tests;
222  }
223 }
loadTemplate($template, $templateName=null, $line=null, $index=null)
Definition: Template.php:351
Represents a node in the AST.
Definition: Node.php:18
Represents a set node.
Definition: Set.php:17
$env
Represents a module node.
Definition: Module.php:22
Create styles array
The data for the language used.
Default base class for compiled templates.
Definition: Template.php:24
Represents an import node.
Definition: Import.php:17
Represents a text node.
Definition: Text.php:18
Holds information about a non-compiled Twig template.
Definition: Source.php:19
$source
Definition: linkback.php:22
Stores the Twig configuration.
Definition: Environment.php:17
const EOF
How fgetc() reports an End Of File.
Definition: JSMin_lib.php:92