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