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_ModuleTest extends Twig_Test_NodeTestCase
14 public function testConstructor()
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);
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());
31 public function getTests()
33 $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
37 $body = new Twig_Node_Text('foo', 1);
39 $blocks = new Twig_Node();
40 $macros = new Twig_Node();
41 $traits = new Twig_Node();
42 $source = new Twig_Source('{{ foo }}', 'foo.twig');
44 $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $source);
45 $tests[] = array($node, <<<EOF
49 class __TwigTemplate_%x extends Twig_Template
51 public function __construct(Twig_Environment \$env)
53 parent::__construct(\$env);
55 \$this->parent = false;
57 \$this->blocks = array(
61 protected function doDisplay(array \$context, array \$blocks = array())
67 public function getTemplateName()
72 public function getDebugInfo()
74 return array ( 19 => 1,);
77 /** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */
78 public function getSource()
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);
82 return \$this->getSourceContext()->getCode();
85 public function getSourceContext()
87 return new Twig_Source("", "foo.twig", "");
93 $import = new Twig_Node_Import(new Twig_Node_Expression_Constant('foo.twig', 1), new Twig_Node_Expression_AssignName('macro', 1), 2);
95 $body = new Twig_Node(array($import));
96 $extends = new Twig_Node_Expression_Constant('layout.twig', 1);
98 $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $source);
99 $tests[] = array($node, <<<EOF
103 class __TwigTemplate_%x extends Twig_Template
105 public function __construct(Twig_Environment \$env)
107 parent::__construct(\$env);
110 \$this->parent = \$this->loadTemplate("layout.twig", "foo.twig", 1);
111 \$this->blocks = array(
115 protected function doGetParent(array \$context)
117 return "layout.twig";
120 protected function doDisplay(array \$context, array \$blocks = array())
123 \$context["macro"] = \$this->loadTemplate("foo.twig", "foo.twig", 2);
125 \$this->parent->display(\$context, array_merge(\$this->blocks, \$blocks));
128 public function getTemplateName()
133 public function isTraitable()
138 public function getDebugInfo()
140 return array ( 26 => 1, 24 => 2, 11 => 1,);
143 /** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */
144 public function getSource()
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);
148 return \$this->getSourceContext()->getCode();
151 public function getSourceContext()
153 return new Twig_Source("", "foo.twig", "");
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),
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
174 class __TwigTemplate_%x extends Twig_Template
176 protected function doGetParent(array \$context)
179 return \$this->loadTemplate(((true) ? ("foo") : ("foo")), "foo.twig", 2);
182 protected function doDisplay(array \$context, array \$blocks = array())
185 \$context["foo"] = "foo";
187 \$this->getParent(\$context)->display(\$context, array_merge(\$this->blocks, \$blocks));
190 public function getTemplateName()
195 public function isTraitable()
200 public function getDebugInfo()
202 return array ( 17 => 2, 15 => 4, 9 => 2,);
205 /** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */
206 public function getSource()
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);
210 return \$this->getSourceContext()->getCode();
213 public function getSourceContext()
215 return new Twig_Source("{{ foo }}", "foo.twig", "");