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