diff options
author | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-04 17:50:34 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas.loeuillet@gmail.com> | 2013-08-04 17:50:34 +0200 |
commit | 46b77928f746a4231d064774b5b67fd892c7ce86 (patch) | |
tree | e3ea690b3f0def1744ddae758923cf92171ef985 /vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node | |
parent | 68abd9c71b1d2f7bb2e9d21819584d1d15005b25 (diff) | |
download | wallabag-46b77928f746a4231d064774b5b67fd892c7ce86.tar.gz wallabag-46b77928f746a4231d064774b5b67fd892c7ce86.tar.zst wallabag-46b77928f746a4231d064774b5b67fd892c7ce86.zip |
rm vendor
Diffstat (limited to 'vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node')
-rw-r--r-- | vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php | 85 | ||||
-rw-r--r-- | vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php | 282 |
2 files changed, 0 insertions, 367 deletions
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php deleted file mode 100644 index 90afef12..00000000 --- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/FormThemeTest.php +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Bridge\Twig\Tests\Node; | ||
13 | |||
14 | use Symfony\Bridge\Twig\Tests\TestCase; | ||
15 | use Symfony\Bridge\Twig\Node\FormThemeNode; | ||
16 | |||
17 | class FormThemeTest extends TestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | parent::setUp(); | ||
22 | |||
23 | if (version_compare(\Twig_Environment::VERSION, '1.5.0', '<')) { | ||
24 | $this->markTestSkipped('Requires Twig version to be at least 1.5.0.'); | ||
25 | } | ||
26 | } | ||
27 | |||
28 | public function testConstructor() | ||
29 | { | ||
30 | $form = new \Twig_Node_Expression_Name('form', 0); | ||
31 | $resources = new \Twig_Node(array( | ||
32 | new \Twig_Node_Expression_Constant('tpl1', 0), | ||
33 | new \Twig_Node_Expression_Constant('tpl2', 0) | ||
34 | )); | ||
35 | |||
36 | $node = new FormThemeNode($form, $resources, 0); | ||
37 | |||
38 | $this->assertEquals($form, $node->getNode('form')); | ||
39 | $this->assertEquals($resources, $node->getNode('resources')); | ||
40 | } | ||
41 | |||
42 | public function testCompile() | ||
43 | { | ||
44 | $form = new \Twig_Node_Expression_Name('form', 0); | ||
45 | $resources = new \Twig_Node_Expression_Array(array( | ||
46 | new \Twig_Node_Expression_Constant(0, 0), | ||
47 | new \Twig_Node_Expression_Constant('tpl1', 0), | ||
48 | new \Twig_Node_Expression_Constant(1, 0), | ||
49 | new \Twig_Node_Expression_Constant('tpl2', 0) | ||
50 | ), 0); | ||
51 | |||
52 | $node = new FormThemeNode($form, $resources, 0); | ||
53 | |||
54 | $compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
55 | |||
56 | $this->assertEquals( | ||
57 | sprintf( | ||
58 | '$this->env->getExtension(\'form\')->renderer->setTheme(%s, array(0 => "tpl1", 1 => "tpl2"));', | ||
59 | $this->getVariableGetter('form') | ||
60 | ), | ||
61 | trim($compiler->compile($node)->getSource()) | ||
62 | ); | ||
63 | |||
64 | $resources = new \Twig_Node_Expression_Constant('tpl1', 0); | ||
65 | |||
66 | $node = new FormThemeNode($form, $resources, 0); | ||
67 | |||
68 | $this->assertEquals( | ||
69 | sprintf( | ||
70 | '$this->env->getExtension(\'form\')->renderer->setTheme(%s, "tpl1");', | ||
71 | $this->getVariableGetter('form') | ||
72 | ), | ||
73 | trim($compiler->compile($node)->getSource()) | ||
74 | ); | ||
75 | } | ||
76 | |||
77 | protected function getVariableGetter($name) | ||
78 | { | ||
79 | if (version_compare(phpversion(), '5.4.0RC1', '>=')) { | ||
80 | return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name); | ||
81 | } | ||
82 | |||
83 | return sprintf('$this->getContext($context, "%s")', $name); | ||
84 | } | ||
85 | } | ||
diff --git a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php b/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php deleted file mode 100644 index c1f247ca..00000000 --- a/vendor/symfony/twig-bridge/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php +++ /dev/null | |||
@@ -1,282 +0,0 @@ | |||
1 | <?php | ||
2 | |||
3 | /* | ||
4 | * This file is part of the Symfony package. | ||
5 | * | ||
6 | * (c) Fabien Potencier <fabien@symfony.com> | ||
7 | * | ||
8 | * For the full copyright and license information, please view the LICENSE | ||
9 | * file that was distributed with this source code. | ||
10 | */ | ||
11 | |||
12 | namespace Symfony\Bridge\Twig\Tests\Node; | ||
13 | |||
14 | use Symfony\Bridge\Twig\Tests\TestCase; | ||
15 | use Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode; | ||
16 | |||
17 | class SearchAndRenderBlockNodeTest extends TestCase | ||
18 | { | ||
19 | protected function setUp() | ||
20 | { | ||
21 | parent::setUp(); | ||
22 | |||
23 | if (version_compare(\Twig_Environment::VERSION, '1.5.0', '<')) { | ||
24 | $this->markTestSkipped('Requires Twig version to be at least 1.5.0.'); | ||
25 | } | ||
26 | } | ||
27 | |||
28 | public function testCompileWidget() | ||
29 | { | ||
30 | $arguments = new \Twig_Node(array( | ||
31 | new \Twig_Node_Expression_Name('form', 0), | ||
32 | )); | ||
33 | |||
34 | $node = new SearchAndRenderBlockNode('form_widget', $arguments, 0); | ||
35 | |||
36 | $compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
37 | |||
38 | $this->assertEquals( | ||
39 | sprintf( | ||
40 | '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'widget\')', | ||
41 | $this->getVariableGetter('form') | ||
42 | ), | ||
43 | trim($compiler->compile($node)->getSource()) | ||
44 | ); | ||
45 | } | ||
46 | |||
47 | public function testCompileWidgetWithVariables() | ||
48 | { | ||
49 | $arguments = new \Twig_Node(array( | ||
50 | new \Twig_Node_Expression_Name('form', 0), | ||
51 | new \Twig_Node_Expression_Array(array( | ||
52 | new \Twig_Node_Expression_Constant('foo', 0), | ||
53 | new \Twig_Node_Expression_Constant('bar', 0), | ||
54 | ), 0), | ||
55 | )); | ||
56 | |||
57 | $node = new SearchAndRenderBlockNode('form_widget', $arguments, 0); | ||
58 | |||
59 | $compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
60 | |||
61 | $this->assertEquals( | ||
62 | sprintf( | ||
63 | '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'widget\', array("foo" => "bar"))', | ||
64 | $this->getVariableGetter('form') | ||
65 | ), | ||
66 | trim($compiler->compile($node)->getSource()) | ||
67 | ); | ||
68 | } | ||
69 | |||
70 | public function testCompileLabelWithLabel() | ||
71 | { | ||
72 | $arguments = new \Twig_Node(array( | ||
73 | new \Twig_Node_Expression_Name('form', 0), | ||
74 | new \Twig_Node_Expression_Constant('my label', 0), | ||
75 | )); | ||
76 | |||
77 | $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); | ||
78 | |||
79 | $compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
80 | |||
81 | $this->assertEquals( | ||
82 | sprintf( | ||
83 | '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("label" => "my label"))', | ||
84 | $this->getVariableGetter('form') | ||
85 | ), | ||
86 | trim($compiler->compile($node)->getSource()) | ||
87 | ); | ||
88 | } | ||
89 | |||
90 | public function testCompileLabelWithNullLabel() | ||
91 | { | ||
92 | $arguments = new \Twig_Node(array( | ||
93 | new \Twig_Node_Expression_Name('form', 0), | ||
94 | new \Twig_Node_Expression_Constant(null, 0), | ||
95 | )); | ||
96 | |||
97 | $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); | ||
98 | |||
99 | $compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
100 | |||
101 | // "label" => null must not be included in the output! | ||
102 | // Otherwise the default label is overwritten with null. | ||
103 | $this->assertEquals( | ||
104 | sprintf( | ||
105 | '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\')', | ||
106 | $this->getVariableGetter('form') | ||
107 | ), | ||
108 | trim($compiler->compile($node)->getSource()) | ||
109 | ); | ||
110 | } | ||
111 | |||
112 | public function testCompileLabelWithEmptyStringLabel() | ||
113 | { | ||
114 | $arguments = new \Twig_Node(array( | ||
115 | new \Twig_Node_Expression_Name('form', 0), | ||
116 | new \Twig_Node_Expression_Constant('', 0), | ||
117 | )); | ||
118 | |||
119 | $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); | ||
120 | |||
121 | $compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
122 | |||
123 | // "label" => null must not be included in the output! | ||
124 | // Otherwise the default label is overwritten with null. | ||
125 | $this->assertEquals( | ||
126 | sprintf( | ||
127 | '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\')', | ||
128 | $this->getVariableGetter('form') | ||
129 | ), | ||
130 | trim($compiler->compile($node)->getSource()) | ||
131 | ); | ||
132 | } | ||
133 | |||
134 | public function testCompileLabelWithDefaultLabel() | ||
135 | { | ||
136 | $arguments = new \Twig_Node(array( | ||
137 | new \Twig_Node_Expression_Name('form', 0), | ||
138 | )); | ||
139 | |||
140 | $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); | ||
141 | |||
142 | $compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
143 | |||
144 | $this->assertEquals( | ||
145 | sprintf( | ||
146 | '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\')', | ||
147 | $this->getVariableGetter('form') | ||
148 | ), | ||
149 | trim($compiler->compile($node)->getSource()) | ||
150 | ); | ||
151 | } | ||
152 | |||
153 | public function testCompileLabelWithAttributes() | ||
154 | { | ||
155 | $arguments = new \Twig_Node(array( | ||
156 | new \Twig_Node_Expression_Name('form', 0), | ||
157 | new \Twig_Node_Expression_Constant(null, 0), | ||
158 | new \Twig_Node_Expression_Array(array( | ||
159 | new \Twig_Node_Expression_Constant('foo', 0), | ||
160 | new \Twig_Node_Expression_Constant('bar', 0), | ||
161 | ), 0), | ||
162 | )); | ||
163 | |||
164 | $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); | ||
165 | |||
166 | $compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
167 | |||
168 | // "label" => null must not be included in the output! | ||
169 | // Otherwise the default label is overwritten with null. | ||
170 | // https://github.com/symfony/symfony/issues/5029 | ||
171 | $this->assertEquals( | ||
172 | sprintf( | ||
173 | '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("foo" => "bar"))', | ||
174 | $this->getVariableGetter('form') | ||
175 | ), | ||
176 | trim($compiler->compile($node)->getSource()) | ||
177 | ); | ||
178 | } | ||
179 | |||
180 | public function testCompileLabelWithLabelAndAttributes() | ||
181 | { | ||
182 | $arguments = new \Twig_Node(array( | ||
183 | new \Twig_Node_Expression_Name('form', 0), | ||
184 | new \Twig_Node_Expression_Constant('value in argument', 0), | ||
185 | new \Twig_Node_Expression_Array(array( | ||
186 | new \Twig_Node_Expression_Constant('foo', 0), | ||
187 | new \Twig_Node_Expression_Constant('bar', 0), | ||
188 | new \Twig_Node_Expression_Constant('label', 0), | ||
189 | new \Twig_Node_Expression_Constant('value in attributes', 0), | ||
190 | ), 0), | ||
191 | )); | ||
192 | |||
193 | $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); | ||
194 | |||
195 | $compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
196 | |||
197 | $this->assertEquals( | ||
198 | sprintf( | ||
199 | '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("foo" => "bar", "label" => "value in argument"))', | ||
200 | $this->getVariableGetter('form') | ||
201 | ), | ||
202 | trim($compiler->compile($node)->getSource()) | ||
203 | ); | ||
204 | } | ||
205 | |||
206 | public function testCompileLabelWithLabelThatEvaluatesToNull() | ||
207 | { | ||
208 | $arguments = new \Twig_Node(array( | ||
209 | new \Twig_Node_Expression_Name('form', 0), | ||
210 | new \Twig_Node_Expression_Conditional( | ||
211 | // if | ||
212 | new \Twig_Node_Expression_Constant(true, 0), | ||
213 | // then | ||
214 | new \Twig_Node_Expression_Constant(null, 0), | ||
215 | // else | ||
216 | new \Twig_Node_Expression_Constant(null, 0), | ||
217 | 0 | ||
218 | ), | ||
219 | )); | ||
220 | |||
221 | $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); | ||
222 | |||
223 | $compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
224 | |||
225 | // "label" => null must not be included in the output! | ||
226 | // Otherwise the default label is overwritten with null. | ||
227 | // https://github.com/symfony/symfony/issues/5029 | ||
228 | $this->assertEquals( | ||
229 | sprintf( | ||
230 | '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? array() : array("label" => $_label_)))', | ||
231 | $this->getVariableGetter('form') | ||
232 | ), | ||
233 | trim($compiler->compile($node)->getSource()) | ||
234 | ); | ||
235 | } | ||
236 | |||
237 | public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes() | ||
238 | { | ||
239 | $arguments = new \Twig_Node(array( | ||
240 | new \Twig_Node_Expression_Name('form', 0), | ||
241 | new \Twig_Node_Expression_Conditional( | ||
242 | // if | ||
243 | new \Twig_Node_Expression_Constant(true, 0), | ||
244 | // then | ||
245 | new \Twig_Node_Expression_Constant(null, 0), | ||
246 | // else | ||
247 | new \Twig_Node_Expression_Constant(null, 0), | ||
248 | 0 | ||
249 | ), | ||
250 | new \Twig_Node_Expression_Array(array( | ||
251 | new \Twig_Node_Expression_Constant('foo', 0), | ||
252 | new \Twig_Node_Expression_Constant('bar', 0), | ||
253 | new \Twig_Node_Expression_Constant('label', 0), | ||
254 | new \Twig_Node_Expression_Constant('value in attributes', 0), | ||
255 | ), 0), | ||
256 | )); | ||
257 | |||
258 | $node = new SearchAndRenderBlockNode('form_label', $arguments, 0); | ||
259 | |||
260 | $compiler = new \Twig_Compiler(new \Twig_Environment()); | ||
261 | |||
262 | // "label" => null must not be included in the output! | ||
263 | // Otherwise the default label is overwritten with null. | ||
264 | // https://github.com/symfony/symfony/issues/5029 | ||
265 | $this->assertEquals( | ||
266 | sprintf( | ||
267 | '$this->env->getExtension(\'form\')->renderer->searchAndRenderBlock(%s, \'label\', array("foo" => "bar", "label" => "value in attributes") + (twig_test_empty($_label_ = ((true) ? (null) : (null))) ? array() : array("label" => $_label_)))', | ||
268 | $this->getVariableGetter('form') | ||
269 | ), | ||
270 | trim($compiler->compile($node)->getSource()) | ||
271 | ); | ||
272 | } | ||
273 | |||
274 | protected function getVariableGetter($name) | ||
275 | { | ||
276 | if (version_compare(phpversion(), '5.4.0RC1', '>=')) { | ||
277 | return sprintf('(isset($context["%s"]) ? $context["%s"] : null)', $name, $name); | ||
278 | } | ||
279 | |||
280 | return sprintf('$this->getContext($context, "%s")', $name); | ||
281 | } | ||
282 | } | ||