2 namespace TYPO3\CMS\Backend\Tests\Unit\Configuration\TypoScript\ConditionMatching
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
16 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication
;
17 use TYPO3\CMS\Core\Utility\GeneralUtility
;
20 * Testcase for class \TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher.
22 * @author Oliver Hader <oliver@typo3.org>
24 class ConditionMatcherTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
32 * @var \TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher
34 protected $matchCondition;
39 protected $testGlobalNamespace;
44 protected $testTableName;
49 public function setUp() {
50 $this->testTableName
= 'conditionMatcherTestTable';
51 $this->testGlobalNamespace
= uniqid('TEST');
52 $GLOBALS['TCA'][$this->testTableName
] = array('ctrl' => array());
53 $GLOBALS[$this->testGlobalNamespace
] = array();
54 $this->setUpBackend();
55 $this->matchCondition
= $this->getMock(\TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher
::class, array('determineRootline'), array(), '', FALSE);
61 private function setUpBackend() {
62 $this->rootline
= array(
63 2 => array('uid' => 121, 'pid' => 111),
64 1 => array('uid' => 111, 'pid' => 101),
65 0 => array('uid' => 101, 'pid' => 0)
67 $GLOBALS['BE_USER'] = $this->getMock(BackendUserAuthentication
::class, array('dummy'), array(), '', FALSE);
71 * Set up database mock
73 private function setUpDatabaseMockForDeterminePageId() {
74 $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection
::class, array('exec_SELECTquery', 'sql_fetch_assoc', 'sql_free_result'));
75 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTquery')->will($this->returnCallback(array($this, 'determinePageIdByRecordDatabaseExecuteCallback')));
76 $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_fetch_assoc')->will($this->returnCallback(array($this, 'determinePageIdByRecordDatabaseFetchCallback')));
80 * Tests whether a faulty expression fails.
84 public function simulateDisabledMatchAllConditionsFailsOnFaultyExpression() {
85 $this->assertFalse($this->matchCondition
->match('[nullCondition = This expression would return FALSE in general]'));
89 * Tests whether simulating positive matches for all conditions succeeds.
93 public function simulateEnabledMatchAllConditionsSucceeds() {
94 $this->matchCondition
->setSimulateMatchResult(TRUE);
95 $this->assertTrue($this->matchCondition
->match('[nullCondition = This expression would return FALSE in general]'));
99 * Tests whether simulating positive matches for specific conditions succeeds.
103 public function simulateEnabledMatchSpecificConditionsSucceeds() {
104 $testCondition = '[' . uniqid('test') . ' = Any condition to simulate a positive match]';
105 $this->matchCondition
->setSimulateMatchConditions(array($testCondition));
106 $this->assertTrue($this->matchCondition
->match($testCondition));
110 * Tests whether a condition matches Internet Explorer 7 on Windows.
115 public function conditionMatchesInternetExplorer7Windows() {
116 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)';
117 $result = $this->matchCondition
->match('[browser = msie] && [version = 7] && [system = winNT]');
118 $this->assertTrue($result);
122 * Tests whether a condition does not match Internet Explorer 7 on Windows.
127 public function conditionDoesNotMatchInternetExplorer7Windows() {
128 $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.25 (Windows NT 6.0; U; en)';
129 $result = $this->matchCondition
->match('[browser = msie] && [version = 7] && [system = winNT]');
130 $this->assertFalse($result);
134 * Tests whether a condition does match the iOS with the correct and more recent 'iOS'
138 public function conditionDoesMatchIosWithCorrectSystemKey() {
139 $_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';
140 $result = $this->matchCondition
->match('[system = iOS]');
141 $this->assertTrue($result);
145 * Tests whether a condition does match the iOS with the old 'mac'
149 public function conditionDoesMatchIosWithOldSystemKey() {
150 $_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';
151 $result = $this->matchCondition
->match('[system = mac]');
152 $this->assertTrue($result);
156 * Tests whether a condition does match Windows 2000 with the correct and more recent 'win2k'
160 public function conditionDoesMatchWindows2kWithNewSystemKey() {
161 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; SV1)';
162 $result = $this->matchCondition
->match('[system = win2k]');
163 $this->assertTrue($result);
167 * Tests whether a condition does match Windows 2000 with the old 'winNT'
171 public function conditionDoesMatchWindows2kWithOldSystemKey() {
172 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; SV1)';
173 $result = $this->matchCondition
->match('[system = winNT]');
174 $this->assertTrue($result);
178 * Tests whether a condition does match Windows NT with 'winNT'
182 public function conditionDoesMatchWindowsNtWithSystemKey() {
183 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0)';
184 $result = $this->matchCondition
->match('[system = winNT]');
185 $this->assertTrue($result);
189 * Tests whether a condition does match Android with the correct and more recent 'android'
193 public function conditionDoesMatchAndroidWithNewSystemKey() {
194 $_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';
195 $result = $this->matchCondition
->match('[system = android]');
196 $this->assertTrue($result);
200 * Tests whether a condition does match Android with the old 'linux'
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);
211 * Tests whether a device type condition matches a crawler.
215 public function deviceConditionMatchesRobot() {
216 $_SERVER['HTTP_USER_AGENT'] = 'Googlebot/2.1 (+http://www.google.com/bot.html)';
217 $result = $this->matchCondition
->match('[device = robot]');
218 $this->assertTrue($result);
222 * Tests whether a device type condition does not match a crawler.
226 public function deviceConditionDoesNotMatchRobot() {
227 $_SERVER['HTTP_USER_AGENT'] = md5('Some strange user agent');
228 $result = $this->matchCondition
->match('[device = robot]');
229 $this->assertFalse($result);
233 * Tests whether the language comparison matches.
237 public function languageConditionMatchesSingleLanguageExpression() {
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 = *de*]'));
240 $this->assertTrue($this->matchCondition
->match('[language = *de-de*]'));
244 * Tests whether the language comparison matches.
248 public function languageConditionMatchesMultipleLanguagesExpression() {
249 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
250 $this->assertTrue($this->matchCondition
->match('[language = *en*,*de*]'));
251 $this->assertTrue($this->matchCondition
->match('[language = *en-us*,*de-de*]'));
255 * Tests whether the language comparison matches.
259 public function languageConditionMatchesCompleteLanguagesExpression() {
260 $this->markTestSkipped('This comparison seems to be incomplete in \TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher.');
261 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
262 $this->assertTrue($this->matchCondition
->match('[language = de-de,de;q=0.8]'));
266 * Tests whether usergroup comparison matches.
270 public function usergroupConditionMatchesSingleGroupId() {
271 $GLOBALS['BE_USER']->groupList
= '13,14,15';
272 $this->assertTrue($this->matchCondition
->match('[usergroup = 13]'));
276 * Tests whether usergroup comparison matches.
280 public function usergroupConditionMatchesMultipleUserGroupId() {
281 $GLOBALS['BE_USER']->groupList
= '13,14,15';
282 $this->assertTrue($this->matchCondition
->match('[usergroup = 999,15,14,13]'));
286 * Tests whether user comparison matches.
290 public function loginUserConditionMatchesAnyLoggedInUser() {
291 $GLOBALS['BE_USER']->user
['uid'] = 13;
292 $this->assertTrue($this->matchCondition
->match('[loginUser = *]'));
296 * Tests whether user comparison matches.
300 public function loginUserConditionMatchesSingleLoggedInUser() {
301 $GLOBALS['BE_USER']->user
['uid'] = 13;
302 $this->assertTrue($this->matchCondition
->match('[loginUser = 13]'));
306 * Tests whether user comparison matches.
310 public function loginUserConditionDoesNotMatchSingleLoggedInUser() {
311 $GLOBALS['BE_USER']->user
['uid'] = 13;
312 $this->assertFalse($this->matchCondition
->match('[loginUser = 999]'));
316 * Tests whether user comparison matches.
320 public function loginUserConditionMatchesMultipleLoggedInUsers() {
321 $GLOBALS['BE_USER']->user
['uid'] = 13;
322 $this->assertTrue($this->matchCondition
->match('[loginUser = 999,13]'));
326 * Tests whether checkinf for an admin user matches
330 public function adminUserConditionMatchesAdminUser() {
331 $GLOBALS['BE_USER']->user
['uid'] = 13;
332 $GLOBALS['BE_USER']->user
['admin'] = 1;
333 $this->assertTrue($this->matchCondition
->match('[adminUser = 1]'));
337 * Tests whether checkinf for an admin user matches
341 public function adminUserConditionMatchesRegularUser() {
342 $GLOBALS['BE_USER']->user
['uid'] = 14;
343 $GLOBALS['BE_USER']->user
['admin'] = 0;
344 $this->assertTrue($this->matchCondition
->match('[adminUser = 0]'));
348 * Tests whether checkinf for an admin user matches
352 public function adminUserConditionDoesNotMatchRegularUser() {
353 $GLOBALS['BE_USER']->user
['uid'] = 14;
354 $GLOBALS['BE_USER']->user
['admin'] = 0;
355 $this->assertFalse($this->matchCondition
->match('[adminUser = 1]'));
359 * Tests whether numerical comparison matches.
363 public function globalVarConditionMatchesOnEqualExpression() {
364 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10 = 10]'), '1');
365 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.1 = 10.1]'), '2');
366 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10 == 10]'), '3');
367 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.1 == 10.1]'), '4');
371 * Tests whether numerical comparison matches.
375 public function globalVarConditionMatchesOnEqualExpressionWithMultipleValues() {
376 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10 = 10|20|30]'));
377 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.1 = 10.1|20.2|30.3]'));
378 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:20 = 10|20|30]'));
379 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:20.2 = 10.1|20.2|30.3]'));
380 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10 == 10|20|30]'));
381 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.1 == 10.1|20.2|30.3]'));
382 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:20 == 10|20|30]'));
383 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:20.2 == 10.1|20.2|30.3]'));
387 * Tests whether numerical comparison matches.
391 public function globalVarConditionMatchesOnNotEqualExpression() {
392 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10 != 20]'));
393 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.1 != 10.2]'));
397 * Tests whether numerical comparison does not match.
401 public function globalVarConditionDoesNotMatchOnNotEqualExpression() {
402 $this->assertFalse($this->matchCondition
->match('[globalVar = LIT:10 != 10]'));
406 * Tests whether numerical comparison matches.
410 public function globalVarConditionMatchesOnNotEqualExpressionWithMultipleValues() {
411 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10 != 20|30]'));
412 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.1 != 10.2|20.3]'));
416 * Tests whether numerical comparison matches.
420 public function globalVarConditionMatchesOnLowerThanExpression() {
421 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10 < 20]'));
422 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.1 < 10.2]'));
426 * Tests whether numerical comparison matches.
430 public function globalVarConditionMatchesOnLowerThanOrEqualExpression() {
431 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10 <= 10]'));
432 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10 <= 20]'));
433 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.1 <= 10.1]'));
434 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.1 <= 10.2]'));
438 * Tests whether numerical comparison matches.
442 public function globalVarConditionMatchesOnGreaterThanExpression() {
443 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:20 > 10]'));
444 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.2 > 10.1]'));
448 * Tests whether numerical comparison matches.
452 public function globalVarConditionMatchesOnGreaterThanOrEqualExpression() {
453 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10 >= 10]'));
454 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:20 >= 10]'));
455 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.1 >= 10.1]'));
456 $this->assertTrue($this->matchCondition
->match('[globalVar = LIT:10.2 >= 10.1]'));
460 * Tests whether numerical comparison matches.
464 public function globalVarConditionMatchesOnEmptyExpressionWithNoValueSet() {
465 $testKey = uniqid('test');
466 $this->assertTrue($this->matchCondition
->match('[globalVar = GP:' . $testKey . '=]'));
467 $this->assertTrue($this->matchCondition
->match('[globalVar = GP:' . $testKey . ' = ]'));
471 * Tests whether numerical comparison matches.
475 public function globalVarConditionDoesNotMatchOnEmptyExpressionWithValueSetToZero() {
476 $testKey = uniqid('test');
478 $_POST = array($testKey => 0);
479 $this->assertFalse($this->matchCondition
->match('[globalVar = GP:' . $testKey . '=]'));
480 $this->assertFalse($this->matchCondition
->match('[globalVar = GP:' . $testKey . ' = ]'));
484 * Tests whether string comparison matches.
488 public function globalStringConditionMatchesOnEqualExpression() {
489 $this->assertTrue($this->matchCondition
->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.Test.Condition]'));
490 $this->assertFalse($this->matchCondition
->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3]'));
494 * Tests whether string comparison matches.
498 public function globalStringConditionMatchesOnEmptyExpressionWithValueSetToEmptyString() {
499 $testKey = uniqid('test');
501 $_POST = array($testKey => '');
502 $this->assertTrue($this->matchCondition
->match('[globalString = GP:' . $testKey . '=]'));
503 $this->assertTrue($this->matchCondition
->match('[globalString = GP:' . $testKey . ' = ]'));
507 * Tests whether string comparison matches.
511 public function globalStringConditionMatchesOnEmptyLiteralExpressionWithValueSetToEmptyString() {
512 $this->assertTrue($this->matchCondition
->match('[globalString = LIT:=]'));
513 $this->assertTrue($this->matchCondition
->match('[globalString = LIT: = ]'));
517 * Tests whether string comparison matches.
521 public function globalStringConditionMatchesWildcardExpression() {
522 $this->assertTrue($this->matchCondition
->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]'));
523 $this->assertTrue($this->matchCondition
->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]'));
524 $this->assertTrue($this->matchCondition
->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?T*t?Condition]'));
528 * Tests whether string comparison matches.
532 public function globalStringConditionMatchesRegularExpression() {
533 $this->assertTrue($this->matchCondition
->match('[globalString = LIT:TYPO3.Test.Condition = /^[A-Za-z3.]+$/]'));
534 $this->assertTrue($this->matchCondition
->match('[globalString = LIT:TYPO3.Test.Condition = /^TYPO3\\..+Condition$/]'));
535 $this->assertFalse($this->matchCondition
->match('[globalString = LIT:TYPO3.Test.Condition = /^FALSE/]'));
539 * Tests whether string comparison matches.
543 public function globalStringConditionMatchesEmptyRegularExpression() {
544 $testKey = uniqid('test');
545 $_SERVER[$testKey] = '';
546 $this->assertTrue($this->matchCondition
->match('[globalString = _SERVER|' . $testKey . ' = /^$/]'));
550 * Tests whether treeLevel comparison matches.
554 public function treeLevelConditionMatchesSingleValue() {
555 $this->matchCondition
->setRootline($this->rootline
);
556 $this->assertTrue($this->matchCondition
->match('[treeLevel = 2]'));
560 * Tests whether treeLevel comparison matches.
564 public function treeLevelConditionMatchesMultipleValues() {
565 $this->matchCondition
->setRootline($this->rootline
);
566 $this->assertTrue($this->matchCondition
->match('[treeLevel = 999,998,2]'));
570 * Tests whether treeLevel comparison matches.
574 public function treeLevelConditionDoesNotMatchFaultyValue() {
575 $this->matchCondition
->setRootline($this->rootline
);
576 $this->assertFalse($this->matchCondition
->match('[treeLevel = 999]'));
580 * Tests whether treeLevel comparison matches when creating new pages.
584 public function treeLevelConditionMatchesCurrentPageIdWhileEditingNewPage() {
585 $GLOBALS['SOBE'] = $this->getMock(\TYPO3\CMS\Backend\Controller\EditDocumentController
::class, array(), array(), '', FALSE);
586 $GLOBALS['SOBE']->elementsData
= array(
589 'uid' => 'NEW4adc6021e37e7',
595 $GLOBALS['SOBE']->data
= array();
596 $this->matchCondition
->setRootline($this->rootline
);
597 $this->matchCondition
->setPageId(121);
598 $this->assertTrue($this->matchCondition
->match('[treeLevel = 3]'));
602 * Tests whether treeLevel comparison matches when creating new pages.
606 public function treeLevelConditionMatchesCurrentPageIdWhileSavingNewPage() {
607 $GLOBALS['SOBE'] = $this->getMock(\TYPO3\CMS\Backend\Controller\EditDocumentController
::class, array(), array(), '', FALSE);
608 $GLOBALS['SOBE']->elementsData
= array(
611 /// 999 is the uid of the page that was just created
618 $GLOBALS['SOBE']->data
= array(
620 'NEW4adc6021e37e7' => array(
625 $this->matchCondition
->setRootline($this->rootline
);
626 $this->matchCondition
->setPageId(121);
627 $this->assertTrue($this->matchCondition
->match('[treeLevel = 3]'));
631 * Tests whether a page Id is found in the previous rootline entries.
635 public function PIDupinRootlineConditionMatchesSinglePageIdInRootline() {
636 $this->matchCondition
->setRootline($this->rootline
);
637 $this->matchCondition
->setPageId(121);
638 $this->assertTrue($this->matchCondition
->match('[PIDupinRootline = 111]'));
642 * Tests whether a page Id is found in the previous rootline entries.
646 public function PIDupinRootlineConditionMatchesMultiplePageIdsInRootline() {
647 $this->matchCondition
->setRootline($this->rootline
);
648 $this->matchCondition
->setPageId(121);
649 $this->assertTrue($this->matchCondition
->match('[PIDupinRootline = 999,111,101]'));
653 * Tests whether a page Id is found in the previous rootline entries.
657 public function PIDupinRootlineConditionDoesNotMatchPageIdNotInRootline() {
658 $this->matchCondition
->setRootline($this->rootline
);
659 $this->matchCondition
->setPageId(121);
660 $this->assertFalse($this->matchCondition
->match('[PIDupinRootline = 999]'));
664 * Tests whether a page Id is found in the previous rootline entries.
668 public function PIDupinRootlineConditionDoesNotMatchLastPageIdInRootline() {
669 $this->matchCondition
->setRootline($this->rootline
);
670 $this->matchCondition
->setPageId(121);
671 $this->assertFalse($this->matchCondition
->match('[PIDupinRootline = 121]'));
675 * Tests whether a page Id is found in the previous rootline entries.
679 public function PIDupinRootlineConditionMatchesCurrentPageIdWhileEditingNewPage() {
680 $GLOBALS['SOBE'] = $this->getMock(\TYPO3\CMS\Backend\Controller\EditDocumentController
::class, array(), array(), '', FALSE);
681 $GLOBALS['SOBE']->elementsData
= array(
684 'uid' => 'NEW4adc6021e37e7',
690 $GLOBALS['SOBE']->data
= array();
691 $this->matchCondition
->setRootline($this->rootline
);
692 $this->matchCondition
->setPageId(121);
693 $this->assertTrue($this->matchCondition
->match('[PIDupinRootline = 121]'));
697 * Tests whether a page Id is found in the previous rootline entries.
701 public function PIDupinRootlineConditionMatchesCurrentPageIdWhileSavingNewPage() {
702 $GLOBALS['SOBE'] = $this->getMock(\TYPO3\CMS\Backend\Controller\EditDocumentController
::class, array(), array(), '', FALSE);
703 $GLOBALS['SOBE']->elementsData
= array(
706 /// 999 is the uid of the page that was just created
713 $GLOBALS['SOBE']->data
= array(
715 'NEW4adc6021e37e7' => array(
720 $this->matchCondition
->setRootline($this->rootline
);
721 $this->matchCondition
->setPageId(121);
722 $this->assertTrue($this->matchCondition
->match('[PIDupinRootline = 121]'));
726 * Tests whether a page Id is found in all rootline entries.
730 public function PIDinRootlineConditionMatchesSinglePageIdInRootline() {
731 $this->matchCondition
->setRootline($this->rootline
);
732 $this->matchCondition
->setPageId(121);
733 $this->assertTrue($this->matchCondition
->match('[PIDinRootline = 111]'));
737 * Tests whether a page Id is found in all rootline entries.
741 public function PIDinRootlineConditionMatchesMultiplePageIdsInRootline() {
742 $this->matchCondition
->setRootline($this->rootline
);
743 $this->matchCondition
->setPageId(121);
744 $this->assertTrue($this->matchCondition
->match('[PIDinRootline = 999,111,101]'));
748 * Tests whether a page Id is found in all rootline entries.
752 public function PIDinRootlineConditionMatchesLastPageIdInRootline() {
753 $this->matchCondition
->setRootline($this->rootline
);
754 $this->matchCondition
->setPageId(121);
755 $this->assertTrue($this->matchCondition
->match('[PIDinRootline = 121]'));
759 * Tests whether a page Id is found in all rootline entries.
763 public function PIDinRootlineConditionDoesNotMatchPageIdNotInRootline() {
764 $this->matchCondition
->setRootline($this->rootline
);
765 $this->matchCondition
->setPageId(121);
766 $this->assertFalse($this->matchCondition
->match('[PIDinRootline = 999]'));
770 * Tests whether the compatibility version can be evaluated.
771 * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
775 public function compatVersionConditionMatchesOlderRelease() {
776 $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
777 $this->assertTrue($this->matchCondition
->match('[compatVersion = 4.0]'));
781 * Tests whether the compatibility version can be evaluated.
782 * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
786 public function compatVersionConditionMatchesSameRelease() {
787 $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
788 $this->assertTrue($this->matchCondition
->match('[compatVersion = 4.9]'));
792 * Tests whether the compatibility version can be evaluated.
793 * (e.g. 4.9 is compatible to 4.0 but not to 5.0)
797 public function compatVersionConditionDoesNotMatchNewerRelease() {
798 $GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version'] = '4.9';
799 $this->assertFalse($this->matchCondition
->match('[compatVersion = 5.0]'));
803 * Tests whether the generic fetching of variables works with the namespace 'GP'.
807 public function genericGetVariablesSucceedsWithNamespaceGP() {
808 $_GET = array('testGet' => 'getTest');
809 $_POST = array('testPost' => 'postTest');
810 $this->assertTrue($this->matchCondition
->match('[globalString = GP:testGet = getTest]'));
811 $this->assertTrue($this->matchCondition
->match('[globalString = GP:testPost = postTest]'));
815 * Tests whether the generic fetching of variables does not work with the namespace 'TSFE',
816 * since we are in the backend context here.
820 public function genericGetVariablesFailsWithNamespaceTSFE() {
821 $GLOBALS['TSFE'] = new \
stdClass();
822 $GLOBALS['TSFE']->id
= 1234567;
823 $this->assertFalse($this->matchCondition
->match('[globalString = TSFE:id = 1234567]'));
827 * Tests whether the generic fetching of variables works with the namespace 'ENV'.
831 public function genericGetVariablesSucceedsWithNamespaceENV() {
832 $testKey = uniqid('test');
833 putenv($testKey . '=testValue');
834 $this->assertTrue($this->matchCondition
->match('[globalString = ENV:' . $testKey . ' = testValue]'));
838 * Tests whether the generic fetching of variables works with the namespace 'IENV'.
842 public function genericGetVariablesSucceedsWithNamespaceIENV() {
843 $_SERVER['HTTP_HOST'] = GeneralUtility
::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567';
844 $this->assertTrue($this->matchCondition
->match('[globalString = IENV:TYPO3_PORT = 1234567]'));
848 * Tests whether the generic fetching of variables works with any global namespace.
852 public function genericGetVariablesSucceedsWithAnyGlobalNamespace() {
853 $GLOBALS[$this->testGlobalNamespace
] = array(
854 'first' => 'testFirst',
855 'second' => array('third' => 'testThird')
857 $this->assertTrue($this->matchCondition
->match('[globalString = ' . $this->testGlobalNamespace
. '|first = testFirst]'));
858 $this->assertTrue($this->matchCondition
->match('[globalString = ' . $this->testGlobalNamespace
. '|second|third = testThird]'));
862 * Tests whether determining a pageId works.
866 public function pageIdCanBeDeterminedWhileCallingModuleWithPageTree() {
868 $this->matchCondition
->match('[globalVar = LIT:10 = 10]');
869 $this->assertEquals(999, $this->matchCondition
->getPageId());
873 * Tests whether determining a pageId works.
877 public function pageIdCanBeDeterminedWhileEditingAPageRecord() {
878 $_GET['edit']['pages'][999] = 'edit';
879 $this->matchCondition
->match('[globalVar = LIT:10 = 10]');
880 $this->assertEquals(999, $this->matchCondition
->getPageId());
884 * Tests whether determining a pageId works.
888 public function pageIdCanBeDeterminedWhileEditingARegularRecord() {
889 $this->setUpDatabaseMockForDeterminePageId();
890 $_GET['edit'][$this->testTableName
][13] = 'edit';
891 $this->matchCondition
->match('[globalVar = LIT:10 = 10]');
892 $this->assertEquals(999, $this->matchCondition
->getPageId());
896 * Tests whether determining a pageId works.
900 public function pageIdCanBeDeterminedWhileCreatingARecord() {
901 $_GET['edit']['pages'][999] = 'new';
902 $this->matchCondition
->match('[globalVar = LIT:10 = 10]');
903 $this->assertEquals(999, $this->matchCondition
->getPageId());
907 * Tests whether determining a pageId works.
911 public function pageIdCanBeDeterminedWhileCreatingARecordAfterAnExistingRecord() {
912 $this->setUpDatabaseMockForDeterminePageId();
913 $_GET['edit'][$this->testTableName
][-13] = 'new';
914 $this->matchCondition
->match('[globalVar = LIT:10 = 10]');
915 $this->assertEquals(999, $this->matchCondition
->getPageId());
919 * Tests whether determining a pageId works.
923 public function pageIdCanBeDeterminedWhileDeletingAPageRecord() {
924 $_GET['cmd']['pages'][999]['delete'] = 1;
925 $this->matchCondition
->match('[globalVar = LIT:10 = 10]');
926 $this->assertEquals(999, $this->matchCondition
->getPageId());
930 * Tests whether determining a pageId works.
934 public function pageIdCanBeDeterminedWhileCopyingARecordToAnotherPage() {
935 $_GET['cmd']['pages'][121]['copy'] = 999;
936 $this->matchCondition
->match('[globalVar = LIT:10 = 10]');
937 $this->assertEquals(999, $this->matchCondition
->getPageId());
941 * Tests whether determining a pageId works.
945 public function pageIdCanBeDeterminedWhileCopyingARecordAfterAnExistingRecord() {
946 $this->setUpDatabaseMockForDeterminePageId();
947 $_GET['cmd'][$this->testTableName
][121]['copy'] = -13;
948 $this->matchCondition
->match('[globalVar = LIT:10 = 10]');
949 $this->assertEquals(999, $this->matchCondition
->getPageId());
953 * Tests whether determining a pageId works.
957 public function pageIdCanBeDeterminedWhileMovingARecordToAnotherPage() {
958 $_GET['cmd']['pages'][121]['move'] = 999;
959 $this->matchCondition
->match('[globalVar = LIT:10 = 10]');
960 $this->assertEquals(999, $this->matchCondition
->getPageId());
964 * Callback method for pageIdCanBeDetermined test cases.
965 * Simulates TYPO3_DB->exec_SELECTquery().
967 * @param string $fields
968 * @param string $table
969 * @param string $where
972 public function determinePageIdByRecordDatabaseExecuteCallback($fields, $table, $where) {
973 if ($table === $this->testTableName
) {
975 'scope' => $this->testTableName
,
986 * Callback method for pageIdCanBeDetermined test cases.
987 * Simulates TYPO3_DB->sql_fetch_assoc().
989 * @param mixed $resource
992 public function determinePageIdByRecordDatabaseFetchCallback($resource) {
993 if (is_array($resource) && $resource['scope'] === $this->testTableName
) {
994 return $resource['data'];