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