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
15 * @covers Twig_Node_Module::__construct
17 public function testConstructor()
19 $body = new Twig_Node_Text('foo', 1);
20 $parent = new Twig_Node_Expression_Constant('layout.twig', 1);
21 $blocks = new Twig_Node();
22 $macros = new Twig_Node();
23 $traits = new Twig_Node();
24 $filename = 'foo.twig';
25 $node = new Twig_Node_Module($body, $parent, $blocks, $macros, $traits, new Twig_Node(array()), $filename);
27 $this->assertEquals($body, $node->getNode('body'));
28 $this->assertEquals($blocks, $node->getNode('blocks'));
29 $this->assertEquals($macros, $node->getNode('macros'));
30 $this->assertEquals($parent, $node->getNode('parent'));
31 $this->assertEquals($filename, $node->getAttribute('filename'));
35 * @covers Twig_Node_Module::compile
36 * @covers Twig_Node_Module::compileTemplate
37 * @covers Twig_Node_Module::compileMacros
38 * @covers Twig_Node_Module::compileClassHeader
39 * @covers Twig_Node_Module::compileDisplayHeader
40 * @covers Twig_Node_Module::compileDisplayBody
41 * @covers Twig_Node_Module::compileDisplayFooter
42 * @covers Twig_Node_Module::compileClassFooter
43 * @dataProvider getTests
45 public function testCompile($node, $source, $environment = null)
47 parent
::testCompile($node, $source, $environment);
50 public function getTests()
52 $twig = new Twig_Environment(new Twig_Loader_String());
56 $body = new Twig_Node_Text('foo', 1);
58 $blocks = new Twig_Node();
59 $macros = new Twig_Node();
60 $traits = new Twig_Node();
61 $filename = 'foo.twig';
63 $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $filename);
64 $tests[] = array($node, <<<EOF
68 class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
70 public function __construct(Twig_Environment \$env)
72 parent::__construct(\$env);
74 \$this->parent = false;
76 \$this->blocks = array(
80 protected function doDisplay(array \$context, array \$blocks = array())
86 public function getTemplateName()
91 public function getDebugInfo()
93 return array ( 19 => 1,);
99 $import = new Twig_Node_Import(new Twig_Node_Expression_Constant('foo.twig', 1), new Twig_Node_Expression_AssignName('macro', 1), 1);
101 $body = new Twig_Node(array($import));
102 $extends = new Twig_Node_Expression_Constant('layout.twig', 1);
104 $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $filename);
105 $tests[] = array($node, <<<EOF
109 class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
111 public function __construct(Twig_Environment \$env)
113 parent::__construct(\$env);
115 \$this->parent = \$this->env->loadTemplate("layout.twig");
117 \$this->blocks = array(
121 protected function doGetParent(array \$context)
123 return "layout.twig";
126 protected function doDisplay(array \$context, array \$blocks = array())
129 \$context["macro"] = \$this->env->loadTemplate("foo.twig");
130 \$this->parent->display(\$context, array_merge(\$this->blocks, \$blocks));
133 public function getTemplateName()
138 public function isTraitable()
143 public function getDebugInfo()
145 return array ( 24 => 1,);
151 $body = new Twig_Node();
152 $extends = new Twig_Node_Expression_Conditional(
153 new Twig_Node_Expression_Constant(true, 1),
154 new Twig_Node_Expression_Constant('foo', 1),
155 new Twig_Node_Expression_Constant('foo', 1),
159 $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $filename);
160 $tests[] = array($node, <<<EOF
164 class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
166 protected function doGetParent(array \$context)
168 return \$this->env->resolveTemplate(((true) ? ("foo") : ("foo")));
171 protected function doDisplay(array \$context, array \$blocks = array())
173 \$this->getParent(\$context)->display(\$context, array_merge(\$this->blocks, \$blocks));
176 public function getTemplateName()
181 public function isTraitable()
186 public function getDebugInfo()