[TASK] PHP7 is_numeric change
[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 TYPO3 Flow 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 /**
15 * Test case
16 */
17 class BooleanNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
18
19 /**
20 * @var \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode
21 */
22 protected $viewHelperNode;
23
24 /**
25 * @var \TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface
26 */
27 protected $renderingContext;
28
29 /**
30 * Setup fixture
31 */
32 protected function setUp() {
33 $this->renderingContext = $this->getMock(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface::class);
34 }
35
36 /**
37 * @test
38 * @expectedException \TYPO3\CMS\Fluid\Core\Parser\Exception
39 */
40 public function havingMoreThanThreeElementsInTheSyntaxTreeThrowsException() {
41 $rootNode = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode::class);
42 $rootNode->expects($this->once())->method('getChildNodes')->will($this->returnValue(array(1, 2, 3, 4)));
43
44 new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
45 }
46
47 /**
48 * @test
49 */
50 public function comparingEqualNumbersReturnsTrue() {
51 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
52 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('5'));
53 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('=='));
54 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('5'));
55
56 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
57 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
58 }
59
60 /**
61 * @test
62 */
63 public function comparingUnequalNumbersReturnsFalse() {
64 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
65 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('5'));
66 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('=='));
67 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('3'));
68
69 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
70 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
71 }
72
73 /**
74 * @test
75 */
76 public function notEqualReturnsFalseIfNumbersAreEqual() {
77 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
78 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('5'));
79 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('!='));
80 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('5'));
81
82 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
83 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
84 }
85
86 /**
87 * @test
88 */
89 public function notEqualReturnsTrueIfNumbersAreNotEqual() {
90 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
91 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('5'));
92 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('!='));
93 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('3'));
94
95 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
96 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
97 }
98
99 /**
100 * @test
101 */
102 public function oddNumberModulo2ReturnsTrue() {
103 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
104 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('43'));
105 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('%'));
106 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('2'));
107
108 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
109 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
110 }
111
112 /**
113 * @test
114 */
115 public function evenNumberModulo2ReturnsFalse() {
116 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
117 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('42'));
118 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('%'));
119 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('2'));
120
121 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
122 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
123 }
124
125 /**
126 * @test
127 */
128 public function greaterThanReturnsTrueIfNumberIsReallyGreater() {
129 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
130 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
131 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('>'));
132 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('9'));
133
134 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
135 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
136 }
137
138 /**
139 * @test
140 */
141 public function greaterThanReturnsFalseIfNumberIsEqual() {
142 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
143 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
144 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('>'));
145 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
146
147 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
148 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
149 }
150
151 /**
152 * @test
153 */
154 public function greaterOrEqualsReturnsTrueIfNumberIsReallyGreater() {
155 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
156 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
157 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('>='));
158 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('9'));
159
160 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
161 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
162 }
163
164 /**
165 * @test
166 */
167 public function greaterOrEqualsReturnsTrueIfNumberIsEqual() {
168 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
169 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
170 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('>='));
171 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
172
173 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
174 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
175 }
176
177 /**
178 * @test
179 */
180 public function greaterOrEqualsReturnFalseIfNumberIsSmaller() {
181 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
182 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
183 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('>='));
184 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('11'));
185
186 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
187 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
188 }
189
190 /**
191 * @test
192 */
193 public function lessThanReturnsTrueIfNumberIsReallyless() {
194 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
195 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('9'));
196 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('<'));
197 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
198
199 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
200 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
201 }
202
203 /**
204 * @test
205 */
206 public function lessThanReturnsFalseIfNumberIsEqual() {
207 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
208 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
209 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('<'));
210 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
211
212 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
213 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
214 }
215
216 /**
217 * @test
218 */
219 public function lessOrEqualsReturnsTrueIfNumberIsReallyLess() {
220 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
221 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('9'));
222 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('<='));
223 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
224
225 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
226 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
227 }
228
229 /**
230 * @test
231 */
232 public function lessOrEqualsReturnsTrueIfNumberIsEqual() {
233 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
234 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
235 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('<='));
236 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
237
238 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
239 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
240 }
241
242 /**
243 * @test
244 */
245 public function lessOrEqualsReturnFalseIfNumberIsBigger() {
246 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
247 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('11'));
248 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('<='));
249 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('10'));
250
251 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
252 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
253 }
254
255 /**
256 * @test
257 */
258 public function lessOrEqualsReturnFalseIfComparingWithANegativeNumber() {
259 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
260 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('11 <= -2.1'));
261 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
262 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
263 }
264
265 /**
266 * @test
267 */
268 public function notEqualReturnsFalseIfComparingMatchingStrings() {
269 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
270 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' != "stringA"'));
271
272 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
273 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
274 }
275
276 /**
277 * @test
278 */
279 public function notEqualReturnsTrueIfComparingNonMatchingStrings() {
280 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
281 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' != \'stringB\''));
282
283 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
284 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
285 }
286
287 /**
288 * @test
289 */
290 public function equalsReturnsFalseIfComparingNonMatchingStrings() {
291 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
292 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' == \'stringB\''));
293
294 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
295 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
296 }
297
298 /**
299 * @test
300 */
301 public function equalsReturnsTrueIfComparingMatchingStrings() {
302 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
303 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' == "stringA"'));
304
305 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
306 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
307 }
308
309 /**
310 * @test
311 */
312 public function equalsReturnsTrueIfComparingMatchingStringsWithEscapedQuotes() {
313 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
314 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'\\\'stringA\\\'\' == \'\\\'stringA\\\'\''));
315
316 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
317 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
318 }
319
320 /**
321 * @test
322 */
323 public function equalsReturnsFalseIfComparingStringWithNonZero() {
324 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
325 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' == 42'));
326
327 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
328 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
329 }
330
331 /**
332 * @test
333 */
334 public function equalsReturnsTrueIfComparingStringWithZero() {
335 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
336 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('\'stringA\' == 0'));
337
338 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
339 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
340 }
341
342 /**
343 * @test
344 */
345 public function objectsAreComparedStrictly() {
346 $object1 = new \stdClass();
347 $object2 = new \stdClass();
348
349 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
350
351 $object1Node = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ObjectAccessorNode::class, array('evaluate'), array('foo'));
352 $object1Node->expects($this->any())->method('evaluate')->will($this->returnValue($object1));
353
354 $object2Node = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ObjectAccessorNode::class, array('evaluate'), array('foo'));
355 $object2Node->expects($this->any())->method('evaluate')->will($this->returnValue($object2));
356
357 $rootNode->addChildNode($object1Node);
358 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('=='));
359 $rootNode->addChildNode($object2Node);
360
361 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
362 $this->assertFalse($booleanNode->evaluate($this->renderingContext));
363 }
364
365 /**
366 * @test
367 */
368 public function objectsAreComparedStrictlyInUnequalComparison() {
369 $object1 = new \stdClass();
370 $object2 = new \stdClass();
371
372 $rootNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\RootNode();
373
374 $object1Node = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ObjectAccessorNode::class, array('evaluate'), array('foo'));
375 $object1Node->expects($this->any())->method('evaluate')->will($this->returnValue($object1));
376
377 $object2Node = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ObjectAccessorNode::class, array('evaluate'), array('foo'));
378 $object2Node->expects($this->any())->method('evaluate')->will($this->returnValue($object2));
379
380 $rootNode->addChildNode($object1Node);
381 $rootNode->addChildNode(new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\TextNode('!='));
382 $rootNode->addChildNode($object2Node);
383
384 $booleanNode = new \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode($rootNode);
385 $this->assertTrue($booleanNode->evaluate($this->renderingContext));
386 }
387
388 /**
389 * @test
390 */
391 public function convertToBooleanProperlyConvertsValuesOfTypeBoolean() {
392 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(FALSE));
393 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(TRUE));
394 }
395
396 /**
397 * @test
398 */
399 public function convertToBooleanProperlyConvertsValuesOfTypeString() {
400 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(''));
401 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('false'));
402 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('FALSE'));
403
404 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('true'));
405 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('TRUE'));
406 }
407
408 /**
409 * @test
410 */
411 public function convertToBooleanProperlyConvertsNumericValues() {
412 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(FALSE));
413 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(TRUE));
414
415 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(0));
416 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('0'));
417
418 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(0.0));
419 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('0.0'));
420
421 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(0x0));
422
423 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(0x1));
424 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('0x1'));
425
426 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(0e0));
427 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('0e0'));
428
429 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(1e0));
430 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('1e0'));
431
432 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(-1));
433 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('-1'));
434
435 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(-0.5));
436 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('-0.5'));
437
438 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(1));
439 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('1'));
440
441 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(0.5));
442 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('0.5'));
443
444 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(0x1));
445 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('0x10'));
446 }
447
448 /**
449 * @test
450 */
451 public function convertToBooleanProperlyConvertsValuesOfTypeArray() {
452 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(array()));
453
454 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(array('foo')));
455 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(array('foo' => 'bar')));
456 }
457
458 /**
459 * @test
460 */
461 public function convertToBooleanProperlyConvertsObjects() {
462 $this->assertFalse(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(NULL));
463
464 $this->assertTrue(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean(new \stdClass()));
465 }
466
467 }