2 declare(strict_types
= 1);
3 namespace TYPO3\CMS\Frontend\Tests\Unit\Configuration\TypoScript\ConditionMatching
;
6 * This file is part of the TYPO3 CMS project.
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
15 * The TYPO3 project - inspiring people to share!
18 use Prophecy\Argument
;
19 use TYPO3\CMS\Core\Configuration\TypoScript\Exception\InvalidTypoScriptConditionException
;
20 use TYPO3\CMS\Core\Context\Context
;
21 use TYPO3\CMS\Core\Context\UserAspect
;
22 use TYPO3\CMS\Core\Http\ServerRequest
;
23 use TYPO3\CMS\Core\Site\Entity\Site
;
24 use TYPO3\CMS\Core\Utility\GeneralUtility
;
25 use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
;
26 use TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher
;
27 use TYPO3\CMS\Frontend\Tests\Unit\Configuration\TypoScript\ConditionMatching\Fixtures\TestConditionException
;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase
;
33 class ConditionMatcherTest
extends UnitTestCase
35 protected function setUp(): void
37 $this->testGlobalNamespace
= $this->getUniqueId('TEST');
38 GeneralUtility
::flushInternalRuntimeCaches();
39 $GLOBALS[$this->testGlobalNamespace
] = [];
40 $GLOBALS['TSFE'] = new \
stdClass();
41 $GLOBALS['TSFE']->tmpl
= new \
stdClass();
42 $GLOBALS['TSFE']->tmpl
->rootLine
= [
43 2 => ['uid' => 121, 'pid' => 111],
44 1 => ['uid' => 111, 'pid' => 101],
45 0 => ['uid' => 101, 'pid' => 0]
50 * Tests whether a faulty expression fails.
54 public function simulateDisabledMatchAllConditionsFailsOnFaultyExpression(): void
56 $subject = new ConditionMatcher(new Context());
57 $this->assertFalse($subject->match('[nullCondition = This expression would return FALSE in general]'));
61 * Tests whether simulating positive matches for all conditions succeeds.
65 public function simulateEnabledMatchAllConditionsSucceeds(): void
67 $subject = new ConditionMatcher(new Context());
68 $subject->setSimulateMatchResult(true
);
69 $this->assertTrue($subject->match('[nullCondition = This expression would return FALSE in general]'));
73 * Tests whether simulating positive matches for specific conditions succeeds.
77 public function simulateEnabledMatchSpecificConditionsSucceeds(): void
79 $subject = new ConditionMatcher(new Context());
80 $testCondition = '[' . $this->getUniqueId('test') . ' = Any condition to simulate a positive match]';
81 $subject->setSimulateMatchConditions([$testCondition]);
82 $this->assertTrue($subject->match($testCondition));
86 * Tests whether the language comparison matches.
90 public function languageConditionMatchesSingleLanguageExpression(): void
92 $subject = new ConditionMatcher(new Context());
93 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
94 $this->assertTrue($subject->match('[language = *de*]'));
95 $this->assertTrue($subject->match('[language = *de-de*]'));
99 * Tests whether the language comparison matches.
103 public function languageConditionMatchesMultipleLanguagesExpression(): void
105 $subject = new ConditionMatcher(new Context());
106 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
107 $this->assertTrue($subject->match('[language = *en*,*de*]'));
108 $this->assertTrue($subject->match('[language = *en-us*,*de-de*]'));
112 * Tests whether the language comparison matches.
116 public function languageConditionMatchesCompleteLanguagesExpression(): void
118 $subject = new ConditionMatcher(new Context());
119 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
120 $this->assertTrue($subject->match('[language = de-de,de;q=0.8,en-us;q=0.5,en;q=0.3]'));
124 * Tests whether usergroup comparison matches.
128 public function usergroupConditionMatchesSingleGroupId(): void
130 $subject = new ConditionMatcher(new Context([
131 'frontend.user' => new UserAspect(new FrontendUserAuthentication(), [13, 14, 15])
133 $this->assertTrue($subject->match('[usergroup = 13]'));
137 * Tests whether usergroup comparison matches.
141 public function usergroupConditionMatchesMultipleUserGroupId(): void
143 $subject = new ConditionMatcher(new Context([
144 'frontend.user' => new UserAspect(new FrontendUserAuthentication(), [13, 14, 15])
146 $this->assertTrue($subject->match('[usergroup = 999,15,14,13]'));
150 * Tests whether usergroup comparison matches.
154 public function usergroupConditionDoesNotMatchDefaulUserGroupIds(): void
156 $subject = new ConditionMatcher(new Context([
157 'frontend.user' => new UserAspect(new FrontendUserAuthentication(), [0, -1])
159 $this->assertFalse($subject->match('[usergroup = 0,-1]'));
163 * Tests whether user comparison matches.
167 public function loginUserConditionMatchesAnyLoggedInUser(): void
169 $user = new FrontendUserAuthentication();
170 $user->user
['uid'] = 13;
171 $user->groupData
['uid'] = [14];
172 $subject = new ConditionMatcher(new Context([
173 'frontend.user' => new UserAspect($user)
175 $this->assertTrue($subject->match('[loginUser = *]'));
179 * Tests whether user comparison matches.
183 public function loginUserConditionMatchesSingleLoggedInUser(): void
185 $user = new FrontendUserAuthentication();
186 $user->user
['uid'] = 13;
187 $user->groupData
['uid'] = [14];
188 $subject = new ConditionMatcher(new Context([
189 'frontend.user' => new UserAspect($user)
191 $this->assertTrue($subject->match('[loginUser = 13]'));
195 * Tests whether user comparison matches.
199 public function loginUserConditionMatchesMultipleLoggedInUsers(): void
201 $user = new FrontendUserAuthentication();
202 $user->user
['uid'] = 13;
203 $user->groupData
['uid'] = [14];
204 $subject = new ConditionMatcher(new Context([
205 'frontend.user' => new UserAspect($user)
207 $this->assertTrue($subject->match('[loginUser = 999,13]'));
211 * Tests whether user comparison matches.
215 public function loginUserConditionDoesNotMatchIfNotUserIsLoggedId(): void
217 $user = new FrontendUserAuthentication();
218 $user->user
['uid'] = 13;
219 $subject = new ConditionMatcher(new Context([
220 'frontend.user' => new UserAspect($user)
222 $this->assertFalse($subject->match('[loginUser = *]'));
223 $this->assertFalse($subject->match('[loginUser = 13]'));
227 * Tests whether user is not logged in
231 public function loginUserConditionMatchIfUserIsNotLoggedIn(): void
233 $user = new FrontendUserAuthentication();
234 $subject = new ConditionMatcher(new Context([
235 'frontend.user' => new UserAspect($user)
237 $this->assertTrue($subject->match('[loginUser = ]'));
241 * Tests whether numerical comparison matches.
245 public function globalVarConditionMatchesOnEqualExpression(): void
247 $subject = new ConditionMatcher(new Context());
248 $this->assertTrue($subject->match('[globalVar = LIT:10 = 10]'));
249 $this->assertTrue($subject->match('[globalVar = LIT:10.1 = 10.1]'));
250 $this->assertTrue($subject->match('[globalVar = LIT:10 == 10]'));
251 $this->assertTrue($subject->match('[globalVar = LIT:10.1 == 10.1]'));
255 * Tests whether numerical comparison matches.
259 public function globalVarConditionMatchesOnEqualExpressionWithMultipleValues(): void
261 $subject = new ConditionMatcher(new Context());
262 $this->assertTrue($subject->match('[globalVar = LIT:10 = 10|20|30]'));
263 $this->assertTrue($subject->match('[globalVar = LIT:10.1 = 10.1|20.2|30.3]'));
264 $this->assertTrue($subject->match('[globalVar = LIT:20 = 10|20|30]'));
265 $this->assertTrue($subject->match('[globalVar = LIT:20.2 = 10.1|20.2|30.3]'));
266 $this->assertTrue($subject->match('[globalVar = LIT:10 == 10|20|30]'));
267 $this->assertTrue($subject->match('[globalVar = LIT:10.1 == 10.1|20.2|30.3]'));
268 $this->assertTrue($subject->match('[globalVar = LIT:20 == 10|20|30]'));
269 $this->assertTrue($subject->match('[globalVar = LIT:20.2 == 10.1|20.2|30.3]'));
273 * Tests whether numerical comparison matches.
277 public function globalVarConditionMatchesOnNotEqualExpression(): void
279 $subject = new ConditionMatcher(new Context());
280 $this->assertTrue($subject->match('[globalVar = LIT:10 != 20]'));
281 $this->assertTrue($subject->match('[globalVar = LIT:10.1 != 10.2]'));
285 * Tests whether numerical comparison does not match.
289 public function globalVarConditionDoesNotMatchOnNotEqualExpression(): void
291 $subject = new ConditionMatcher(new Context());
292 $this->assertFalse($subject->match('[globalVar = LIT:10 != 10]'));
296 * Tests whether numerical comparison matches.
300 public function globalVarConditionMatchesOnNotEqualExpressionWithMultipleValues(): void
302 $subject = new ConditionMatcher(new Context());
303 $this->assertTrue($subject->match('[globalVar = LIT:10 != 20|30]'));
304 $this->assertTrue($subject->match('[globalVar = LIT:10.1 != 10.2|20.3]'));
308 * Tests whether numerical comparison matches.
312 public function globalVarConditionMatchesOnLowerThanExpression(): void
314 $subject = new ConditionMatcher(new Context());
315 $this->assertTrue($subject->match('[globalVar = LIT:10 < 20]'));
316 $this->assertTrue($subject->match('[globalVar = LIT:10.1 < 10.2]'));
320 * Tests whether numerical comparison matches.
324 public function globalVarConditionMatchesOnLowerThanOrEqualExpression(): void
326 $subject = new ConditionMatcher(new Context());
327 $this->assertTrue($subject->match('[globalVar = LIT:10 <= 10]'));
328 $this->assertTrue($subject->match('[globalVar = LIT:10 <= 20]'));
329 $this->assertTrue($subject->match('[globalVar = LIT:10.1 <= 10.1]'));
330 $this->assertTrue($subject->match('[globalVar = LIT:10.1 <= 10.2]'));
334 * Tests whether numerical comparison matches.
338 public function globalVarConditionMatchesOnGreaterThanExpression(): void
340 $subject = new ConditionMatcher(new Context());
341 $this->assertTrue($subject->match('[globalVar = LIT:20 > 10]'));
342 $this->assertTrue($subject->match('[globalVar = LIT:10.2 > 10.1]'));
346 * Tests whether numerical comparison matches.
350 public function globalVarConditionMatchesOnGreaterThanOrEqualExpression(): void
352 $subject = new ConditionMatcher(new Context());
353 $this->assertTrue($subject->match('[globalVar = LIT:10 >= 10]'));
354 $this->assertTrue($subject->match('[globalVar = LIT:20 >= 10]'));
355 $this->assertTrue($subject->match('[globalVar = LIT:10.1 >= 10.1]'));
356 $this->assertTrue($subject->match('[globalVar = LIT:10.2 >= 10.1]'));
360 * Tests whether numerical comparison matches.
364 public function globalVarConditionMatchesOnEmptyExpressionWithNoValueSet(): void
366 $subject = new ConditionMatcher(new Context());
367 $testKey = $this->getUniqueId('test');
368 $this->assertTrue($subject->match('[globalVar = GP:' . $testKey . '=]'));
369 $this->assertTrue($subject->match('[globalVar = GP:' . $testKey . ' = ]'));
373 * Tests whether numerical comparison matches.
377 public function globalVarConditionDoesNotMatchOnEmptyExpressionWithValueSetToZero(): void
379 $subject = new ConditionMatcher(new Context());
380 $testKey = $this->getUniqueId('test');
382 $_POST = [$testKey => 0];
383 $this->assertFalse($subject->match('[globalVar = GP:' . $testKey . '=]'));
384 $this->assertFalse($subject->match('[globalVar = GP:' . $testKey . ' = ]'));
388 * Tests whether an array with zero as key matches its value
392 public function globalVarConditionMatchesOnArrayExpressionWithZeroAsKey(): void
394 $subject = new ConditionMatcher(new Context());
395 $testKey = $this->getUniqueId('test');
398 $_POST = [$testKey => ['0' => $testValue]];
399 $this->assertTrue($subject->match('[globalVar = GP:' . $testKey . '|0=' . $testValue . ']'));
403 * Tests whether string comparison matches.
407 public function globalStringConditionMatchesOnEqualExpression(): void
409 $subject = new ConditionMatcher(new Context());
410 $this->assertTrue($subject->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.Test.Condition]'));
411 $this->assertFalse($subject->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3]'));
415 * Tests whether string comparison matches.
419 public function globalStringConditionMatchesOnEmptyExpressionWithValueSetToEmptyString(): void
421 $subject = new ConditionMatcher(new Context());
422 $testKey = $this->getUniqueId('test');
424 $_POST = [$testKey => ''];
425 $this->assertTrue($subject->match('[globalString = GP:' . $testKey . '=]'));
426 $this->assertTrue($subject->match('[globalString = GP:' . $testKey . ' = ]'));
430 * Tests whether string comparison matches.
434 public function globalStringConditionMatchesOnEmptyLiteralExpressionWithValueSetToEmptyString(): void
436 $subject = new ConditionMatcher(new Context());
437 $this->assertTrue($subject->match('[globalString = LIT:=]'));
438 $this->assertTrue($subject->match('[globalString = LIT: = ]'));
442 * Tests whether string comparison matches.
446 public function globalStringConditionMatchesWildcardExpression(): void
448 $subject = new ConditionMatcher(new Context());
449 $this->assertTrue($subject->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]'));
450 $this->assertTrue($subject->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]'));
451 $this->assertTrue($subject->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?T*t?Condition]'));
455 * Tests whether string comparison matches.
459 public function globalStringConditionMatchesRegularExpression(): void
461 $subject = new ConditionMatcher(new Context());
462 $this->assertTrue($subject->match('[globalString = LIT:TYPO3.Test.Condition = /^[A-Za-z3.]+$/]'));
463 $this->assertTrue($subject->match('[globalString = LIT:TYPO3.Test.Condition = /^TYPO3\\..+Condition$/]'));
464 $this->assertFalse($subject->match('[globalString = LIT:TYPO3.Test.Condition = /^FALSE/]'));
468 * Tests whether string comparison matches.
472 public function globalStringConditionMatchesEmptyRegularExpression(): void
474 $subject = new ConditionMatcher(new Context());
475 $testKey = $this->getUniqueId('test');
476 $_SERVER[$testKey] = '';
477 $this->assertTrue($subject->match('[globalString = _SERVER|' . $testKey . ' = /^$/]'));
481 * Tests whether treeLevel comparison matches.
485 public function treeLevelConditionMatchesSingleValue(): void
487 $subject = new ConditionMatcher(new Context());
488 $this->assertTrue($subject->match('[treeLevel = 2]'));
492 * Tests whether treeLevel comparison matches.
496 public function treeLevelConditionMatchesMultipleValues(): void
498 $subject = new ConditionMatcher(new Context());
499 $this->assertTrue($subject->match('[treeLevel = 999,998,2]'));
503 * Tests whether treeLevel comparison matches.
507 public function treeLevelConditionDoesNotMatchFaultyValue(): void
509 $subject = new ConditionMatcher(new Context());
510 $this->assertFalse($subject->match('[treeLevel = 999]'));
514 * Tests whether a page Id is found in the previous rootline entries.
518 public function PIDupinRootlineConditionMatchesSinglePageIdInRootline(): void
520 $GLOBALS['TSFE']->id
= 121;
521 $subject = new ConditionMatcher(new Context());
522 $this->assertTrue($subject->match('[PIDupinRootline = 111]'));
526 * Tests whether a page Id is found in the previous rootline entries.
530 public function PIDupinRootlineConditionMatchesMultiplePageIdsInRootline(): void
532 $GLOBALS['TSFE']->id
= 121;
533 $subject = new ConditionMatcher(new Context());
534 $this->assertTrue($subject->match('[PIDupinRootline = 999,111,101]'));
538 * Tests whether a page Id is found in the previous rootline entries.
542 public function PIDupinRootlineConditionDoesNotMatchPageIdNotInRootline(): void
544 $GLOBALS['TSFE']->id
= 121;
545 $subject = new ConditionMatcher(new Context());
546 $this->assertFalse($subject->match('[PIDupinRootline = 999]'));
550 * Tests whether a page Id is found in the previous rootline entries.
554 public function PIDupinRootlineConditionDoesNotMatchLastPageIdInRootline(): void
556 $GLOBALS['TSFE']->id
= 121;
557 $subject = new ConditionMatcher(new Context());
558 $this->assertFalse($subject->match('[PIDupinRootline = 121]'));
562 * Tests whether a page Id is found in all rootline entries.
566 public function PIDinRootlineConditionMatchesSinglePageIdInRootline(): void
568 $GLOBALS['TSFE']->id
= 121;
569 $subject = new ConditionMatcher(new Context());
570 $this->assertTrue($subject->match('[PIDinRootline = 111]'));
574 * Tests whether a page Id is found in all rootline entries.
578 public function PIDinRootlineConditionMatchesMultiplePageIdsInRootline(): void
580 $GLOBALS['TSFE']->id
= 121;
581 $subject = new ConditionMatcher(new Context());
582 $this->assertTrue($subject->match('[PIDinRootline = 999,111,101]'));
586 * Tests whether a page Id is found in all rootline entries.
590 public function PIDinRootlineConditionMatchesLastPageIdInRootline(): void
592 $GLOBALS['TSFE']->id
= 121;
593 $subject = new ConditionMatcher(new Context());
594 $this->assertTrue($subject->match('[PIDinRootline = 121]'));
598 * Tests whether a page Id is found in all rootline entries.
602 public function PIDinRootlineConditionDoesNotMatchPageIdNotInRootline(): void
604 $GLOBALS['TSFE']->id
= 121;
605 $subject = new ConditionMatcher(new Context());
606 $this->assertFalse($subject->match('[PIDinRootline = 999]'));
610 * Tests whether the compatibility version can be evaluated.
611 * (e.g. 7.9 is compatible to 7.0 but not to 15.0)
615 public function compatVersionConditionMatchesOlderRelease(): void
617 $subject = new ConditionMatcher(new Context());
618 $this->assertTrue($subject->match('[compatVersion = 7.0]'));
622 * Tests whether the compatibility version can be evaluated.
623 * (e.g. 7.9 is compatible to 7.0 but not to 15.0)
627 public function compatVersionConditionMatchesSameRelease(): void
629 $subject = new ConditionMatcher(new Context());
630 $this->assertTrue($subject->match('[compatVersion = ' . TYPO3_branch
. ']'));
634 * Tests whether the compatibility version can be evaluated.
635 * (e.g. 7.9 is compatible to 7.0 but not to 15.0)
639 public function compatVersionConditionDoesNotMatchNewerRelease(): void
641 $subject = new ConditionMatcher(new Context());
642 $this->assertFalse($subject->match('[compatVersion = 15.0]'));
646 * Tests whether the generic fetching of variables works with the namespace 'GP'.
650 public function genericGetVariablesSucceedsWithNamespaceGP(): void
652 $_GET = ['testGet' => 'getTest'];
653 $_POST = ['testPost' => 'postTest'];
654 $subject = new ConditionMatcher(new Context());
655 $this->assertTrue($subject->match('[globalString = GP:testGet = getTest]'));
656 $this->assertTrue($subject->match('[globalString = GP:testPost = postTest]'));
660 * Tests whether the generic fetching of variables works with the namespace 'TSFE'.
664 public function genericGetVariablesSucceedsWithNamespaceTSFE(): void
666 $GLOBALS['TSFE']->id
= 1234567;
667 $GLOBALS['TSFE']->testSimpleObject
= new \
stdClass();
668 $GLOBALS['TSFE']->testSimpleObject
->testSimpleVariable
= 'testValue';
670 $subject = new ConditionMatcher(new Context());
671 $this->assertTrue($subject->match('[globalString = TSFE:id = 1234567]'));
672 $this->assertTrue($subject->match('[globalString = TSFE:testSimpleObject|testSimpleVariable = testValue]'));
676 * Tests whether the generic fetching of variables works with the namespace 'session'.
680 public function genericGetVariablesSucceedsWithNamespaceSession(): void
682 $prophecy = $this->prophesize(FrontendUserAuthentication
::class);
683 $prophecy->getSessionData(Argument
::exact('foo'))->willReturn(['bar' => 1234567]);
684 $GLOBALS['TSFE']->fe_user
= $prophecy->reveal();
686 $subject = new ConditionMatcher(new Context());
687 $this->assertTrue($subject->match('[globalString = session:foo|bar = 1234567]'));
691 * Tests whether the generic fetching of variables works with the namespace 'ENV'.
695 public function genericGetVariablesSucceedsWithNamespaceENV(): void
697 $testKey = $this->getUniqueId('test');
698 putenv($testKey . '=testValue');
699 $subject = new ConditionMatcher(new Context());
700 $this->assertTrue($subject->match('[globalString = ENV:' . $testKey . ' = testValue]'));
704 * Tests whether the generic fetching of variables works with the namespace 'IENV'.
708 public function genericGetVariablesSucceedsWithNamespaceIENV(): void
710 $_SERVER['HTTP_HOST'] = GeneralUtility
::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567';
711 $subject = new ConditionMatcher(new Context());
712 $this->assertTrue($subject->match('[globalString = IENV:TYPO3_PORT = 1234567]'));
716 * Tests whether the generic fetching of variables works with any global namespace.
720 public function genericGetVariablesSucceedsWithAnyGlobalNamespace(): void
722 $GLOBALS[$this->testGlobalNamespace
] = [
723 'first' => 'testFirst',
724 'second' => ['third' => 'testThird']
726 $subject = new ConditionMatcher(new Context());
727 $this->assertTrue($subject->match('[globalString = ' . $this->testGlobalNamespace
. '|first = testFirst]'));
728 $this->assertTrue($subject->match('[globalString = ' . $this->testGlobalNamespace
. '|second|third = testThird]'));
732 * Tests whether any property of a site language matches the request
736 public function siteLanguageMatchesCondition(): void
738 $site = new Site('angelo', 13, [
742 'title' => 'United States',
743 'locale' => 'en_US.UTF-8',
748 'locale' => 'en_UK.UTF-8',
752 $GLOBALS['TYPO3_REQUEST'] = new ServerRequest();
753 $GLOBALS['TYPO3_REQUEST'] = $GLOBALS['TYPO3_REQUEST']->withAttribute('language', $site->getLanguageById(0));
754 $subject = new ConditionMatcher(new Context());
755 $this->assertTrue($subject->match('[siteLanguage = locale = en_US.UTF-8]'));
756 $this->assertTrue($subject->match('[siteLanguage = locale = de_DE, locale = en_US.UTF-8]'));
760 * Tests whether any property of a site language does NOT match the request
764 public function siteLanguageDoesNotMatchCondition(): void
766 $site = new Site('angelo', 13, [
770 'title' => 'United States',
771 'locale' => 'en_US.UTF-8',
776 'locale' => 'en_UK.UTF-8',
780 $GLOBALS['TYPO3_REQUEST'] = new ServerRequest();
781 $GLOBALS['TYPO3_REQUEST'] = $GLOBALS['TYPO3_REQUEST']->withAttribute('language', $site->getLanguageById(0));
782 $subject = new ConditionMatcher(new Context());
783 $this->assertFalse($subject->match('[siteLanguage = locale = en_UK.UTF-8]'));
784 $this->assertFalse($subject->match('[siteLanguage = locale = de_DE, title = UK]'));
788 * Tests whether any property of a site matches the request
792 public function siteMatchesCondition(): void
794 $site = new Site('angelo', 13, ['languages' => [], 'base' => 'https://typo3.org/']);
795 $GLOBALS['TYPO3_REQUEST'] = new ServerRequest();
796 $GLOBALS['TYPO3_REQUEST'] = $GLOBALS['TYPO3_REQUEST']->withAttribute('language', $site->getLanguageById(0));
797 $subject = new ConditionMatcher(new Context());
798 $this->assertTrue($subject->match('[site = identifier = angelo]'));
799 $this->assertTrue($subject->match('[site = rootPageId = 13]'));
800 $this->assertTrue($subject->match('[site = base = https://typo3.org/]'));
804 * Tests whether any property of a site that does NOT match the request
808 public function siteDoesNotMatchCondition(): void
810 $site = new Site('angelo', 13, [
814 'title' => 'United States',
815 'locale' => 'en_US.UTF-8',
820 'locale' => 'en_UK.UTF-8',
824 $GLOBALS['TYPO3_REQUEST'] = new ServerRequest();
825 $GLOBALS['TYPO3_REQUEST'] = $GLOBALS['TYPO3_REQUEST']->withAttribute('language', $site->getLanguageById(0));
826 $subject = new ConditionMatcher(new Context());
827 $this->assertFalse($subject->match('[site = identifier = berta]'));
828 $this->assertFalse($subject->match('[site = rootPageId = 14, rootPageId=23]'));
834 public function matchThrowsExceptionIfConditionClassDoesNotInheritFromAbstractCondition(): void
836 $this->expectException(InvalidTypoScriptConditionException
::class);
837 $this->expectExceptionCode(1410286153);
838 $subject = new ConditionMatcher(new Context());
839 $subject->match('[stdClass = foo]');
845 public function matchCallsTestConditionAndHandsOverParameters(): void
847 $this->expectException(TestConditionException
::class);
848 $this->expectExceptionCode(1411581139);
849 $subject = new ConditionMatcher(new Context());
850 $subject->match('[TYPO3\\CMS\\Frontend\\Tests\\Unit\\Configuration\\TypoScript\\ConditionMatching\\Fixtures\\TestCondition = 7, != 6]');