[FEATURE] Support literal strings in boolean arguments
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / Core / Parser / SyntaxTree / BooleanNodeTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\Core\Parser\SyntaxTree;
3
4 /* *
5 * This script is backported from the FLOW3 package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13 /**
14 * Testcase for ViewHelperNode's evaluateBooleanExpression()
15 */
16 class BooleanNodeTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
17
18 /**
19 * @var \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode
20 */
21 protected $viewHelperNode;
22
23 /**
24 * @var \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface
25 */
26 protected $renderingContext;
27
28 /**
29 * Setup fixture
30 */
31 public function setUp() {
32 $this->renderingContext = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContextInterface');
33 }
34
35 /**
36 * @test
37 * @expectedException \TYPO3\CMS\Fluid\Core\Parser\Exception
38 */
39 public function havingMoreThanThreeElementsInTheSyntaxTreeThrowsException() {
40 $rootNode = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\RootNode');
41 $rootNode->expects($this->once())->method('getChildNodes')->will($this->returnValue(array(1, 2, 3, 4)));
42 new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
43 }
44
45 /**
46 * @test
47 */
48 public function comparingEqualNumbersReturnsTrue() {
49 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
50 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('5'));
51 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('=='));
52 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('5'));
53 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
54 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
55 }
56
57 /**
58 * @test
59 */
60 public function comparingUnequalNumbersReturnsFalse() {
61 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
62 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('5'));
63 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('=='));
64 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('3'));
65 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
66 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
67 }
68
69 /**
70 * @test
71 */
72 public function notEqualReturnsFalseIfNumbersAreEqual() {
73 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
74 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('5'));
75 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('!='));
76 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('5'));
77 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
78 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
79 }
80
81 /**
82 * @test
83 */
84 public function notEqualReturnsTrueIfNumbersAreNotEqual() {
85 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
86 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('5'));
87 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('!='));
88 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('3'));
89 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
90 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
91 }
92
93 /**
94 * @test
95 */
96 public function oddNumberModulo2ReturnsTrue() {
97 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
98 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('43'));
99 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('%'));
100 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('2'));
101 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
102 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
103 }
104
105 /**
106 * @test
107 */
108 public function evenNumberModulo2ReturnsFalse() {
109 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
110 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('42'));
111 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('%'));
112 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('2'));
113 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
114 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
115 }
116
117 /**
118 * @test
119 */
120 public function greaterThanReturnsTrueIfNumberIsReallyGreater() {
121 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
122 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
123 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('>'));
124 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('9'));
125 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
126 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
127 }
128
129 /**
130 * @test
131 */
132 public function greaterThanReturnsFalseIfNumberIsEqual() {
133 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
134 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
135 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('>'));
136 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
137 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
138 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
139 }
140
141 /**
142 * @test
143 */
144 public function greaterOrEqualsReturnsTrueIfNumberIsReallyGreater() {
145 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
146 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
147 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('>='));
148 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('9'));
149 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
150 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
151 }
152
153 /**
154 * @test
155 */
156 public function greaterOrEqualsReturnsTrueIfNumberIsEqual() {
157 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
158 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
159 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('>='));
160 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
161 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
162 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
163 }
164
165 /**
166 * @test
167 */
168 public function greaterOrEqualsReturnFalseIfNumberIsSmaller() {
169 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
170 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
171 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('>='));
172 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('11'));
173 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
174 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
175 }
176
177 /**
178 * @test
179 */
180 public function lessThanReturnsTrueIfNumberIsReallyless() {
181 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
182 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('9'));
183 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('<'));
184 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
185 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
186 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
187 }
188
189 /**
190 * @test
191 */
192 public function lessThanReturnsFalseIfNumberIsEqual() {
193 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
194 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
195 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('<'));
196 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
197 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
198 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
199 }
200
201 /**
202 * @test
203 */
204 public function lessOrEqualsReturnsTrueIfNumberIsReallyLess() {
205 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
206 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('9'));
207 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('<='));
208 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
209 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
210 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
211 }
212
213 /**
214 * @test
215 */
216 public function lessOrEqualsReturnsTrueIfNumberIsEqual() {
217 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
218 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
219 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('<='));
220 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
221 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
222 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
223 }
224
225 /**
226 * @test
227 */
228 public function lessOrEqualsReturnFalseIfNumberIsBigger() {
229 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
230 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('11'));
231 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('<='));
232 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
233 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
234 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
235 }
236
237 /**
238 * @test
239 */
240 public function lessOrEqualsReturnFalseIfComparingWithANegativeNumber() {
241 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
242 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('11 <= -2.1'));
243 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
244 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
245 }
246
247 /**
248 * @test
249 */
250 public function notEqualReturnsFalseIfComparingMatchingStrings() {
251 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
252 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' != "stringA"'));
253
254 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
255 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
256 }
257
258 /**
259 * @test
260 */
261 public function notEqualReturnsTrueIfComparingNonMatchingStrings() {
262 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
263 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' != \'stringB\''));
264
265 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
266 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
267 }
268
269 /**
270 * @test
271 */
272 public function equalsReturnsFalseIfComparingNonMatchingStrings() {
273 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
274 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' == \'stringB\''));
275
276 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
277 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
278 }
279
280 /**
281 * @test
282 */
283 public function equalsReturnsTrueIfComparingMatchingStrings() {
284 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
285 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' == "stringA"'));
286
287 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
288 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
289 }
290
291 /**
292 * @test
293 */
294 public function equalsReturnsTrueIfComparingMatchingStringsWithEscapedQuotes() {
295 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
296 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'\\\'stringA\\\'\' == \'\\\'stringA\\\'\''));
297
298 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
299 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
300 }
301
302 /**
303 * @test
304 */
305 public function equalsReturnsFalseIfComparingStringWithNonZero() {
306 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
307 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' == 42'));
308
309 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
310 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
311 }
312
313 /**
314 * @test
315 */
316 public function equalsReturnsTrueIfComparingStringWithZero() {
317 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
318 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' == 0'));
319
320 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
321 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
322 }
323
324 /**
325 * @test
326 */
327 public function objectsAreComparedStrictly() {
328 $object1 = new \stdClass();
329 $object2 = new \stdClass();
330 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
331 $object1Node = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ObjectAccessorNode', array('evaluate'), array('foo'));
332 $object1Node->expects($this->any())->method('evaluate')->will($this->returnValue($object1));
333 $object2Node = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ObjectAccessorNode', array('evaluate'), array('foo'));
334 $object2Node->expects($this->any())->method('evaluate')->will($this->returnValue($object2));
335 $rootNode->addChildNode($object1Node);
336 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('=='));
337 $rootNode->addChildNode($object2Node);
338 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
339 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
340 }
341
342 /**
343 * @test
344 */
345 public function objectsAreComparedStrictlyInUnequalComparison() {
346 $object1 = new \stdClass();
347 $object2 = new \stdClass();
348 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
349 $object1Node = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ObjectAccessorNode', array('evaluate'), array('foo'));
350 $object1Node->expects($this->any())->method('evaluate')->will($this->returnValue($object1));
351 $object2Node = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\ObjectAccessorNode', array('evaluate'), array('foo'));
352 $object2Node->expects($this->any())->method('evaluate')->will($this->returnValue($object2));
353 $rootNode->addChildNode($object1Node);
354 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('!='));
355 $rootNode->addChildNode($object2Node);
356 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
357 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
358 }
359
360 /**
361 * @test
362 */
363 public function convertToBooleanProperlyConvertsValuesOfTypeBoolean() {
364 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(FALSE));
365 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(TRUE));
366 }
367
368 /**
369 * @test
370 */
371 public function convertToBooleanProperlyConvertsValuesOfTypeString() {
372 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(''));
373 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('false'));
374 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('FALSE'));
375 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('true'));
376 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('TRUE'));
377 }
378
379 /**
380 * @test
381 */
382 public function convertToBooleanProperlyConvertsNumericValues() {
383 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(0));
384 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(-1));
385 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('-1'));
386 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(-0.5));
387 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(1));
388 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(0.5));
389 }
390
391 /**
392 * @test
393 */
394 public function convertToBooleanProperlyConvertsValuesOfTypeArray() {
395 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(array()));
396 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(array('foo')));
397 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(array('foo' => 'bar')));
398 }
399
400 /**
401 * @test
402 */
403 public function convertToBooleanProperlyConvertsObjects() {
404 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(NULL));
405 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(new \stdClass()));
406 }
407 }
408
409 ?>