Skip to content
This repository
Newer
Older
100644 197 lines (163 sloc) 5.394 kb
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
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
36372c61 »
2012-09-17 Made node tests reusable
12 class Twig_Tests_Node_ModuleTest extends Twig_Test_NodeTestCase
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
13 {
14 /**
15 * @covers Twig_Node_Module::__construct
16 */
17 public function testConstructor()
18 {
3031fe6b »
2012-10-19 changed Node instances line numbers from 0 to 1 in unit tests to bett…
19 $body = new Twig_Node_Text('foo', 1);
20 $parent = new Twig_Node_Expression_Constant('layout.twig', 1);
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
21 $blocks = new Twig_Node();
22 $macros = new Twig_Node();
221eb48e »
2011-04-13 added support for traits (experimental)
23 $traits = new Twig_Node();
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
24 $filename = 'foo.twig';
2fa8224b »
2012-04-23 added the inline tag
25 $node = new Twig_Node_Module($body, $parent, $blocks, $macros, $traits, new Twig_Node(array()), $filename);
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
26
29b020eb »
2010-10-02 changed the way to access nodes and attributes from a node
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'));
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
32 }
33
34 /**
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
44 */
45 public function testCompile($node, $source, $environment = null)
46 {
47 parent::testCompile($node, $source, $environment);
48 }
49
50 public function getTests()
51 {
52 $twig = new Twig_Environment(new Twig_Loader_String());
53
54 $tests = array();
55
3031fe6b »
2012-10-19 changed Node instances line numbers from 0 to 1 in unit tests to bett…
56 $body = new Twig_Node_Text('foo', 1);
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
57 $extends = null;
58 $blocks = new Twig_Node();
59 $macros = new Twig_Node();
221eb48e »
2011-04-13 added support for traits (experimental)
60 $traits = new Twig_Node();
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
61 $filename = 'foo.twig';
62
2fa8224b »
2012-04-23 added the inline tag
63 $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $filename);
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
64 $tests[] = array($node, <<<EOF
65 <?php
66
67 /* foo.twig */
9a01db60 »
2013-08-04 replaced usage of md5/sha1 by sha256
68 class __TwigTemplate_a2bfbf7dd6ab85666684fe9297f69363a3fc2046d90f22a317d380c18638df0d extends Twig_Template
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
69 {
3398b38c »
2012-04-03 fixed a regression when a template only extends another one without d…
70 public function __construct(Twig_Environment \$env)
71 {
72 parent::__construct(\$env);
73
74 \$this->parent = false;
75
76 \$this->blocks = array(
77 );
78 }
79
f93a8571 »
2011-02-02 added possibility to customize "display" in the base template class
80 protected function doDisplay(array \$context, array \$blocks = array())
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
81 {
3031fe6b »
2012-10-19 changed Node instances line numbers from 0 to 1 in unit tests to bett…
82 // line 1
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
83 echo "foo";
84 }
85
c66ab823 »
2010-11-27 made error message for strict variables more useful
86 public function getTemplateName()
87 {
88 return "foo.twig";
89 }
221eb48e »
2011-04-13 added support for traits (experimental)
90
49ee8d6e »
2012-03-17 made the strategy used to guess the real template file name and line …
91 public function getDebugInfo()
92 {
74586e9f »
2013-10-02 Revert "merged branch hason/macros (PR #1139)"
93 return array ( 19 => 1,);
49ee8d6e »
2012-03-17 made the strategy used to guess the real template file name and line …
94 }
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
95 }
96 EOF
97 , $twig);
98
3031fe6b »
2012-10-19 changed Node instances line numbers from 0 to 1 in unit tests to bett…
99 $import = new Twig_Node_Import(new Twig_Node_Expression_Constant('foo.twig', 1), new Twig_Node_Expression_AssignName('macro', 1), 1);
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
100
7f5390a6 »
2011-07-26 fixed compilation of templates when the body of a child template is n…
101 $body = new Twig_Node(array($import));
3031fe6b »
2012-10-19 changed Node instances line numbers from 0 to 1 in unit tests to bett…
102 $extends = new Twig_Node_Expression_Constant('layout.twig', 1);
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
103
2fa8224b »
2012-04-23 added the inline tag
104 $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $filename);
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
105 $tests[] = array($node, <<<EOF
106 <?php
107
108 /* foo.twig */
9a01db60 »
2013-08-04 replaced usage of md5/sha1 by sha256
109 class __TwigTemplate_a2bfbf7dd6ab85666684fe9297f69363a3fc2046d90f22a317d380c18638df0d extends Twig_Template
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
110 {
3398b38c »
2012-04-03 fixed a regression when a template only extends another one without d…
111 public function __construct(Twig_Environment \$env)
112 {
113 parent::__construct(\$env);
114
115 \$this->parent = \$this->env->loadTemplate("layout.twig");
116
117 \$this->blocks = array(
118 );
119 }
120
c201137f »
2011-08-06 moved Template::getParent() logic to the base class
121 protected function doGetParent(array \$context)
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
122 {
c201137f »
2011-08-06 moved Template::getParent() logic to the base class
123 return "layout.twig";
15f32766 »
2010-10-01 changed the implementation of template inheritance
124 }
125
f93a8571 »
2011-02-02 added possibility to customize "display" in the base template class
126 protected function doDisplay(array \$context, array \$blocks = array())
15f32766 »
2010-10-01 changed the implementation of template inheritance
127 {
3031fe6b »
2012-10-19 changed Node instances line numbers from 0 to 1 in unit tests to bett…
128 // line 1
e0cd7661 »
2011-09-30 fixed hardcoded name escaping
129 \$context["macro"] = \$this->env->loadTemplate("foo.twig");
1e9a1ae0 »
2012-03-30 optimized parent template creation when the template does not use dyn…
130 \$this->parent->display(\$context, array_merge(\$this->blocks, \$blocks));
0f51a54f »
2010-06-09 added support for dynamic and conditional inheritance ({% extends som…
131 }
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
132
c66ab823 »
2010-11-27 made error message for strict variables more useful
133 public function getTemplateName()
134 {
135 return "foo.twig";
136 }
221eb48e »
2011-04-13 added support for traits (experimental)
137
138 public function isTraitable()
139 {
140 return false;
141 }
49ee8d6e »
2012-03-17 made the strategy used to guess the real template file name and line …
142
143 public function getDebugInfo()
144 {
74586e9f »
2013-10-02 Revert "merged branch hason/macros (PR #1139)"
145 return array ( 24 => 1,);
49ee8d6e »
2012-03-17 made the strategy used to guess the real template file name and line …
146 }
0f51a54f »
2010-06-09 added support for dynamic and conditional inheritance ({% extends som…
147 }
148 EOF
149 , $twig);
150
7f5390a6 »
2011-07-26 fixed compilation of templates when the body of a child template is n…
151 $body = new Twig_Node();
0f51a54f »
2010-06-09 added support for dynamic and conditional inheritance ({% extends som…
152 $extends = new Twig_Node_Expression_Conditional(
3031fe6b »
2012-10-19 changed Node instances line numbers from 0 to 1 in unit tests to bett…
153 new Twig_Node_Expression_Constant(true, 1),
154 new Twig_Node_Expression_Constant('foo', 1),
155 new Twig_Node_Expression_Constant('foo', 1),
0f51a54f »
2010-06-09 added support for dynamic and conditional inheritance ({% extends som…
156 0
157 );
158
2fa8224b »
2012-04-23 added the inline tag
159 $node = new Twig_Node_Module($body, $extends, $blocks, $macros, $traits, new Twig_Node(array()), $filename);
0f51a54f »
2010-06-09 added support for dynamic and conditional inheritance ({% extends som…
160 $tests[] = array($node, <<<EOF
161 <?php
162
163 /* foo.twig */
9a01db60 »
2013-08-04 replaced usage of md5/sha1 by sha256
164 class __TwigTemplate_a2bfbf7dd6ab85666684fe9297f69363a3fc2046d90f22a317d380c18638df0d extends Twig_Template
0f51a54f »
2010-06-09 added support for dynamic and conditional inheritance ({% extends som…
165 {
c201137f »
2011-08-06 moved Template::getParent() logic to the base class
166 protected function doGetParent(array \$context)
0f51a54f »
2010-06-09 added support for dynamic and conditional inheritance ({% extends som…
167 {
4402ee2c »
2011-08-27 added support for an array of templates to the "extends" tag
168 return \$this->env->resolveTemplate(((true) ? ("foo") : ("foo")));
15f32766 »
2010-10-01 changed the implementation of template inheritance
169 }
170
f93a8571 »
2011-02-02 added possibility to customize "display" in the base template class
171 protected function doDisplay(array \$context, array \$blocks = array())
15f32766 »
2010-10-01 changed the implementation of template inheritance
172 {
173 \$this->getParent(\$context)->display(\$context, array_merge(\$this->blocks, \$blocks));
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
174 }
175
c66ab823 »
2010-11-27 made error message for strict variables more useful
176 public function getTemplateName()
177 {
178 return "foo.twig";
179 }
221eb48e »
2011-04-13 added support for traits (experimental)
180
181 public function isTraitable()
182 {
183 return false;
184 }
49ee8d6e »
2012-03-17 made the strategy used to guess the real template file name and line …
185
186 public function getDebugInfo()
187 {
188 return array ();
189 }
56318ee4 »
2010-06-01 made a big refactoring of Twig internals (and added a bunch of unit t…
190 }
191 EOF
192 , $twig);
193
194 return $tests;
195 }
196 }
Something went wrong with that request. Please try again.