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