dc1e75bc35623610d5f310a4be08f855305cbf3b
[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 $this->markTestSkipped('This comparison seems to be incomplete in \TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher.');
240 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
241 $this->assertTrue($this->matchCondition->match('[language = de-de,de;q=0.8]'));
242 }
243
244 /**
245 * Tests whether usergroup comparison matches.
246 *
247 * @test
248 */
249 public function usergroupConditionMatchesSingleGroupId() {
250 $GLOBALS['TSFE']->gr_list = '13,14,15';
251 $this->assertTrue($this->matchCondition->match('[usergroup = 13]'));
252 }
253
254 /**
255 * Tests whether usergroup comparison matches.
256 *
257 * @test
258 */
259 public function usergroupConditionMatchesMultipleUserGroupId() {
260 $GLOBALS['TSFE']->gr_list = '13,14,15';
261 $this->assertTrue($this->matchCondition->match('[usergroup = 999,15,14,13]'));
262 }
263
264 /**
265 * Tests whether usergroup comparison matches.
266 *
267 * @test
268 */
269 public function usergroupConditionDoesNotMatchDefaulUserGroupIds() {
270 $GLOBALS['TSFE']->gr_list = '0,-1';
271 $this->assertFalse($this->matchCondition->match('[usergroup = 0,-1]'));
272 }
273
274 /**
275 * Tests whether user comparison matches.
276 *
277 * @test
278 */
279 public function loginUserConditionMatchesAnyLoggedInUser() {
280 $GLOBALS['TSFE']->loginUser = TRUE;
281 $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
282 $this->assertTrue($this->matchCondition->match('[loginUser = *]'));
283 }
284
285 /**
286 * Tests whether user comparison matches.
287 *
288 * @test
289 */
290 public function loginUserConditionMatchesSingleLoggedInUser() {
291 $GLOBALS['TSFE']->loginUser = TRUE;
292 $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
293 $this->assertTrue($this->matchCondition->match('[loginUser = 13]'));
294 }
295
296 /**
297 * Tests whether user comparison matches.
298 *
299 * @test
300 */
301 public function loginUserConditionMatchesMultipleLoggedInUsers() {
302 $GLOBALS['TSFE']->loginUser = TRUE;
303 $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
304 $this->assertTrue($this->matchCondition->match('[loginUser = 999,13]'));
305 }
306
307 /**
308 * Tests whether user comparison matches.
309 *
310 * @test
311 */
312 public function loginUserConditionDoesNotMatchIfNotUserIsLoggedId() {
313 $GLOBALS['TSFE']->loginUser = FALSE;
314 $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
315 $this->assertFalse($this->matchCondition->match('[loginUser = *]'));
316 $this->assertFalse($this->matchCondition->match('[loginUser = 13]'));
317 }
318
319 /**
320 * Tests whether user is not logged in
321 *
322 * @test
323 */
324 public function loginUserConditionMatchIfUserIsNotLoggedIn() {
325 $GLOBALS['TSFE']->loginUser = FALSE;
326 $this->assertTrue($this->matchCondition->match('[loginUser = ]'));
327 }
328
329 /**
330 * Tests whether numerical comparison matches.
331 *
332 * @test
333 */
334 public function globalVarConditionMatchesOnEqualExpression() {
335 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10]'));
336 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1]'));
337 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10]'));
338 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1]'));
339 }
340
341 /**
342 * Tests whether numerical comparison matches.
343 *
344 * @test
345 */
346 public function globalVarConditionMatchesOnEqualExpressionWithMultipleValues() {
347 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10|20|30]'));
348 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1|20.2|30.3]'));
349 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 = 10|20|30]'));
350 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20.2 = 10.1|20.2|30.3]'));
351 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10|20|30]'));
352 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1|20.2|30.3]'));
353 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 == 10|20|30]'));
354 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20.2 == 10.1|20.2|30.3]'));
355 }
356
357 /**
358 * Tests whether numerical comparison matches.
359 *
360 * @test
361 */
362 public function globalVarConditionMatchesOnNotEqualExpression() {
363 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20]'));
364 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2]'));
365 }
366
367 /**
368 * Tests whether numerical comparison does not match.
369 *
370 * @test
371 */
372 public function globalVarConditionDoesNotMatchOnNotEqualExpression() {
373 $this->assertFalse($this->matchCondition->match('[globalVar = LIT:10 != 10]'));
374 }
375
376 /**
377 * Tests whether numerical comparison matches.
378 *
379 * @test
380 */
381 public function globalVarConditionMatchesOnNotEqualExpressionWithMultipleValues() {
382 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20|30]'));
383 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2|20.3]'));
384 }
385
386 /**
387 * Tests whether numerical comparison matches.
388 *
389 * @test
390 */
391 public function globalVarConditionMatchesOnLowerThanExpression() {
392 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 < 20]'));
393 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 < 10.2]'));
394 }
395
396 /**
397 * Tests whether numerical comparison matches.
398 *
399 * @test
400 */
401 public function globalVarConditionMatchesOnLowerThanOrEqualExpression() {
402 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 10]'));
403 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 20]'));
404 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.1]'));
405 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.2]'));
406 }
407
408 /**
409 * Tests whether numerical comparison matches.
410 *
411 * @test
412 */
413 public function globalVarConditionMatchesOnGreaterThanExpression() {
414 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 > 10]'));
415 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 > 10.1]'));
416 }
417
418 /**
419 * Tests whether numerical comparison matches.
420 *
421 * @test
422 */
423 public function globalVarConditionMatchesOnGreaterThanOrEqualExpression() {
424 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 >= 10]'));
425 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 >= 10]'));
426 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 >= 10.1]'));
427 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 >= 10.1]'));
428 }
429
430 /**
431 * Tests whether numerical comparison matches.
432 *
433 * @test
434 */
435 public function globalVarConditionMatchesOnEmptyExpressionWithNoValueSet() {
436 $testKey = uniqid('test');
437 $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]'));
438 $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]'));
439 }
440
441 /**
442 * Tests whether numerical comparison matches.
443 *
444 * @test
445 */
446 public function globalVarConditionDoesNotMatchOnEmptyExpressionWithValueSetToZero() {
447 $testKey = uniqid('test');
448 $_GET = array();
449 $_POST = array($testKey => 0);
450 $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]'));
451 $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]'));
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 = uniqid('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 globalStringConditionMatchesWildcardExpression() {
483 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]'));
484 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]'));
485 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?T*t?Condition]'));
486 }
487
488 /**
489 * Tests whether string comparison matches.
490 *
491 * @test
492 */
493 public function globalStringConditionMatchesRegularExpression() {
494 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^[A-Za-z3.]+$/]'));
495 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^TYPO3\\..+Condition$/]'));
496 $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^FALSE/]'));
497 }
498
499 /**
500 * Tests whether string comparison matches.
501 *
502 * @test
503 */
504 public function globalStringConditionMatchesEmptyRegularExpression() {
505 $testKey = uniqid('test');
506 $_SERVER[$testKey] = '';
507 $this->assertTrue($this->matchCondition->match('[globalString = _SERVER|' . $testKey . ' = /^$/]'));
508 }
509
510 /**
511 * Tests whether treeLevel comparison matches.
512 *
513 * @test
514 */
515 public function treeLevelConditionMatchesSingleValue() {
516 $this->assertTrue($this->matchCondition->match('[treeLevel = 2]'));
517 }
518
519 /**
520 * Tests whether treeLevel comparison matches.
521 *
522 * @test
523 */
524 public function treeLevelConditionMatchesMultipleValues() {
525 $this->assertTrue($this->matchCondition->match('[treeLevel = 999,998,2]'));
526 }
527
528 /**
529 * Tests whether treeLevel comparison matches.
530 *
531 * @test
532 */
533 public function treeLevelConditionDoesNotMatchFaultyValue() {
534 $this->assertFalse($this->matchCondition->match('[treeLevel = 999]'));
535 }
536
537 /**
538 * Tests whether a page Id is found in the previous rootline entries.
539 *
540 * @test
541 */
542 public function PIDupinRootlineConditionMatchesSinglePageIdInRootline() {
543 $GLOBALS['TSFE']->id = 121;
544 $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 111]'));
545 }
546
547 /**
548 * Tests whether a page Id is found in the previous rootline entries.
549 *
550 * @test
551 */
552 public function PIDupinRootlineConditionMatchesMultiplePageIdsInRootline() {
553 $GLOBALS['TSFE']->id = 121;
554 $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 999,111,101]'));
555 }
556
557 /**
558 * Tests whether a page Id is found in the previous rootline entries.
559 *
560 * @test
561 */
562 public function PIDupinRootlineConditionDoesNotMatchPageIdNotInRootline() {
563 $GLOBALS['TSFE']->id = 121;
564 $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 999]'));
565 }
566
567 /**
568 * Tests whether a page Id is found in the previous rootline entries.
569 *
570 * @test
571 */
572 public function PIDupinRootlineConditionDoesNotMatchLastPageIdInRootline() {
573 $GLOBALS['TSFE']->id = 121;
574 $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 121]'));
575 }
576
577 /**
578 * Tests whether a page Id is found in all rootline entries.
579 *
580 * @test
581 */
582 public function PIDinRootlineConditionMatchesSinglePageIdInRootline() {
583 $GLOBALS['TSFE']->id = 121;
584 $this->assertTrue($this->matchCondition->match('[PIDinRootline = 111]'));
585 }
586
587 /**
588 * Tests whether a page Id is found in all rootline entries.
589 *
590 * @test
591 */
592 public function PIDinRootlineConditionMatchesMultiplePageIdsInRootline() {
593 $GLOBALS['TSFE']->id = 121;
594 $this->assertTrue($this->matchCondition->match('[PIDinRootline = 999,111,101]'));
595 }
596
597 /**
598 * Tests whether a page Id is found in all rootline entries.
599 *
600 * @test
601 */
602 public function PIDinRootlineConditionMatchesLastPageIdInRootline() {
603 $GLOBALS['TSFE']->id = 121;
604 $this->assertTrue($this->matchCondition->match('[PIDinRootline = 121]'));
605 }
606
607 /**
608 * Tests whether a page Id is found in all rootline entries.
609 *
610 * @test
611 */
612 public function PIDinRootlineConditionDoesNotMatchPageIdNotInRootline() {
613 $GLOBALS['TSFE']->id = 121;
614 $this->assertFalse($this->matchCondition->match('[PIDinRootline = 999]'));
615 }
616
617 /**
618 * Tests whether the compatibility version can be evaluated.
619 * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
620 *
621 * @test
622 */
623 public function compatVersionConditionMatchesOlderRelease() {
624 $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
625 $this->assertTrue($this->matchCondition->match('[compatVersion = 4.0]'));
626 }
627
628 /**
629 * Tests whether the compatibility version can be evaluated.
630 * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
631 *
632 * @test
633 */
634 public function compatVersionConditionMatchesSameRelease() {
635 $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
636 $this->assertTrue($this->matchCondition->match('[compatVersion = 4.9]'));
637 }
638
639 /**
640 * Tests whether the compatibility version can be evaluated.
641 * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
642 *
643 * @test
644 */
645 public function compatVersionConditionDoesNotMatchNewerRelease() {
646 $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
647 $this->assertFalse($this->matchCondition->match('[compatVersion = 5.0]'));
648 }
649
650 /**
651 * Tests whether the generic fetching of variables works with the namespace 'GP'.
652 *
653 * @test
654 */
655 public function genericGetVariablesSucceedsWithNamespaceGP() {
656 $_GET = array('testGet' => 'getTest');
657 $_POST = array('testPost' => 'postTest');
658 $this->assertTrue($this->matchCondition->match('[globalString = GP:testGet = getTest]'));
659 $this->assertTrue($this->matchCondition->match('[globalString = GP:testPost = postTest]'));
660 }
661
662 /**
663 * Tests whether the generic fetching of variables works with the namespace 'TSFE'.
664 *
665 * @test
666 */
667 public function genericGetVariablesSucceedsWithNamespaceTSFE() {
668 $GLOBALS['TSFE']->id = 1234567;
669 $GLOBALS['TSFE']->testSimpleObject = new \stdClass();
670 $GLOBALS['TSFE']->testSimpleObject->testSimpleVariable = 'testValue';
671 $this->assertTrue($this->matchCondition->match('[globalString = TSFE:id = 1234567]'));
672 $this->assertTrue($this->matchCondition->match('[globalString = TSFE:testSimpleObject|testSimpleVariable = testValue]'));
673 }
674
675 /**
676 * Tests whether the generic fetching of variables works with the namespace 'ENV'.
677 *
678 * @test
679 */
680 public function genericGetVariablesSucceedsWithNamespaceENV() {
681 $testKey = uniqid('test');
682 putenv($testKey . '=testValue');
683 $this->assertTrue($this->matchCondition->match('[globalString = ENV:' . $testKey . ' = testValue]'));
684 }
685
686 /**
687 * Tests whether the generic fetching of variables works with the namespace 'IENV'.
688 *
689 * @test
690 */
691 public function genericGetVariablesSucceedsWithNamespaceIENV() {
692 $_SERVER['HTTP_HOST'] = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567';
693 $this->assertTrue($this->matchCondition->match('[globalString = IENV:TYPO3_PORT = 1234567]'));
694 }
695
696 /**
697 * Tests whether the generic fetching of variables works with any global namespace.
698 *
699 * @test
700 */
701 public function genericGetVariablesSucceedsWithAnyGlobalNamespace() {
702 $GLOBALS[$this->testGlobalNamespace] = array(
703 'first' => 'testFirst',
704 'second' => array('third' => 'testThird')
705 );
706 $this->assertTrue($this->matchCondition->match('[globalString = ' . $this->testGlobalNamespace . '|first = testFirst]'));
707 $this->assertTrue($this->matchCondition->match('[globalString = ' . $this->testGlobalNamespace . '|second|third = testThird]'));
708 }
709
710 }