f5ff1bec7c54c49dca846c47f9112934ea6b1d77
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / Configuration / TypoScript / ConditionMatching / ConditionMatcherTest.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\Configuration\TypoScript\ConditionMatching;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Tests\UnitTestCase;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher;
20
21 /**
22 * Test case
23 */
24 class ConditionMatcherTest extends UnitTestCase
25 {
26 /**
27 * @var string Name of a key in $GLOBALS for this test
28 */
29 protected $testGlobalNamespace;
30
31 /**
32 * @var \TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher Class under test
33 */
34 protected $matchCondition;
35
36 protected function setUp()
37 {
38 $this->testGlobalNamespace = $this->getUniqueId('TEST');
39 GeneralUtility::flushInternalRuntimeCaches();
40 $GLOBALS[$this->testGlobalNamespace] = array();
41 $GLOBALS['TSFE'] = new \stdClass();
42 $GLOBALS['TSFE']->tmpl = new \stdClass();
43 $GLOBALS['TSFE']->tmpl->rootLine = array(
44 2 => array('uid' => 121, 'pid' => 111),
45 1 => array('uid' => 111, 'pid' => 101),
46 0 => array('uid' => 101, 'pid' => 0)
47 );
48 $this->matchCondition = GeneralUtility::makeInstance(ConditionMatcher::class);
49 }
50
51 /**
52 * Tests whether a faulty expression fails.
53 *
54 * @test
55 */
56 public function simulateDisabledMatchAllConditionsFailsOnFaultyExpression()
57 {
58 $this->matchCondition->matchAll = false;
59 $this->assertFalse($this->matchCondition->match('[nullCondition = This expression would return FALSE in general]'));
60 }
61
62 /**
63 * Tests whether simulating positive matches for all conditions succeeds.
64 *
65 * @test
66 */
67 public function simulateEnabledMatchAllConditionsSucceeds()
68 {
69 $this->matchCondition->setSimulateMatchResult(true);
70 $this->assertTrue($this->matchCondition->match('[nullCondition = This expression would return FALSE in general]'));
71 }
72
73 /**
74 * Tests whether simulating positive matches for specific conditions succeeds.
75 *
76 * @test
77 */
78 public function simulateEnabledMatchSpecificConditionsSucceeds()
79 {
80 $testCondition = '[' . $this->getUniqueId('test') . ' = Any condition to simulate a positive match]';
81 $this->matchCondition->setSimulateMatchConditions(array($testCondition));
82 $this->assertTrue($this->matchCondition->match($testCondition));
83 }
84
85 /**
86 * Tests whether a condition matches Internet Explorer 7 on Windows.
87 *
88 * @return void
89 * @test
90 */
91 public function conditionMatchesInternetExplorer7Windows()
92 {
93 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)';
94 $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
95 $this->assertTrue($result);
96 }
97
98 /**
99 * Tests whether a condition does not match Internet Explorer 7 on Windows.
100 *
101 * @return void
102 * @test
103 */
104 public function conditionDoesNotMatchInternetExplorer7Windows()
105 {
106 $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.25 (Windows NT 6.0; U; en)';
107 $result = $this->matchCondition->match('[browser = msie] && [version = 7] && [system = winNT]');
108 $this->assertFalse($result);
109 }
110
111 /**
112 * Tests whether a condition does match the iOS with the correct and more recent 'iOS'
113 *
114 * @test
115 */
116 public function conditionDoesMatchIosWithCorrectSystemKey()
117 {
118 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7W367a Safari/531.21.10';
119 $result = $this->matchCondition->match('[system = iOS]');
120 $this->assertTrue($result);
121 }
122
123 /**
124 * Tests whether a condition does match the iOS with the old 'mac'
125 *
126 * @test
127 */
128 public function conditionDoesMatchIosWithOldSystemKey()
129 {
130 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7W367a Safari/531.21.10';
131 $result = $this->matchCondition->match('[system = mac]');
132 $this->assertTrue($result);
133 }
134
135 /**
136 * Tests whether a condition does match Windows 2000 with the correct and more recent 'win2k'
137 *
138 * @test
139 */
140 public function conditionDoesMatchWindows2kWithNewSystemKey()
141 {
142 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; SV1)';
143 $result = $this->matchCondition->match('[system = win2k]');
144 $this->assertTrue($result);
145 }
146
147 /**
148 * Tests whether a condition does match Windows 2000 with the old 'winNT'
149 *
150 * @test
151 */
152 public function conditionDoesMatchWindows2kWithOldSystemKey()
153 {
154 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; SV1)';
155 $result = $this->matchCondition->match('[system = winNT]');
156 $this->assertTrue($result);
157 }
158
159 /**
160 * Tests whether a condition does match Windows NT with 'winNT'
161 *
162 * @test
163 */
164 public function conditionDoesMatchWindowsNtWithSystemKey()
165 {
166 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0)';
167 $result = $this->matchCondition->match('[system = winNT]');
168 $this->assertTrue($result);
169 }
170
171 /**
172 * Tests whether a condition does match Android with the correct and more recent 'android'
173 *
174 * @test
175 */
176 public function conditionDoesMatchAndroidWithNewSystemKey()
177 {
178 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Linux; U; Android 2.3; en-US; sdk Build/GRH55) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1';
179 $result = $this->matchCondition->match('[system = android]');
180 $this->assertTrue($result);
181 }
182
183 /**
184 * Tests whether a condition does match Android with the old 'linux'
185 *
186 * @test
187 */
188 public function conditionDoesMatchAndroidWithOldSystemKey()
189 {
190 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Linux; U; Android 2.3; en-US; sdk Build/GRH55) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1';
191 $result = $this->matchCondition->match('[system = linux]');
192 $this->assertTrue($result);
193 }
194
195 /**
196 * Tests whether a device type condition matches a crawler.
197 *
198 * @test
199 */
200 public function deviceConditionMatchesRobot()
201 {
202 $_SERVER['HTTP_USER_AGENT'] = 'Googlebot/2.1 (+http://www.google.com/bot.html)';
203 $result = $this->matchCondition->match('[device = robot]');
204 $this->assertTrue($result);
205 }
206
207 /**
208 * Tests whether a device type condition does not match a crawler.
209 *
210 * @test
211 */
212 public function deviceConditionDoesNotMatchRobot()
213 {
214 $_SERVER['HTTP_USER_AGENT'] = md5('Some strange user agent');
215 $result = $this->matchCondition->match('[device = robot]');
216 $this->assertFalse($result);
217 }
218
219 /**
220 * Tests whether the language comparison matches.
221 *
222 * @test
223 */
224 public function languageConditionMatchesSingleLanguageExpression()
225 {
226 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
227 $this->assertTrue($this->matchCondition->match('[language = *de*]'));
228 $this->assertTrue($this->matchCondition->match('[language = *de-de*]'));
229 }
230
231 /**
232 * Tests whether the language comparison matches.
233 *
234 * @test
235 */
236 public function languageConditionMatchesMultipleLanguagesExpression()
237 {
238 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
239 $this->assertTrue($this->matchCondition->match('[language = *en*,*de*]'));
240 $this->assertTrue($this->matchCondition->match('[language = *en-us*,*de-de*]'));
241 }
242
243 /**
244 * Tests whether the language comparison matches.
245 *
246 * @test
247 */
248 public function languageConditionMatchesCompleteLanguagesExpression()
249 {
250 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
251 $this->assertTrue($this->matchCondition->match('[language = de-de,de;q=0.8,en-us;q=0.5,en;q=0.3]'));
252 }
253
254 /**
255 * Tests whether usergroup comparison matches.
256 *
257 * @test
258 */
259 public function usergroupConditionMatchesSingleGroupId()
260 {
261 $GLOBALS['TSFE']->gr_list = '13,14,15';
262 $this->assertTrue($this->matchCondition->match('[usergroup = 13]'));
263 }
264
265 /**
266 * Tests whether usergroup comparison matches.
267 *
268 * @test
269 */
270 public function usergroupConditionMatchesMultipleUserGroupId()
271 {
272 $GLOBALS['TSFE']->gr_list = '13,14,15';
273 $this->assertTrue($this->matchCondition->match('[usergroup = 999,15,14,13]'));
274 }
275
276 /**
277 * Tests whether usergroup comparison matches.
278 *
279 * @test
280 */
281 public function usergroupConditionDoesNotMatchDefaulUserGroupIds()
282 {
283 $GLOBALS['TSFE']->gr_list = '0,-1';
284 $this->assertFalse($this->matchCondition->match('[usergroup = 0,-1]'));
285 }
286
287 /**
288 * Tests whether user comparison matches.
289 *
290 * @test
291 */
292 public function loginUserConditionMatchesAnyLoggedInUser()
293 {
294 $GLOBALS['TSFE']->loginUser = true;
295 $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
296 $this->assertTrue($this->matchCondition->match('[loginUser = *]'));
297 }
298
299 /**
300 * Tests whether user comparison matches.
301 *
302 * @test
303 */
304 public function loginUserConditionMatchesSingleLoggedInUser()
305 {
306 $GLOBALS['TSFE']->loginUser = true;
307 $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
308 $this->assertTrue($this->matchCondition->match('[loginUser = 13]'));
309 }
310
311 /**
312 * Tests whether user comparison matches.
313 *
314 * @test
315 */
316 public function loginUserConditionMatchesMultipleLoggedInUsers()
317 {
318 $GLOBALS['TSFE']->loginUser = true;
319 $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
320 $this->assertTrue($this->matchCondition->match('[loginUser = 999,13]'));
321 }
322
323 /**
324 * Tests whether user comparison matches.
325 *
326 * @test
327 */
328 public function loginUserConditionDoesNotMatchIfNotUserIsLoggedId()
329 {
330 $GLOBALS['TSFE']->loginUser = false;
331 $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
332 $this->assertFalse($this->matchCondition->match('[loginUser = *]'));
333 $this->assertFalse($this->matchCondition->match('[loginUser = 13]'));
334 }
335
336 /**
337 * Tests whether user is not logged in
338 *
339 * @test
340 */
341 public function loginUserConditionMatchIfUserIsNotLoggedIn()
342 {
343 $GLOBALS['TSFE']->loginUser = false;
344 $this->assertTrue($this->matchCondition->match('[loginUser = ]'));
345 }
346
347 /**
348 * Tests whether numerical comparison matches.
349 *
350 * @test
351 */
352 public function globalVarConditionMatchesOnEqualExpression()
353 {
354 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10]'));
355 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1]'));
356 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10]'));
357 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1]'));
358 }
359
360 /**
361 * Tests whether numerical comparison matches.
362 *
363 * @test
364 */
365 public function globalVarConditionMatchesOnEqualExpressionWithMultipleValues()
366 {
367 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10|20|30]'));
368 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1|20.2|30.3]'));
369 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 = 10|20|30]'));
370 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20.2 = 10.1|20.2|30.3]'));
371 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10|20|30]'));
372 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1|20.2|30.3]'));
373 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 == 10|20|30]'));
374 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20.2 == 10.1|20.2|30.3]'));
375 }
376
377 /**
378 * Tests whether numerical comparison matches.
379 *
380 * @test
381 */
382 public function globalVarConditionMatchesOnNotEqualExpression()
383 {
384 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20]'));
385 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2]'));
386 }
387
388 /**
389 * Tests whether numerical comparison does not match.
390 *
391 * @test
392 */
393 public function globalVarConditionDoesNotMatchOnNotEqualExpression()
394 {
395 $this->assertFalse($this->matchCondition->match('[globalVar = LIT:10 != 10]'));
396 }
397
398 /**
399 * Tests whether numerical comparison matches.
400 *
401 * @test
402 */
403 public function globalVarConditionMatchesOnNotEqualExpressionWithMultipleValues()
404 {
405 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20|30]'));
406 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2|20.3]'));
407 }
408
409 /**
410 * Tests whether numerical comparison matches.
411 *
412 * @test
413 */
414 public function globalVarConditionMatchesOnLowerThanExpression()
415 {
416 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 < 20]'));
417 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 < 10.2]'));
418 }
419
420 /**
421 * Tests whether numerical comparison matches.
422 *
423 * @test
424 */
425 public function globalVarConditionMatchesOnLowerThanOrEqualExpression()
426 {
427 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 10]'));
428 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 20]'));
429 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.1]'));
430 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.2]'));
431 }
432
433 /**
434 * Tests whether numerical comparison matches.
435 *
436 * @test
437 */
438 public function globalVarConditionMatchesOnGreaterThanExpression()
439 {
440 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 > 10]'));
441 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 > 10.1]'));
442 }
443
444 /**
445 * Tests whether numerical comparison matches.
446 *
447 * @test
448 */
449 public function globalVarConditionMatchesOnGreaterThanOrEqualExpression()
450 {
451 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 >= 10]'));
452 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 >= 10]'));
453 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 >= 10.1]'));
454 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 >= 10.1]'));
455 }
456
457 /**
458 * Tests whether numerical comparison matches.
459 *
460 * @test
461 */
462 public function globalVarConditionMatchesOnEmptyExpressionWithNoValueSet()
463 {
464 $testKey = $this->getUniqueId('test');
465 $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]'));
466 $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]'));
467 }
468
469 /**
470 * Tests whether numerical comparison matches.
471 *
472 * @test
473 */
474 public function globalVarConditionDoesNotMatchOnEmptyExpressionWithValueSetToZero()
475 {
476 $testKey = $this->getUniqueId('test');
477 $_GET = array();
478 $_POST = array($testKey => 0);
479 $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]'));
480 $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]'));
481 }
482
483 /**
484 * Tests whether an array with zero as key matches its value
485 *
486 * @test
487 */
488 public function globalVarConditionMatchesOnArrayExpressionWithZeroAsKey()
489 {
490 $testKey = $this->getUniqueId('test');
491 $testValue = '1';
492 $_GET = array();
493 $_POST = array($testKey => array('0' => $testValue));
494 $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . '|0=' . $testValue . ']'));
495 }
496
497 /**
498 * Tests whether string comparison matches.
499 *
500 * @test
501 */
502 public function globalStringConditionMatchesOnEqualExpression()
503 {
504 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.Test.Condition]'));
505 $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3]'));
506 }
507
508 /**
509 * Tests whether string comparison matches.
510 *
511 * @test
512 */
513 public function globalStringConditionMatchesOnEmptyExpressionWithValueSetToEmptyString()
514 {
515 $testKey = $this->getUniqueId('test');
516 $_GET = array();
517 $_POST = array($testKey => '');
518 $this->assertTrue($this->matchCondition->match('[globalString = GP:' . $testKey . '=]'));
519 $this->assertTrue($this->matchCondition->match('[globalString = GP:' . $testKey . ' = ]'));
520 }
521
522 /**
523 * Tests whether string comparison matches.
524 *
525 * @test
526 */
527 public function globalStringConditionMatchesOnEmptyLiteralExpressionWithValueSetToEmptyString()
528 {
529 $this->assertTrue($this->matchCondition->match('[globalString = LIT:=]'));
530 $this->assertTrue($this->matchCondition->match('[globalString = LIT: = ]'));
531 }
532
533 /**
534 * Tests whether string comparison matches.
535 *
536 * @test
537 */
538 public function globalStringConditionMatchesWildcardExpression()
539 {
540 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]'));
541 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]'));
542 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?T*t?Condition]'));
543 }
544
545 /**
546 * Tests whether string comparison matches.
547 *
548 * @test
549 */
550 public function globalStringConditionMatchesRegularExpression()
551 {
552 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^[A-Za-z3.]+$/]'));
553 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^TYPO3\\..+Condition$/]'));
554 $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^FALSE/]'));
555 }
556
557 /**
558 * Tests whether string comparison matches.
559 *
560 * @test
561 */
562 public function globalStringConditionMatchesEmptyRegularExpression()
563 {
564 $testKey = $this->getUniqueId('test');
565 $_SERVER[$testKey] = '';
566 $this->assertTrue($this->matchCondition->match('[globalString = _SERVER|' . $testKey . ' = /^$/]'));
567 }
568
569 /**
570 * Tests whether treeLevel comparison matches.
571 *
572 * @test
573 */
574 public function treeLevelConditionMatchesSingleValue()
575 {
576 $this->assertTrue($this->matchCondition->match('[treeLevel = 2]'));
577 }
578
579 /**
580 * Tests whether treeLevel comparison matches.
581 *
582 * @test
583 */
584 public function treeLevelConditionMatchesMultipleValues()
585 {
586 $this->assertTrue($this->matchCondition->match('[treeLevel = 999,998,2]'));
587 }
588
589 /**
590 * Tests whether treeLevel comparison matches.
591 *
592 * @test
593 */
594 public function treeLevelConditionDoesNotMatchFaultyValue()
595 {
596 $this->assertFalse($this->matchCondition->match('[treeLevel = 999]'));
597 }
598
599 /**
600 * Tests whether a page Id is found in the previous rootline entries.
601 *
602 * @test
603 */
604 public function PIDupinRootlineConditionMatchesSinglePageIdInRootline()
605 {
606 $GLOBALS['TSFE']->id = 121;
607 $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 111]'));
608 }
609
610 /**
611 * Tests whether a page Id is found in the previous rootline entries.
612 *
613 * @test
614 */
615 public function PIDupinRootlineConditionMatchesMultiplePageIdsInRootline()
616 {
617 $GLOBALS['TSFE']->id = 121;
618 $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 999,111,101]'));
619 }
620
621 /**
622 * Tests whether a page Id is found in the previous rootline entries.
623 *
624 * @test
625 */
626 public function PIDupinRootlineConditionDoesNotMatchPageIdNotInRootline()
627 {
628 $GLOBALS['TSFE']->id = 121;
629 $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 999]'));
630 }
631
632 /**
633 * Tests whether a page Id is found in the previous rootline entries.
634 *
635 * @test
636 */
637 public function PIDupinRootlineConditionDoesNotMatchLastPageIdInRootline()
638 {
639 $GLOBALS['TSFE']->id = 121;
640 $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 121]'));
641 }
642
643 /**
644 * Tests whether a page Id is found in all rootline entries.
645 *
646 * @test
647 */
648 public function PIDinRootlineConditionMatchesSinglePageIdInRootline()
649 {
650 $GLOBALS['TSFE']->id = 121;
651 $this->assertTrue($this->matchCondition->match('[PIDinRootline = 111]'));
652 }
653
654 /**
655 * Tests whether a page Id is found in all rootline entries.
656 *
657 * @test
658 */
659 public function PIDinRootlineConditionMatchesMultiplePageIdsInRootline()
660 {
661 $GLOBALS['TSFE']->id = 121;
662 $this->assertTrue($this->matchCondition->match('[PIDinRootline = 999,111,101]'));
663 }
664
665 /**
666 * Tests whether a page Id is found in all rootline entries.
667 *
668 * @test
669 */
670 public function PIDinRootlineConditionMatchesLastPageIdInRootline()
671 {
672 $GLOBALS['TSFE']->id = 121;
673 $this->assertTrue($this->matchCondition->match('[PIDinRootline = 121]'));
674 }
675
676 /**
677 * Tests whether a page Id is found in all rootline entries.
678 *
679 * @test
680 */
681 public function PIDinRootlineConditionDoesNotMatchPageIdNotInRootline()
682 {
683 $GLOBALS['TSFE']->id = 121;
684 $this->assertFalse($this->matchCondition->match('[PIDinRootline = 999]'));
685 }
686
687 /**
688 * Tests whether the compatibility version can be evaluated.
689 * (e.g. 7.9 is compatible to 7.0 but not to 15.0)
690 *
691 * @test
692 */
693 public function compatVersionConditionMatchesOlderRelease()
694 {
695 $this->assertTrue($this->matchCondition->match('[compatVersion = 7.0]'));
696 }
697
698 /**
699 * Tests whether the compatibility version can be evaluated.
700 * (e.g. 7.9 is compatible to 7.0 but not to 15.0)
701 *
702 * @test
703 */
704 public function compatVersionConditionMatchesSameRelease()
705 {
706 $this->assertTrue($this->matchCondition->match('[compatVersion = ' . TYPO3_branch . ']'));
707 }
708
709 /**
710 * Tests whether the compatibility version can be evaluated.
711 * (e.g. 7.9 is compatible to 7.0 but not to 15.0)
712 *
713 * @test
714 */
715 public function compatVersionConditionDoesNotMatchNewerRelease()
716 {
717 $this->assertFalse($this->matchCondition->match('[compatVersion = 15.0]'));
718 }
719
720 /**
721 * Tests whether the generic fetching of variables works with the namespace 'GP'.
722 *
723 * @test
724 */
725 public function genericGetVariablesSucceedsWithNamespaceGP()
726 {
727 $_GET = array('testGet' => 'getTest');
728 $_POST = array('testPost' => 'postTest');
729 $this->assertTrue($this->matchCondition->match('[globalString = GP:testGet = getTest]'));
730 $this->assertTrue($this->matchCondition->match('[globalString = GP:testPost = postTest]'));
731 }
732
733 /**
734 * Tests whether the generic fetching of variables works with the namespace 'TSFE'.
735 *
736 * @test
737 */
738 public function genericGetVariablesSucceedsWithNamespaceTSFE()
739 {
740 $GLOBALS['TSFE']->id = 1234567;
741 $GLOBALS['TSFE']->testSimpleObject = new \stdClass();
742 $GLOBALS['TSFE']->testSimpleObject->testSimpleVariable = 'testValue';
743 $this->assertTrue($this->matchCondition->match('[globalString = TSFE:id = 1234567]'));
744 $this->assertTrue($this->matchCondition->match('[globalString = TSFE:testSimpleObject|testSimpleVariable = testValue]'));
745 }
746
747 /**
748 * Tests whether the generic fetching of variables works with the namespace 'ENV'.
749 *
750 * @test
751 */
752 public function genericGetVariablesSucceedsWithNamespaceENV()
753 {
754 $testKey = $this->getUniqueId('test');
755 putenv($testKey . '=testValue');
756 $this->assertTrue($this->matchCondition->match('[globalString = ENV:' . $testKey . ' = testValue]'));
757 }
758
759 /**
760 * Tests whether the generic fetching of variables works with the namespace 'IENV'.
761 *
762 * @test
763 */
764 public function genericGetVariablesSucceedsWithNamespaceIENV()
765 {
766 $_SERVER['HTTP_HOST'] = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567';
767 $this->assertTrue($this->matchCondition->match('[globalString = IENV:TYPO3_PORT = 1234567]'));
768 }
769
770 /**
771 * Tests whether the generic fetching of variables works with any global namespace.
772 *
773 * @test
774 */
775 public function genericGetVariablesSucceedsWithAnyGlobalNamespace()
776 {
777 $GLOBALS[$this->testGlobalNamespace] = array(
778 'first' => 'testFirst',
779 'second' => array('third' => 'testThird')
780 );
781 $this->assertTrue($this->matchCondition->match('[globalString = ' . $this->testGlobalNamespace . '|first = testFirst]'));
782 $this->assertTrue($this->matchCondition->match('[globalString = ' . $this->testGlobalNamespace . '|second|third = testThird]'));
783 }
784
785 /**
786 * @test
787 * @expectedException \TYPO3\CMS\Core\Configuration\TypoScript\Exception\InvalidTypoScriptConditionException
788 */
789 public function matchThrowsExceptionIfConditionClassDoesNotInheritFromAbstractCondition()
790 {
791 $this->matchCondition->match('[stdClass = foo]');
792 }
793
794 /**
795 * @test
796 * @expectedException \TYPO3\CMS\Frontend\Tests\Unit\Configuration\TypoScript\ConditionMatching\Fixtures\TestConditionException
797 */
798 public function matchCallsTestConditionAndHandsOverParameters()
799 {
800 $this->matchCondition->match('[TYPO3\\CMS\\Frontend\\Tests\\Unit\\Configuration\\TypoScript\\ConditionMatching\\Fixtures\\TestCondition = 7, != 6]');
801 }
802 }