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