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