2 namespace TYPO3\CMS\Backend\Tests\Unit\Configuration\TypoScript\ConditionMatching;
50 $this->testTableName =
'conditionMatcherTestTable';
51 $this->testGlobalNamespace = $this->getUniqueId(
'TEST');
56 $this->matchCondition = $this->getMock(\TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher::class, array(
'determineRootline'), array(),
'',
false);
64 $this->rootline = array(
65 2 => array(
'uid' => 121,
'pid' => 111),
66 1 => array(
'uid' => 111,
'pid' => 101),
67 0 => array(
'uid' => 101,
'pid' => 0)
69 $GLOBALS[
'BE_USER'] = $this->getMock(BackendUserAuthentication::class, array(
'dummy'), array(),
'',
false);
77 $GLOBALS[
'TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, array(
'exec_SELECTquery',
'sql_fetch_assoc',
'sql_free_result'));
78 $GLOBALS[
'TYPO3_DB']->expects($this->any())->method(
'exec_SELECTquery')->will($this->returnCallback(array($this,
'determinePageIdByRecordDatabaseExecuteCallback')));
79 $GLOBALS[
'TYPO3_DB']->expects($this->any())->method(
'sql_fetch_assoc')->will($this->returnCallback(array($this,
'determinePageIdByRecordDatabaseFetchCallback')));
89 $this->assertFalse($this->matchCondition->match(
'[nullCondition = This expression would return FALSE in general]'));
99 $this->matchCondition->setSimulateMatchResult(
true);
100 $this->assertTrue($this->matchCondition->match(
'[nullCondition = This expression would return FALSE in general]'));
110 $testCondition =
'[' . $this->getUniqueId(
'test') .
' = Any condition to simulate a positive match]';
111 $this->matchCondition->setSimulateMatchConditions(array($testCondition));
112 $this->assertTrue($this->matchCondition->match($testCondition));
123 $_SERVER[
'HTTP_USER_AGENT'] =
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)';
124 $result = $this->matchCondition->match(
'[browser = msie] && [version = 7] && [system = winNT]');
125 $this->assertTrue($result);
136 $_SERVER[
'HTTP_USER_AGENT'] =
'Opera/9.25 (Windows NT 6.0; U; en)';
137 $result = $this->matchCondition->match(
'[browser = msie] && [version = 7] && [system = winNT]');
138 $this->assertFalse($result);
148 $_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';
149 $result = $this->matchCondition->match(
'[system = iOS]');
150 $this->assertTrue($result);
160 $_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';
161 $result = $this->matchCondition->match(
'[system = mac]');
162 $this->assertTrue($result);
172 $_SERVER[
'HTTP_USER_AGENT'] =
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; SV1)';
173 $result = $this->matchCondition->match(
'[system = win2k]');
174 $this->assertTrue($result);
184 $_SERVER[
'HTTP_USER_AGENT'] =
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; SV1)';
185 $result = $this->matchCondition->match(
'[system = winNT]');
186 $this->assertTrue($result);
196 $_SERVER[
'HTTP_USER_AGENT'] =
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0)';
197 $result = $this->matchCondition->match(
'[system = winNT]');
198 $this->assertTrue($result);
208 $_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';
209 $result = $this->matchCondition->match(
'[system = android]');
210 $this->assertTrue($result);
220 $_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';
221 $result = $this->matchCondition->match(
'[system = linux]');
222 $this->assertTrue($result);
232 $_SERVER[
'HTTP_USER_AGENT'] =
'Googlebot/2.1 (+http://www.google.com/bot.html)';
233 $result = $this->matchCondition->match(
'[device = robot]');
234 $this->assertTrue($result);
244 $_SERVER[
'HTTP_USER_AGENT'] = md5(
'Some strange user agent');
245 $result = $this->matchCondition->match(
'[device = robot]');
246 $this->assertFalse($result);
256 $_SERVER[
'HTTP_ACCEPT_LANGUAGE'] =
'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
257 $this->assertTrue($this->matchCondition->match(
'[language = *de*]'));
258 $this->assertTrue($this->matchCondition->match(
'[language = *de-de*]'));
268 $_SERVER[
'HTTP_ACCEPT_LANGUAGE'] =
'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
269 $this->assertTrue($this->matchCondition->match(
'[language = *en*,*de*]'));
270 $this->assertTrue($this->matchCondition->match(
'[language = *en-us*,*de-de*]'));
280 $this->markTestSkipped(
'This comparison seems to be incomplete in \TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher.');
281 $_SERVER[
'HTTP_ACCEPT_LANGUAGE'] =
'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
282 $this->assertTrue($this->matchCondition->match(
'[language = de-de,de;q=0.8]'));
292 $GLOBALS[
'BE_USER']->groupList =
'13,14,15';
293 $this->assertTrue($this->matchCondition->match(
'[usergroup = 13]'));
303 $GLOBALS[
'BE_USER']->groupList =
'13,14,15';
304 $this->assertTrue($this->matchCondition->match(
'[usergroup = 999,15,14,13]'));
314 $GLOBALS[
'BE_USER']->user[
'uid'] = 13;
315 $this->assertTrue($this->matchCondition->match(
'[loginUser = *]'));
325 $GLOBALS[
'BE_USER']->user[
'uid'] = 13;
326 $this->assertTrue($this->matchCondition->match(
'[loginUser = 13]'));
336 $GLOBALS[
'BE_USER']->user[
'uid'] = 13;
337 $this->assertFalse($this->matchCondition->match(
'[loginUser = 999]'));
347 $GLOBALS[
'BE_USER']->user[
'uid'] = 13;
348 $this->assertTrue($this->matchCondition->match(
'[loginUser = 999,13]'));
358 $GLOBALS[
'BE_USER']->user[
'uid'] = 13;
359 $GLOBALS[
'BE_USER']->user[
'admin'] = 1;
360 $this->assertTrue($this->matchCondition->match(
'[adminUser = 1]'));
370 $GLOBALS[
'BE_USER']->user[
'uid'] = 14;
371 $GLOBALS[
'BE_USER']->user[
'admin'] = 0;
372 $this->assertTrue($this->matchCondition->match(
'[adminUser = 0]'));
382 $GLOBALS[
'BE_USER']->user[
'uid'] = 14;
383 $GLOBALS[
'BE_USER']->user[
'admin'] = 0;
384 $this->assertFalse($this->matchCondition->match(
'[adminUser = 1]'));
394 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 = 10]'),
'1');
395 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 = 10.1]'),
'2');
396 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 == 10]'),
'3');
397 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 == 10.1]'),
'4');
407 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 = 10|20|30]'));
408 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 = 10.1|20.2|30.3]'));
409 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:20 = 10|20|30]'));
410 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:20.2 = 10.1|20.2|30.3]'));
411 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 == 10|20|30]'));
412 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 == 10.1|20.2|30.3]'));
413 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:20 == 10|20|30]'));
414 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:20.2 == 10.1|20.2|30.3]'));
424 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 != 20]'));
425 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 != 10.2]'));
435 $this->assertFalse($this->matchCondition->match(
'[globalVar = LIT:10 != 10]'));
445 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 != 20|30]'));
446 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 != 10.2|20.3]'));
456 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 < 20]'));
457 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 < 10.2]'));
467 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 <= 10]'));
468 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 <= 20]'));
469 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 <= 10.1]'));
470 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 <= 10.2]'));
480 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:20 > 10]'));
481 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.2 > 10.1]'));
491 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10 >= 10]'));
492 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:20 >= 10]'));
493 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.1 >= 10.1]'));
494 $this->assertTrue($this->matchCondition->match(
'[globalVar = LIT:10.2 >= 10.1]'));
504 $testKey = $this->getUniqueId(
'test');
505 $this->assertTrue($this->matchCondition->match(
'[globalVar = GP:' . $testKey .
'=]'));
506 $this->assertTrue($this->matchCondition->match(
'[globalVar = GP:' . $testKey .
' = ]'));
516 $testKey = $this->getUniqueId(
'test');
518 $_POST = array($testKey => 0);
519 $this->assertFalse($this->matchCondition->match(
'[globalVar = GP:' . $testKey .
'=]'));
520 $this->assertFalse($this->matchCondition->match(
'[globalVar = GP:' . $testKey .
' = ]'));
530 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = TYPO3.Test.Condition]'));
531 $this->assertFalse($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = TYPO3]'));
541 $testKey = $this->getUniqueId(
'test');
543 $_POST = array($testKey =>
'');
544 $this->assertTrue($this->matchCondition->match(
'[globalString = GP:' . $testKey .
'=]'));
545 $this->assertTrue($this->matchCondition->match(
'[globalString = GP:' . $testKey .
' = ]'));
555 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT:=]'));
556 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT: = ]'));
566 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]'));
567 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]'));
568 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = TYPO3?T*t?Condition]'));
578 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = /^[A-Za-z3.]+$/]'));
579 $this->assertTrue($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = /^TYPO3\\..+Condition$/]'));
580 $this->assertFalse($this->matchCondition->match(
'[globalString = LIT:TYPO3.Test.Condition = /^FALSE/]'));
590 $testKey = $this->getUniqueId(
'test');
591 $_SERVER[$testKey] =
'';
592 $this->assertTrue($this->matchCondition->match(
'[globalString = _SERVER|' . $testKey .
' = /^$/]'));
602 $this->matchCondition->setRootline($this->rootline);
603 $this->assertTrue($this->matchCondition->match(
'[treeLevel = 2]'));
613 $this->matchCondition->setRootline($this->rootline);
614 $this->assertTrue($this->matchCondition->match(
'[treeLevel = 999,998,2]'));
624 $this->matchCondition->setRootline($this->rootline);
625 $this->assertFalse($this->matchCondition->match(
'[treeLevel = 999]'));
635 $GLOBALS[
'SOBE'] = $this->getMock(\TYPO3\CMS\Backend\Controller\EditDocumentController::class, array(), array(),
'',
false);
636 $GLOBALS[
'SOBE']->elementsData = array(
639 'uid' =>
'NEW4adc6021e37e7',
646 $this->matchCondition->setRootline($this->rootline);
647 $this->matchCondition->setPageId(121);
648 $this->assertTrue($this->matchCondition->match(
'[treeLevel = 3]'));
658 $GLOBALS[
'SOBE'] = $this->getMock(\TYPO3\CMS\Backend\Controller\EditDocumentController::class, array(), array(),
'',
false);
659 $GLOBALS[
'SOBE']->elementsData = array(
671 'NEW4adc6021e37e7' => array(
676 $this->matchCondition->setRootline($this->rootline);
677 $this->matchCondition->setPageId(121);
678 $this->assertTrue($this->matchCondition->match(
'[treeLevel = 3]'));
688 $this->matchCondition->setRootline($this->rootline);
689 $this->matchCondition->setPageId(121);
690 $this->assertTrue($this->matchCondition->match(
'[PIDupinRootline = 111]'));
700 $this->matchCondition->setRootline($this->rootline);
701 $this->matchCondition->setPageId(121);
702 $this->assertTrue($this->matchCondition->match(
'[PIDupinRootline = 999,111,101]'));
712 $this->matchCondition->setRootline($this->rootline);
713 $this->matchCondition->setPageId(121);
714 $this->assertFalse($this->matchCondition->match(
'[PIDupinRootline = 999]'));
724 $this->matchCondition->setRootline($this->rootline);
725 $this->matchCondition->setPageId(121);
726 $this->assertFalse($this->matchCondition->match(
'[PIDupinRootline = 121]'));
736 $GLOBALS[
'SOBE'] = $this->getMock(\TYPO3\CMS\Backend\Controller\EditDocumentController::class, array(), array(),
'',
false);
737 $GLOBALS[
'SOBE']->elementsData = array(
740 'uid' =>
'NEW4adc6021e37e7',
747 $this->matchCondition->setRootline($this->rootline);
748 $this->matchCondition->setPageId(121);
749 $this->assertTrue($this->matchCondition->match(
'[PIDupinRootline = 121]'));
759 $GLOBALS[
'SOBE'] = $this->getMock(\TYPO3\CMS\Backend\Controller\EditDocumentController::class, array(), array(),
'',
false);
760 $GLOBALS[
'SOBE']->elementsData = array(
772 'NEW4adc6021e37e7' => array(
777 $this->matchCondition->setRootline($this->rootline);
778 $this->matchCondition->setPageId(121);
779 $this->assertTrue($this->matchCondition->match(
'[PIDupinRootline = 121]'));
789 $this->matchCondition->setRootline($this->rootline);
790 $this->matchCondition->setPageId(121);
791 $this->assertTrue($this->matchCondition->match(
'[PIDinRootline = 111]'));
801 $this->matchCondition->setRootline($this->rootline);
802 $this->matchCondition->setPageId(121);
803 $this->assertTrue($this->matchCondition->match(
'[PIDinRootline = 999,111,101]'));
813 $this->matchCondition->setRootline($this->rootline);
814 $this->matchCondition->setPageId(121);
815 $this->assertTrue($this->matchCondition->match(
'[PIDinRootline = 121]'));
825 $this->matchCondition->setRootline($this->rootline);
826 $this->matchCondition->setPageId(121);
827 $this->assertFalse($this->matchCondition->match(
'[PIDinRootline = 999]'));
838 $this->assertTrue($this->matchCondition->match(
'[compatVersion = 7.0]'));
849 $this->assertTrue($this->matchCondition->match(
'[compatVersion = ' . TYPO3_branch .
']'));
860 $this->assertFalse($this->matchCondition->match(
'[compatVersion = 15.0]'));
870 $_GET = array(
'testGet' =>
'getTest');
871 $_POST = array(
'testPost' =>
'postTest');
872 $this->assertTrue($this->matchCondition->match(
'[globalString = GP:testGet = getTest]'));
873 $this->assertTrue($this->matchCondition->match(
'[globalString = GP:testPost = postTest]'));
886 $this->assertFalse($this->matchCondition->match(
'[globalString = TSFE:id = 1234567]'));
896 $testKey = $this->getUniqueId(
'test');
897 putenv($testKey .
'=testValue');
898 $this->assertTrue($this->matchCondition->match(
'[globalString = ENV:' . $testKey .
' = testValue]'));
909 $this->assertTrue($this->matchCondition->match(
'[globalString = IENV:TYPO3_PORT = 1234567]'));
920 'first' =>
'testFirst',
921 'second' => array(
'third' =>
'testThird')
923 $this->assertTrue($this->matchCondition->match(
'[globalString = ' . $this->testGlobalNamespace .
'|first = testFirst]'));
924 $this->assertTrue($this->matchCondition->match(
'[globalString = ' . $this->testGlobalNamespace .
'|second|third = testThird]'));
935 $this->matchCondition->match(
'[globalVar = LIT:10 = 10]');
936 $this->assertEquals(999, $this->matchCondition->getPageId());
946 $_GET[
'edit'][
'pages'][999] =
'edit';
947 $this->matchCondition->match(
'[globalVar = LIT:10 = 10]');
948 $this->assertEquals(999, $this->matchCondition->getPageId());
960 $this->matchCondition->match(
'[globalVar = LIT:10 = 10]');
961 $this->assertEquals(999, $this->matchCondition->getPageId());
971 $_GET[
'edit'][
'pages'][999] =
'new';
972 $this->matchCondition->match(
'[globalVar = LIT:10 = 10]');
973 $this->assertEquals(999, $this->matchCondition->getPageId());
985 $this->matchCondition->match(
'[globalVar = LIT:10 = 10]');
986 $this->assertEquals(999, $this->matchCondition->getPageId());
996 $_GET[
'cmd'][
'pages'][999][
'delete'] = 1;
997 $this->matchCondition->match(
'[globalVar = LIT:10 = 10]');
998 $this->assertEquals(999, $this->matchCondition->getPageId());
1008 $_GET[
'cmd'][
'pages'][121][
'copy'] = 999;
1009 $this->matchCondition->match(
'[globalVar = LIT:10 = 10]');
1010 $this->assertEquals(999, $this->matchCondition->getPageId());
1022 $this->matchCondition->match(
'[globalVar = LIT:10 = 10]');
1023 $this->assertEquals(999, $this->matchCondition->getPageId());
1033 $_GET[
'cmd'][
'pages'][121][
'move'] = 999;
1034 $this->matchCondition->match(
'[globalVar = LIT:10 = 10]');
1035 $this->assertEquals(999, $this->matchCondition->getPageId());
1049 if ($table === $this->testTableName) {
1051 'scope' => $this->testTableName,
1070 if (is_array($resource) && $resource[
'scope'] === $this->testTableName) {
1071 return $resource[
'data'];
1083 $this->matchCondition->match(
'[TYPO3\\CMS\\Backend\\Tests\\Unit\\Configuration\\TypoScript\\ConditionMatching\\Fixtures\\TestCondition = 7, != 6]');