2 declare(strict_types = 1);
18 use Prophecy\Argument;
29 use TYPO3\CMS\Core\Package\PackageManager;
31 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
61 protected function setUp(): void
63 require_once
'Fixtures/ConditionMatcherUserFuncs.php';
65 $this->resetSingletonInstances =
true;
67 $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
68 $cacheFrontendProphecy->has(Argument::any())->willReturn(
false);
69 $cacheFrontendProphecy->set(Argument::any(), Argument::any())->willReturn(
null);
70 $cacheManagerProphecy = $this->prophesize(CacheManager::class);
71 $cacheManagerProphecy->getCache(
'cache_core')->willReturn($cacheFrontendProphecy->reveal());
72 GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
74 $packageManagerProphecy = $this->prophesize(PackageManager::class);
75 $corePackageProphecy = $this->prophesize(PackageInterface::class);
76 $corePackageProphecy->getPackagePath()->willReturn(__DIR__ .
'/../../../../../../../sysext/core/');
77 $packageManagerProphecy->getActivePackages()->willReturn([
78 $corePackageProphecy->reveal()
80 GeneralUtility::setSingletonInstance(PackageManager::class, $packageManagerProphecy->reveal());
83 $this->backupApplicationContext = GeneralUtility::getApplicationContext();
89 $this->conditionMatcher = $this->getAccessibleMock(ConditionMatcher::class, [
'determineRootline']);
90 $this->evaluateConditionCommonMethod = new \ReflectionMethod(AbstractConditionMatcher::class,
'evaluateConditionCommon');
91 $this->evaluateConditionCommonMethod->setAccessible(
true);
92 $this->evaluateExpressionMethod = new \ReflectionMethod(AbstractConditionMatcher::class,
'evaluateExpression');
93 $this->evaluateExpressionMethod->setAccessible(
true);
94 $loggerProphecy = $this->prophesize(Logger::class);
95 $this->conditionMatcher->setLogger($loggerProphecy->reveal());
113 '[dayofmonth = 17]' => [
'dayofmonth', 17,
true],
114 '[dayofweek = 3]' => [
'dayofweek', 3,
true],
115 '[dayofyear = 16]' => [
'dayofyear', 16,
true],
116 '[hour = 11]' => [
'hour', 11,
true],
117 '[minute = 4]' => [
'minute', 4,
true],
118 '[month = 1]' => [
'month', 1,
true],
119 '[year = 1945]' => [
'year', 1945,
true],
132 $GLOBALS[
'SIM_EXEC_TIME'] = mktime(11, 4, 0, 1, 17, 1945);
133 $this->assertSame($expected, $this->evaluateConditionCommonMethod->invokeArgs(
134 $this->conditionMatcher,
135 [$expressionMethod, $expressionValue]
145 '[dayofmonth = 17]' => [
'j', 17,
true],
146 '[dayofweek = 3]' => [
'w', 3,
true],
147 '[dayofyear = 16]' => [
'z', 16,
true],
148 '[hour = 11]' => [
'G', 11,
true],
149 '[minute = 4]' => [
'i', 4,
true],
150 '[month = 1]' => [
'n', 1,
true],
151 '[year = 1945]' => [
'Y', 1945,
true],
164 $GLOBALS[
'SIM_EXEC_TIME'] = gmmktime(11, 4, 0, 1, 17, 1945);
165 GeneralUtility::makeInstance(Context::class)
169 $this->evaluateExpressionMethod->invokeArgs($this->conditionMatcher, [
'date("' . $format .
'") == ' . $expressionValue])
178 $featureName =
'test.testFeature';
179 $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'features'][$featureName] =
true;
181 $this->evaluateExpressionMethod->invokeArgs($this->conditionMatcher, [
'feature("' . $featureName .
'")'])
184 $this->evaluateExpressionMethod->invokeArgs($this->conditionMatcher, [
'feature("' . $featureName .
'") == true'])
187 $this->evaluateExpressionMethod->invokeArgs($this->conditionMatcher, [
'feature("' . $featureName .
'") === true'])
190 $this->evaluateExpressionMethod->invokeArgs($this->conditionMatcher, [
'feature("' . $featureName .
'") == false'])
193 $this->evaluateExpressionMethod->invokeArgs($this->conditionMatcher, [
'feature("' . $featureName .
'") === false'])
196 $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'features'][$featureName] =
false;
198 $this->evaluateExpressionMethod->invokeArgs($this->conditionMatcher, [
'feature("' . $featureName .
'")'])
201 $this->evaluateExpressionMethod->invokeArgs($this->conditionMatcher, [
'feature("' . $featureName .
'") == true'])
204 $this->evaluateExpressionMethod->invokeArgs($this->conditionMatcher, [
'feature("' . $featureName .
'") === true'])
207 $this->evaluateExpressionMethod->invokeArgs($this->conditionMatcher, [
'feature("' . $featureName .
'") == false'])
210 $this->evaluateExpressionMethod->invokeArgs($this->conditionMatcher, [
'feature("' . $featureName .
'") === false'])
220 '[hostname = localhost]' => [
'hostname',
'localhost',
true],
221 '[hostname = localhost, foo.local]' => [
'hostname',
'localhost, foo.local',
true],
222 '[hostname = bar.local, foo.local]' => [
'hostname',
'bar.local, foo.local',
false],
235 $GLOBALS[
'_SERVER'][
'REMOTE_ADDR'] =
'127.0.0.1';
236 $this->assertSame($expected, $this->evaluateConditionCommonMethod->invokeArgs(
237 $this->conditionMatcher,
238 [$expressionMethod, $expressionValue]
251 [
'Production/Staging/*'],
252 [
'Production/Staging/Server2'],
253 [
'/^Production.*$/'],
254 [
'/^Production\\/.+\\/Server\\d+$/'],
265 $applicationContext =
new ApplicationContext(
'Production/Staging/Server2');
270 $this->evaluateConditionCommonMethod->invokeArgs($this->conditionMatcher, [
'applicationContext', $matchingContextCondition])
274 $this->evaluateExpressionMethod->invokeArgs($this->conditionMatcher, [
'like(applicationContext, "' . preg_quote($matchingContextCondition,
'/') .
'")'])
288 [
'Development/Profiling, Testing/Unit'],
289 [
'Testing/Staging/Server2'],
291 [
'/^Production\\/.+\\/Host\\d+$/'],
302 $applicationContext =
new ApplicationContext(
'Production/Staging/Server2');
307 $this->evaluateConditionCommonMethod->invokeArgs($this->conditionMatcher, [
'applicationContext', $notMatchingApplicationContextCondition])
311 $this->evaluateExpressionMethod->invokeArgs($this->conditionMatcher, [
'like(applicationContext, "' . preg_quote($notMatchingApplicationContextCondition,
'/') .
'")'])
331 'ipv4 wildcard subnet' => [
336 'ipv6 wildcard subnet' => [
341 'List of addresses matches' => [
346 'IP does not match' => [
351 'ipv4 subnet does not match' => [
356 'ipv6 subnet does not match' => [
361 'List of addresses does not match' => [
376 unset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'reverseProxyIP']);
378 GeneralUtility::setIndpEnv(
'REMOTE_ADDR', $actualIp);
379 $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'devIPmask'] = $devIpMask;
381 $result = $this->evaluateExpressionMethod->invokeArgs($this->conditionMatcher, [
'ip("devIP")']);
382 $this->assertSame($expectedResult, $result);
391 $this->evaluateConditionCommonMethod->invokeArgs(
392 $this->conditionMatcher,
393 [
'userFunc',
'user_testFunction']
404 $this->evaluateConditionCommonMethod->invokeArgs(
405 $this->conditionMatcher,
406 [
'userFunc',
'user_testFunctionWithSingleArgument(x)']
417 $this->evaluateConditionCommonMethod->invokeArgs(
418 $this->conditionMatcher,
419 [
'userFunc',
'user_testFunctionWithSingleArgument(0)']
430 $this->evaluateConditionCommonMethod->invokeArgs(
431 $this->conditionMatcher,
432 [
'userFunc',
'user_testFunctionWithNoArgument( )']
443 $this->evaluateConditionCommonMethod->invokeArgs(
444 $this->conditionMatcher,
445 [
'userFunc',
'user_testFunctionWithThreeArguments(1,2,3)']
456 $this->evaluateConditionCommonMethod->invokeArgs(
457 $this->conditionMatcher,
458 [
'userFunc',
'user_testFunctionWithThreeArguments(0,true,"foo")']
469 $this->evaluateConditionCommonMethod->invokeArgs(
470 $this->conditionMatcher,
471 [
'userFunc',
'user_testFunctionWithThreeArguments(0,"foo",true)']
482 $this->evaluateConditionCommonMethod->invokeArgs(
483 $this->conditionMatcher,
484 [
'userFunc',
'user_testFunctionWithThreeArguments("foo",true,0)']
495 $this->evaluateConditionCommonMethod->invokeArgs(
496 $this->conditionMatcher,
497 [
'userFunc',
'user_testFunctionWithThreeArguments("foo",0,true)']
508 $this->evaluateConditionCommonMethod->invokeArgs(
509 $this->conditionMatcher,
510 [
'userFunc',
'user_testFunctionWithThreeArguments(true,0,"foo")']
521 $this->evaluateConditionCommonMethod->invokeArgs(
522 $this->conditionMatcher,
523 [
'userFunc',
'user_testFunctionWithThreeArguments(true,"foo",0)']
534 $this->evaluateConditionCommonMethod->invokeArgs(
535 $this->conditionMatcher,
536 [
'userFunc',
"user_testFunctionWithThreeArguments(0,true,'foo')"]
547 $this->evaluateConditionCommonMethod->invokeArgs(
548 $this->conditionMatcher,
549 [
'userFunc',
"user_testFunctionWithThreeArguments(0,'foo',true)"]
560 $this->evaluateConditionCommonMethod->invokeArgs(
561 $this->conditionMatcher,
562 [
'userFunc',
"user_testFunctionWithThreeArguments('foo',true,0)"]
573 $this->evaluateConditionCommonMethod->invokeArgs(
574 $this->conditionMatcher,
575 [
'userFunc',
"user_testFunctionWithThreeArguments('foo',0,true)"]
586 $this->evaluateConditionCommonMethod->invokeArgs(
587 $this->conditionMatcher,
588 [
'userFunc',
"user_testFunctionWithThreeArguments(true,0,'foo')"]
599 $this->evaluateConditionCommonMethod->invokeArgs(
600 $this->conditionMatcher,
601 [
'userFunc',
"user_testFunctionWithThreeArguments(true,'foo',0)"]
612 $this->evaluateConditionCommonMethod->invokeArgs(
613 $this->conditionMatcher,
614 [
'userFunc',
"user_testFunctionWithThreeArguments('foo','bar', 'baz')"]
625 $this->evaluateConditionCommonMethod->invokeArgs(
626 $this->conditionMatcher,
627 [
'userFunc',
'user_testFunctionWithThreeArguments("foo","bar","baz")']
638 $this->evaluateConditionCommonMethod->invokeArgs(
639 $this->conditionMatcher,
640 [
'userFunc',
'user_testFunctionFalse']
651 $this->evaluateConditionCommonMethod->invokeArgs(
652 $this->conditionMatcher,
653 [
'userFunc',
'user_testFunctionWithThreeArguments(1,2,"3,4,5,6")']
664 $this->evaluateConditionCommonMethod->invokeArgs(
665 $this->conditionMatcher,
666 [
'userFunc',
'user_testFunctionWithThreeArguments ( 1 , 2, "3, 4, 5, 6" )']
677 $this->evaluateConditionCommonMethod->invokeArgs(
678 $this->conditionMatcher,
679 [
'userFunc',
'user_testFunctionWithThreeArgumentsSpaces ( 1 , 2, "3, 4, 5, 6" )']
690 $this->evaluateConditionCommonMethod->invokeArgs(
691 $this->conditionMatcher,
692 [
'userFunc',
'user_testFunctionWithSpaces(" 3, 4, 5, 6 ")']
703 $this->evaluateConditionCommonMethod->invokeArgs(
704 $this->conditionMatcher,
705 [
'userFunc',
'user_testFunctionWithThreeArgumentsSpaces ( 1 , 2, "3, \"4, 5\", 6" )']
716 $this->evaluateConditionCommonMethod->invokeArgs(
717 $this->conditionMatcher,
718 [
'userFunc',
'user_testFunctionWithQuoteMissing ("value \")']
729 $this->evaluateConditionCommonMethod->invokeArgs(
730 $this->conditionMatcher,
731 [
'userFunc',
'user_testQuotes("1 \" 2")']
742 $this->evaluateConditionCommonMethod->invokeArgs(
743 $this->conditionMatcher,
744 [
'userFunc',
'ConditionMatcherUserFunctions::isTrue(1)']
753 '[]' => [
'[]',
'[]'],
754 '[foo]' => [
'[foo]',
'[foo]'],
755 '[foo] && [bar]' => [
'[foo] && [bar]',
'[foo]&&[bar]'],
756 '[foo] AND [bar]' => [
'[foo] AND [bar]',
'[foo]&&[bar]'],
757 '[foo] and [bar]' => [
'[foo] and [bar]',
'[foo]&&[bar]'],
758 '[foo] [bar]' => [
'[foo] [bar]',
'[foo]||[bar]'],
759 '[foo] || [bar]' => [
'[foo] || [bar]',
'[foo]||[bar]'],
760 '[foo] OR [bar]' => [
'[foo] OR [bar]',
'[foo]||[bar]'],
761 '[foo] or [bar]' => [
'[foo] or [bar]',
'[foo]||[bar]'],
762 '[foo] && [bar]&&[baz]' => [
'[foo] && [bar]&&[baz]',
'[foo]&&[bar]&&[baz]'],
763 '[foo] AND [bar]AND[baz]' => [
'[foo] AND [bar]AND[baz]',
'[foo]&&[bar]&&[baz]'],
764 '[foo] and [bar]and[baz]' => [
'[foo] and [bar]and[baz]',
'[foo]&&[bar]&&[baz]'],
765 '[foo] || [bar]||[baz]' => [
'[foo] || [bar]||[baz]',
'[foo]||[bar]||[baz]'],
766 '[foo] OR [bar]OR[baz]' => [
'[foo] OR [bar]OR[baz]',
'[foo]||[bar]||[baz]'],
767 '[foo] or [bar]or[baz]' => [
'[foo] or [bar]or[baz]',
'[foo]||[bar]||[baz]'],
768 '[foo] && [bar]||[baz]' => [
'[foo] && [bar]||[baz]',
'[foo]&&[bar]||[baz]'],
769 '[foo] AND [bar]OR[baz]' => [
'[foo] AND [bar]OR[baz]',
'[foo]&&[bar]||[baz]'],
770 '[foo] and [bar]or[baz]' => [
'[foo] and [bar]or[baz]',
'[foo]&&[bar]||[baz]'],
771 '[foo] || [bar]OR[baz]' => [
'[foo] || [bar]OR[baz]',
'[foo]||[bar]||[baz]'],
772 '[foo] || [bar]or[baz]' => [
'[foo] || [bar]or[baz]',
'[foo]||[bar]||[baz]'],
773 '[foo] OR [bar]AND[baz]' => [
'[foo] OR [bar]AND[baz]',
'[foo]||[bar]&&[baz]'],
774 '[foo] or [bar]and[baz]' => [
'[foo] or [bar]and[baz]',
'[foo]||[bar]&&[baz]'],
777 '[foo && bar && baz]' => [
'[foo && bar && baz]',
'[foo && bar && baz]'],
778 '[foo and bar and baz]' => [
'[foo and bar and baz]',
'[foo and bar and baz]'],
779 '[foo AND bar AND baz]' => [
'[foo AND bar AND baz]',
'[foo AND bar AND baz]'],
780 '[foo || bar || baz]' => [
'[foo || bar || baz]',
'[foo || bar || baz]'],
781 '[foo or bar or baz]' => [
'[foo or bar or baz]',
'[foo or bar or baz]'],
782 '[foo OR bar OR baz]' => [
'[foo OR bar OR baz]',
'[foo OR bar OR baz]'],
783 '[request.getParsedBody()[\'type\'] > 0]' => [
'[request.getParsedBody()[\'type\'] > 0]',
'[request.getParsedBody()[\'type\'] > 0]'],
784 '[request.getParsedBody()[\'type\'] > 0 || request.getQueryParams()[\'type\'] > 0]' => [
'[request.getParsedBody()[\'type\'] > 0 || request.getQueryParams()[\'type\'] > 0]',
'[request.getParsedBody()[\'type\'] > 0 || request.getQueryParams()[\'type\'] > 0]'],
785 '[request.getParsedBody()[\'type\'] > 0 or request.getQueryParams()[\'type\'] == 1]' => [
'[request.getParsedBody()[\'type\'] > 0 or request.getQueryParams()[\'type\'] == 1]',
'[request.getParsedBody()[\'type\'] > 0 or request.getQueryParams()[\'type\'] == 1]'],
786 '[ (request.getParsedBody()[\'type\'] > 0) || (request.getQueryParams()[\'type\'] > 0) ]' => [
'[ (request.getParsedBody()[\'type\'] > 0) || (request.getQueryParams()[\'type\'] > 0) ]',
'[ (request.getParsedBody()[\'type\'] > 0) || (request.getQueryParams()[\'type\'] > 0) ]'],
787 '[request.getParsedBody()[\'tx_news_pi1\'][\'news\'] > 0 || request.getQueryParams()[\'tx_news_pi1\'][\'news\'] > 0]' => [
'[request.getParsedBody()[\'tx_news_pi1\'][\'news\'] > 0 || request.getQueryParams()[\'tx_news_pi1\'][\'news\'] > 0]',
'[request.getParsedBody()[\'tx_news_pi1\'][\'news\'] > 0 || request.getQueryParams()[\'tx_news_pi1\'][\'news\'] > 0]'],
788 '[request.getQueryParams()[\'tx_news_pi1\'][\'news\'] > 0]' => [
'[request.getQueryParams()[\'tx_news_pi1\'][\'news\'] > 0]',
'[request.getQueryParams()[\'tx_news_pi1\'][\'news\'] > 0]'],
800 $this->assertSame($expectedResult, $this->conditionMatcher->_call(
'normalizeExpression', $expression));