2 namespace TYPO3\CMS\Frontend\Tests\Unit\Configuration\TypoScript\ConditionMatching;
17 use TYPO3\CMS\Core\Tests\UnitTestCase;
38 $this->testGlobalNamespace = $this->getUniqueId(
'TEST');
42 $GLOBALS[
'TSFE']->tmpl = new \stdClass();
43 $GLOBALS[
'TSFE']->tmpl->rootLine = array(
44 2 => array(
'uid' => 121,
'pid' => 111),
45 1 => array(
'uid' => 111,
'pid' => 101),
46 0 => array(
'uid' => 101,
'pid' => 0)
58 $this->matchCondition->matchAll =
false;
59 $this->assertFalse($this->matchCondition->match(
'[nullCondition = This expression would return FALSE in general]'));
69 $this->matchCondition->setSimulateMatchResult(
true);
70 $this->assertTrue($this->matchCondition->match(
'[nullCondition = This expression would return FALSE in general]'));
80 $testCondition =
'[' . $this->getUniqueId(
'test') .
' = Any condition to simulate a positive match]';
81 $this->matchCondition->setSimulateMatchConditions(array($testCondition));
82 $this->assertTrue($this->matchCondition->match($testCondition));
93 $_SERVER[
'HTTP_USER_AGENT'] =
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)';
94 $result = $this->matchCondition->match(
'[browser = msie] && [version = 7] && [system = winNT]');
95 $this->assertTrue($result);
106 $_SERVER[
'HTTP_USER_AGENT'] =
'Opera/9.25 (Windows NT 6.0; U; en)';
107 $result = $this->matchCondition->match(
'[browser = msie] && [version = 7] && [system = winNT]');
108 $this->assertFalse($result);
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);
130 $_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';
131 $result = $this->matchCondition->match(
'[system = mac]');
132 $this->assertTrue($result);
142 $_SERVER[
'HTTP_USER_AGENT'] =
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; SV1)';
143 $result = $this->matchCondition->match(
'[system = win2k]');
144 $this->assertTrue($result);
154 $_SERVER[
'HTTP_USER_AGENT'] =
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; SV1)';
155 $result = $this->matchCondition->match(
'[system = winNT]');
156 $this->assertTrue($result);
166 $_SERVER[
'HTTP_USER_AGENT'] =
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0)';
167 $result = $this->matchCondition->match(
'[system = winNT]');
168 $this->assertTrue($result);
178 $_SERVER[
'HTTP_USER_AGENT'] =
'Mozilla/5.0 (Linux; U; Android 2.3; en-US; sdk Build/GRH55) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1';
179 $result = $this->matchCondition->match(
'[system = android]');
180 $this->assertTrue($result);
190 $_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';
191 $result = $this->matchCondition->match(
'[system = linux]');
192 $this->assertTrue($result);
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);
214 $_SERVER[
'HTTP_USER_AGENT'] = md5(
'Some strange user agent');
215 $result = $this->matchCondition->match(
'[device = robot]');
216 $this->assertFalse($result);
226 $_SERVER[
'HTTP_ACCEPT_LANGUAGE'] =
'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
227 $this->assertTrue($this->matchCondition->match(
'[language = *de*]'));
228 $this->assertTrue($this->matchCondition->match(
'[language = *de-de*]'));
238 $_SERVER[
'HTTP_ACCEPT_LANGUAGE'] =
'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
239 $this->assertTrue($this->matchCondition->match(
'[language = *en*,*de*]'));
240 $this->assertTrue($this->matchCondition->match(
'[language = *en-us*,*de-de*]'));
250 $_SERVER[
'HTTP_ACCEPT_LANGUAGE'] =
'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
251 $this->assertTrue($this->matchCondition->match(
'[language = de-de,de;q=0.8,en-us;q=0.5,en;q=0.3]'));
261 $GLOBALS[
'TSFE']->gr_list =
'13,14,15';
262 $this->assertTrue($this->matchCondition->match(
'[usergroup = 13]'));
272 $GLOBALS[
'TSFE']->gr_list =
'13,14,15';
273 $this->assertTrue($this->matchCondition->match(
'[usergroup = 999,15,14,13]'));
284 $this->assertFalse($this->matchCondition->match(
'[usergroup = 0,-1]'));
295 $GLOBALS[
'TSFE']->fe_user->user[
'uid'] = 13;
296 $this->assertTrue($this->matchCondition->match(
'[loginUser = *]'));
307 $GLOBALS[
'TSFE']->fe_user->user[
'uid'] = 13;
308 $this->assertTrue($this->matchCondition->match(
'[loginUser = 13]'));
319 $GLOBALS[
'TSFE']->fe_user->user[
'uid'] = 13;
320 $this->assertTrue($this->matchCondition->match(
'[loginUser = 999,13]'));
330 $GLOBALS[
'TSFE']->loginUser =
false;
331 $GLOBALS[
'TSFE']->fe_user->user[
'uid'] = 13;
332 $this->assertFalse($this->matchCondition->match(
'[loginUser = *]'));
333 $this->assertFalse($this->matchCondition->match(
'[loginUser = 13]'));
343 $GLOBALS[
'TSFE']->loginUser =
false;
344 $this->assertTrue($this->matchCondition->match(
'[loginUser = ]'));
354 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 = 10]'));
355 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 = 10.1]'));
356 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 == 10]'));
357 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 == 10.1]'));
367 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 = 10|20|30]'));
368 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 = 10.1|20.2|30.3]'));
369 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:20 = 10|20|30]'));
370 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:20.2 = 10.1|20.2|30.3]'));
371 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 == 10|20|30]'));
372 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 == 10.1|20.2|30.3]'));
373 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:20 == 10|20|30]'));
374 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:20.2 == 10.1|20.2|30.3]'));
384 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 != 20]'));
385 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 != 10.2]'));
395 $this->assertFalse($this->matchCondition->match(
'[globalVar = LIT:10 != 10]'));
405 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 != 20|30]'));
406 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 != 10.2|20.3]'));
416 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 < 20]'));
417 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 < 10.2]'));
427 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 <= 10]'));
428 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 <= 20]'));
429 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 <= 10.1]'));
430 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 <= 10.2]'));
440 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:20 > 10]'));
441 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.2 > 10.1]'));
451 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 >= 10]'));
452 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:20 >= 10]'));
453 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 >= 10.1]'));
454 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.2 >= 10.1]'));
464 $testKey = $this->getUniqueId(
'test');
465 $this->assertTrue($this->matchCondition->match(
'[globalVar = GP:' . $testKey .
'=]'));
466 $this->assertTrue($this->matchCondition->match(
'[globalVar = GP:' . $testKey .
' = ]'));
476 $testKey = $this->getUniqueId(
'test');
478 $_POST = array($testKey => 0);
479 $this->assertFalse($this->matchCondition->match(
'[globalVar = GP:' . $testKey .
'=]'));
480 $this->assertFalse($this->matchCondition->match(
'[globalVar = GP:' . $testKey .
' = ]'));
490 $testKey = $this->getUniqueId(
'test');
493 $_POST = array($testKey => array(
'0' => $testValue));
494 $this->assertTrue($this->matchCondition->match(
'[globalVar = GP:' . $testKey .
'|0=' . $testValue .
']'));
504 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = TYPO3.Test.Condition]'));
505 $this->assertFalse($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = TYPO3]'));
515 $testKey = $this->getUniqueId(
'test');
517 $_POST = array($testKey =>
'');
518 $this->assertTrue($this->matchCondition->match(
'[globalString = GP:' . $testKey .
'=]'));
519 $this->assertTrue($this->matchCondition->match(
'[globalString = GP:' . $testKey .
' = ]'));
529 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT:=]'));
530 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT: = ]'));
540 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]'));
541 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]'));
542 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = TYPO3?T*t?Condition]'));
552 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = /^[A-Za-z3.]+$/]'));
553 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = /^TYPO3\\..+Condition$/]'));
554 $this->assertFalse($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = /^FALSE/]'));
564 $testKey = $this->getUniqueId(
'test');
565 $_SERVER[$testKey] =
'';
566 $this->assertTrue($this->matchCondition->match(
'[globalString = _SERVER|' . $testKey .
' = /^$/]'));
576 $this->assertTrue($this->matchCondition->match(
'[treeLevel = 2]'));
586 $this->assertTrue($this->matchCondition->match(
'[treeLevel = 999,998,2]'));
596 $this->assertFalse($this->matchCondition->match(
'[treeLevel = 999]'));
607 $this->assertTrue($this->matchCondition->match(
'[PIDupinRootline = 111]'));
618 $this->assertTrue($this->matchCondition->match(
'[PIDupinRootline = 999,111,101]'));
629 $this->assertFalse($this->matchCondition->match(
'[PIDupinRootline = 999]'));
640 $this->assertFalse($this->matchCondition->match(
'[PIDupinRootline = 121]'));
651 $this->assertTrue($this->matchCondition->match(
'[PIDinRootline = 111]'));
662 $this->assertTrue($this->matchCondition->match(
'[PIDinRootline = 999,111,101]'));
673 $this->assertTrue($this->matchCondition->match(
'[PIDinRootline = 121]'));
684 $this->assertFalse($this->matchCondition->match(
'[PIDinRootline = 999]'));
695 $this->assertTrue($this->matchCondition->match(
'[compatVersion = 7.0]'));
706 $this->assertTrue($this->matchCondition->match(
'[compatVersion = ' . TYPO3_branch .
']'));
717 $this->assertFalse($this->matchCondition->match(
'[compatVersion = 15.0]'));
727 $_GET = array(
'testGet' =>
'getTest');
728 $_POST = array(
'testPost' =>
'postTest');
729 $this->assertTrue($this->matchCondition->match(
'[globalString = GP:testGet = getTest]'));
730 $this->assertTrue($this->matchCondition->match(
'[globalString = GP:testPost = postTest]'));
741 $GLOBALS[
'TSFE']->testSimpleObject = new \stdClass();
742 $GLOBALS[
'TSFE']->testSimpleObject->testSimpleVariable =
'testValue';
743 $this->assertTrue($this->matchCondition->match(
'[globalString = TSFE:id = 1234567]'));
744 $this->assertTrue($this->matchCondition->match(
'[globalString = TSFE:testSimpleObject|testSimpleVariable = testValue]'));
754 $testKey = $this->getUniqueId(
'test');
755 putenv($testKey .
'=testValue');
756 $this->assertTrue($this->matchCondition->match(
'[globalString = ENV:' . $testKey .
' = testValue]'));
767 $this->assertTrue($this->matchCondition->match(
'[globalString = IENV:TYPO3_PORT = 1234567]'));
778 'first' =>
'testFirst',
779 'second' => array(
'third' =>
'testThird')
781 $this->assertTrue($this->matchCondition->match(
'[globalString = ' . $this->testGlobalNamespace .
'|first = testFirst]'));
782 $this->assertTrue($this->matchCondition->match(
'[globalString = ' . $this->testGlobalNamespace .
'|second|third = testThird]'));
791 $this->matchCondition->match(
'[stdClass = foo]');
800 $this->matchCondition->match(
'[TYPO3\\CMS\\Frontend\\Tests\\Unit\\Configuration\\TypoScript\\ConditionMatching\\Fixtures\\TestCondition = 7, != 6]');