a378654a735390d279404cfce026067ee4960155
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / Configuration / TypoScript / ConditionMatching / ConditionMatcherTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Frontend\Tests\Unit\Configuration\TypoScript\ConditionMatching;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
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.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use Prophecy\Argument;
19 use TYPO3\CMS\Core\Configuration\TypoScript\Exception\InvalidTypoScriptConditionException;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
22 use TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher;
23 use TYPO3\CMS\Frontend\Tests\Unit\Configuration\TypoScript\ConditionMatching\Fixtures\TestConditionException;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25
26 /**
27 * Test case
28 */
29 class ConditionMatcherTest extends UnitTestCase
30 {
31 /**
32 * @var \TYPO3\CMS\Frontend\Configuration\TypoScript\ConditionMatching\ConditionMatcher Class under test
33 */
34 protected $matchCondition;
35
36 protected function setUp(): void
37 {
38 $this->testGlobalNamespace = $this->getUniqueId('TEST');
39 GeneralUtility::flushInternalRuntimeCaches();
40 $GLOBALS[$this->testGlobalNamespace] = [];
41 $GLOBALS['TSFE'] = new \stdClass();
42 $GLOBALS['TSFE']->tmpl = new \stdClass();
43 $GLOBALS['TSFE']->tmpl->rootLine = [
44 2 => ['uid' => 121, 'pid' => 111],
45 1 => ['uid' => 111, 'pid' => 101],
46 0 => ['uid' => 101, 'pid' => 0]
47 ];
48 $this->matchCondition = GeneralUtility::makeInstance(ConditionMatcher::class);
49 }
50
51 /**
52 * Tests whether a faulty expression fails.
53 *
54 * @test
55 */
56 public function simulateDisabledMatchAllConditionsFailsOnFaultyExpression(): void
57 {
58 $this->matchCondition->matchAll = false;
59 $this->assertFalse($this->matchCondition->match('[nullCondition = This expression would return FALSE in general]'));
60 }
61
62 /**
63 * Tests whether simulating positive matches for all conditions succeeds.
64 *
65 * @test
66 */
67 public function simulateEnabledMatchAllConditionsSucceeds(): void
68 {
69 $this->matchCondition->setSimulateMatchResult(true);
70 $this->assertTrue($this->matchCondition->match('[nullCondition = This expression would return FALSE in general]'));
71 }
72
73 /**
74 * Tests whether simulating positive matches for specific conditions succeeds.
75 *
76 * @test
77 */
78 public function simulateEnabledMatchSpecificConditionsSucceeds(): void
79 {
80 $testCondition = '[' . $this->getUniqueId('test') . ' = Any condition to simulate a positive match]';
81 $this->matchCondition->setSimulateMatchConditions([$testCondition]);
82 $this->assertTrue($this->matchCondition->match($testCondition));
83 }
84
85 /**
86 * Tests whether the language comparison matches.
87 *
88 * @test
89 */
90 public function languageConditionMatchesSingleLanguageExpression(): void
91 {
92 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
93 $this->assertTrue($this->matchCondition->match('[language = *de*]'));
94 $this->assertTrue($this->matchCondition->match('[language = *de-de*]'));
95 }
96
97 /**
98 * Tests whether the language comparison matches.
99 *
100 * @test
101 */
102 public function languageConditionMatchesMultipleLanguagesExpression(): void
103 {
104 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
105 $this->assertTrue($this->matchCondition->match('[language = *en*,*de*]'));
106 $this->assertTrue($this->matchCondition->match('[language = *en-us*,*de-de*]'));
107 }
108
109 /**
110 * Tests whether the language comparison matches.
111 *
112 * @test
113 */
114 public function languageConditionMatchesCompleteLanguagesExpression(): void
115 {
116 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3';
117 $this->assertTrue($this->matchCondition->match('[language = de-de,de;q=0.8,en-us;q=0.5,en;q=0.3]'));
118 }
119
120 /**
121 * Tests whether usergroup comparison matches.
122 *
123 * @test
124 */
125 public function usergroupConditionMatchesSingleGroupId(): void
126 {
127 $GLOBALS['TSFE']->gr_list = '13,14,15';
128 $this->assertTrue($this->matchCondition->match('[usergroup = 13]'));
129 }
130
131 /**
132 * Tests whether usergroup comparison matches.
133 *
134 * @test
135 */
136 public function usergroupConditionMatchesMultipleUserGroupId(): void
137 {
138 $GLOBALS['TSFE']->gr_list = '13,14,15';
139 $this->assertTrue($this->matchCondition->match('[usergroup = 999,15,14,13]'));
140 }
141
142 /**
143 * Tests whether usergroup comparison matches.
144 *
145 * @test
146 */
147 public function usergroupConditionDoesNotMatchDefaulUserGroupIds(): void
148 {
149 $GLOBALS['TSFE']->gr_list = '0,-1';
150 $this->assertFalse($this->matchCondition->match('[usergroup = 0,-1]'));
151 }
152
153 /**
154 * Tests whether user comparison matches.
155 *
156 * @test
157 */
158 public function loginUserConditionMatchesAnyLoggedInUser(): void
159 {
160 $GLOBALS['TSFE']->loginUser = true;
161 $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
162 $this->assertTrue($this->matchCondition->match('[loginUser = *]'));
163 }
164
165 /**
166 * Tests whether user comparison matches.
167 *
168 * @test
169 */
170 public function loginUserConditionMatchesSingleLoggedInUser(): void
171 {
172 $GLOBALS['TSFE']->loginUser = true;
173 $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
174 $this->assertTrue($this->matchCondition->match('[loginUser = 13]'));
175 }
176
177 /**
178 * Tests whether user comparison matches.
179 *
180 * @test
181 */
182 public function loginUserConditionMatchesMultipleLoggedInUsers(): void
183 {
184 $GLOBALS['TSFE']->loginUser = true;
185 $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
186 $this->assertTrue($this->matchCondition->match('[loginUser = 999,13]'));
187 }
188
189 /**
190 * Tests whether user comparison matches.
191 *
192 * @test
193 */
194 public function loginUserConditionDoesNotMatchIfNotUserIsLoggedId(): void
195 {
196 $GLOBALS['TSFE']->loginUser = false;
197 $GLOBALS['TSFE']->fe_user->user['uid'] = 13;
198 $this->assertFalse($this->matchCondition->match('[loginUser = *]'));
199 $this->assertFalse($this->matchCondition->match('[loginUser = 13]'));
200 }
201
202 /**
203 * Tests whether user is not logged in
204 *
205 * @test
206 */
207 public function loginUserConditionMatchIfUserIsNotLoggedIn(): void
208 {
209 $GLOBALS['TSFE']->loginUser = false;
210 $this->assertTrue($this->matchCondition->match('[loginUser = ]'));
211 }
212
213 /**
214 * Tests whether numerical comparison matches.
215 *
216 * @test
217 */
218 public function globalVarConditionMatchesOnEqualExpression(): void
219 {
220 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10]'));
221 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1]'));
222 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10]'));
223 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1]'));
224 }
225
226 /**
227 * Tests whether numerical comparison matches.
228 *
229 * @test
230 */
231 public function globalVarConditionMatchesOnEqualExpressionWithMultipleValues(): void
232 {
233 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 = 10|20|30]'));
234 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 = 10.1|20.2|30.3]'));
235 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 = 10|20|30]'));
236 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20.2 = 10.1|20.2|30.3]'));
237 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 == 10|20|30]'));
238 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 == 10.1|20.2|30.3]'));
239 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 == 10|20|30]'));
240 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20.2 == 10.1|20.2|30.3]'));
241 }
242
243 /**
244 * Tests whether numerical comparison matches.
245 *
246 * @test
247 */
248 public function globalVarConditionMatchesOnNotEqualExpression(): void
249 {
250 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20]'));
251 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2]'));
252 }
253
254 /**
255 * Tests whether numerical comparison does not match.
256 *
257 * @test
258 */
259 public function globalVarConditionDoesNotMatchOnNotEqualExpression(): void
260 {
261 $this->assertFalse($this->matchCondition->match('[globalVar = LIT:10 != 10]'));
262 }
263
264 /**
265 * Tests whether numerical comparison matches.
266 *
267 * @test
268 */
269 public function globalVarConditionMatchesOnNotEqualExpressionWithMultipleValues(): void
270 {
271 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 != 20|30]'));
272 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 != 10.2|20.3]'));
273 }
274
275 /**
276 * Tests whether numerical comparison matches.
277 *
278 * @test
279 */
280 public function globalVarConditionMatchesOnLowerThanExpression(): void
281 {
282 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 < 20]'));
283 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 < 10.2]'));
284 }
285
286 /**
287 * Tests whether numerical comparison matches.
288 *
289 * @test
290 */
291 public function globalVarConditionMatchesOnLowerThanOrEqualExpression(): void
292 {
293 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 10]'));
294 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 <= 20]'));
295 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.1]'));
296 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 <= 10.2]'));
297 }
298
299 /**
300 * Tests whether numerical comparison matches.
301 *
302 * @test
303 */
304 public function globalVarConditionMatchesOnGreaterThanExpression(): void
305 {
306 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 > 10]'));
307 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 > 10.1]'));
308 }
309
310 /**
311 * Tests whether numerical comparison matches.
312 *
313 * @test
314 */
315 public function globalVarConditionMatchesOnGreaterThanOrEqualExpression(): void
316 {
317 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10 >= 10]'));
318 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:20 >= 10]'));
319 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.1 >= 10.1]'));
320 $this->assertTrue($this->matchCondition->match('[globalVar = LIT:10.2 >= 10.1]'));
321 }
322
323 /**
324 * Tests whether numerical comparison matches.
325 *
326 * @test
327 */
328 public function globalVarConditionMatchesOnEmptyExpressionWithNoValueSet(): void
329 {
330 $testKey = $this->getUniqueId('test');
331 $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]'));
332 $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]'));
333 }
334
335 /**
336 * Tests whether numerical comparison matches.
337 *
338 * @test
339 */
340 public function globalVarConditionDoesNotMatchOnEmptyExpressionWithValueSetToZero(): void
341 {
342 $testKey = $this->getUniqueId('test');
343 $_GET = [];
344 $_POST = [$testKey => 0];
345 $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . '=]'));
346 $this->assertFalse($this->matchCondition->match('[globalVar = GP:' . $testKey . ' = ]'));
347 }
348
349 /**
350 * Tests whether an array with zero as key matches its value
351 *
352 * @test
353 */
354 public function globalVarConditionMatchesOnArrayExpressionWithZeroAsKey(): void
355 {
356 $testKey = $this->getUniqueId('test');
357 $testValue = '1';
358 $_GET = [];
359 $_POST = [$testKey => ['0' => $testValue]];
360 $this->assertTrue($this->matchCondition->match('[globalVar = GP:' . $testKey . '|0=' . $testValue . ']'));
361 }
362
363 /**
364 * Tests whether string comparison matches.
365 *
366 * @test
367 */
368 public function globalStringConditionMatchesOnEqualExpression(): void
369 {
370 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.Test.Condition]'));
371 $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3]'));
372 }
373
374 /**
375 * Tests whether string comparison matches.
376 *
377 * @test
378 */
379 public function globalStringConditionMatchesOnEmptyExpressionWithValueSetToEmptyString(): void
380 {
381 $testKey = $this->getUniqueId('test');
382 $_GET = [];
383 $_POST = [$testKey => ''];
384 $this->assertTrue($this->matchCondition->match('[globalString = GP:' . $testKey . '=]'));
385 $this->assertTrue($this->matchCondition->match('[globalString = GP:' . $testKey . ' = ]'));
386 }
387
388 /**
389 * Tests whether string comparison matches.
390 *
391 * @test
392 */
393 public function globalStringConditionMatchesOnEmptyLiteralExpressionWithValueSetToEmptyString(): void
394 {
395 $this->assertTrue($this->matchCondition->match('[globalString = LIT:=]'));
396 $this->assertTrue($this->matchCondition->match('[globalString = LIT: = ]'));
397 }
398
399 /**
400 * Tests whether string comparison matches.
401 *
402 * @test
403 */
404 public function globalStringConditionMatchesWildcardExpression(): void
405 {
406 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?Test?Condition]'));
407 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3.T*t.Condition]'));
408 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = TYPO3?T*t?Condition]'));
409 }
410
411 /**
412 * Tests whether string comparison matches.
413 *
414 * @test
415 */
416 public function globalStringConditionMatchesRegularExpression(): void
417 {
418 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^[A-Za-z3.]+$/]'));
419 $this->assertTrue($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^TYPO3\\..+Condition$/]'));
420 $this->assertFalse($this->matchCondition->match('[globalString = LIT:TYPO3.Test.Condition = /^FALSE/]'));
421 }
422
423 /**
424 * Tests whether string comparison matches.
425 *
426 * @test
427 */
428 public function globalStringConditionMatchesEmptyRegularExpression(): void
429 {
430 $testKey = $this->getUniqueId('test');
431 $_SERVER[$testKey] = '';
432 $this->assertTrue($this->matchCondition->match('[globalString = _SERVER|' . $testKey . ' = /^$/]'));
433 }
434
435 /**
436 * Tests whether treeLevel comparison matches.
437 *
438 * @test
439 */
440 public function treeLevelConditionMatchesSingleValue(): void
441 {
442 $this->assertTrue($this->matchCondition->match('[treeLevel = 2]'));
443 }
444
445 /**
446 * Tests whether treeLevel comparison matches.
447 *
448 * @test
449 */
450 public function treeLevelConditionMatchesMultipleValues(): void
451 {
452 $this->assertTrue($this->matchCondition->match('[treeLevel = 999,998,2]'));
453 }
454
455 /**
456 * Tests whether treeLevel comparison matches.
457 *
458 * @test
459 */
460 public function treeLevelConditionDoesNotMatchFaultyValue(): void
461 {
462 $this->assertFalse($this->matchCondition->match('[treeLevel = 999]'));
463 }
464
465 /**
466 * Tests whether a page Id is found in the previous rootline entries.
467 *
468 * @test
469 */
470 public function PIDupinRootlineConditionMatchesSinglePageIdInRootline(): void
471 {
472 $GLOBALS['TSFE']->id = 121;
473 $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 111]'));
474 }
475
476 /**
477 * Tests whether a page Id is found in the previous rootline entries.
478 *
479 * @test
480 */
481 public function PIDupinRootlineConditionMatchesMultiplePageIdsInRootline(): void
482 {
483 $GLOBALS['TSFE']->id = 121;
484 $this->assertTrue($this->matchCondition->match('[PIDupinRootline = 999,111,101]'));
485 }
486
487 /**
488 * Tests whether a page Id is found in the previous rootline entries.
489 *
490 * @test
491 */
492 public function PIDupinRootlineConditionDoesNotMatchPageIdNotInRootline(): void
493 {
494 $GLOBALS['TSFE']->id = 121;
495 $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 999]'));
496 }
497
498 /**
499 * Tests whether a page Id is found in the previous rootline entries.
500 *
501 * @test
502 */
503 public function PIDupinRootlineConditionDoesNotMatchLastPageIdInRootline(): void
504 {
505 $GLOBALS['TSFE']->id = 121;
506 $this->assertFalse($this->matchCondition->match('[PIDupinRootline = 121]'));
507 }
508
509 /**
510 * Tests whether a page Id is found in all rootline entries.
511 *
512 * @test
513 */
514 public function PIDinRootlineConditionMatchesSinglePageIdInRootline(): void
515 {
516 $GLOBALS['TSFE']->id = 121;
517 $this->assertTrue($this->matchCondition->match('[PIDinRootline = 111]'));
518 }
519
520 /**
521 * Tests whether a page Id is found in all rootline entries.
522 *
523 * @test
524 */
525 public function PIDinRootlineConditionMatchesMultiplePageIdsInRootline(): void
526 {
527 $GLOBALS['TSFE']->id = 121;
528 $this->assertTrue($this->matchCondition->match('[PIDinRootline = 999,111,101]'));
529 }
530
531 /**
532 * Tests whether a page Id is found in all rootline entries.
533 *
534 * @test
535 */
536 public function PIDinRootlineConditionMatchesLastPageIdInRootline(): void
537 {
538 $GLOBALS['TSFE']->id = 121;
539 $this->assertTrue($this->matchCondition->match('[PIDinRootline = 121]'));
540 }
541
542 /**
543 * Tests whether a page Id is found in all rootline entries.
544 *
545 * @test
546 */
547 public function PIDinRootlineConditionDoesNotMatchPageIdNotInRootline(): void
548 {
549 $GLOBALS['TSFE']->id = 121;
550 $this->assertFalse($this->matchCondition->match('[PIDinRootline = 999]'));
551 }
552
553 /**
554 * Tests whether the compatibility version can be evaluated.
555 * (e.g. 7.9 is compatible to 7.0 but not to 15.0)
556 *
557 * @test
558 */
559 public function compatVersionConditionMatchesOlderRelease(): void
560 {
561 $this->assertTrue($this->matchCondition->match('[compatVersion = 7.0]'));
562 }
563
564 /**
565 * Tests whether the compatibility version can be evaluated.
566 * (e.g. 7.9 is compatible to 7.0 but not to 15.0)
567 *
568 * @test
569 */
570 public function compatVersionConditionMatchesSameRelease(): void
571 {
572 $this->assertTrue($this->matchCondition->match('[compatVersion = ' . TYPO3_branch . ']'));
573 }
574
575 /**
576 * Tests whether the compatibility version can be evaluated.
577 * (e.g. 7.9 is compatible to 7.0 but not to 15.0)
578 *
579 * @test
580 */
581 public function compatVersionConditionDoesNotMatchNewerRelease(): void
582 {
583 $this->assertFalse($this->matchCondition->match('[compatVersion = 15.0]'));
584 }
585
586 /**
587 * Tests whether the generic fetching of variables works with the namespace 'GP'.
588 *
589 * @test
590 */
591 public function genericGetVariablesSucceedsWithNamespaceGP(): void
592 {
593 $_GET = ['testGet' => 'getTest'];
594 $_POST = ['testPost' => 'postTest'];
595 $this->assertTrue($this->matchCondition->match('[globalString = GP:testGet = getTest]'));
596 $this->assertTrue($this->matchCondition->match('[globalString = GP:testPost = postTest]'));
597 }
598
599 /**
600 * Tests whether the generic fetching of variables works with the namespace 'TSFE'.
601 *
602 * @test
603 */
604 public function genericGetVariablesSucceedsWithNamespaceTSFE(): void
605 {
606 $GLOBALS['TSFE']->id = 1234567;
607 $GLOBALS['TSFE']->testSimpleObject = new \stdClass();
608 $GLOBALS['TSFE']->testSimpleObject->testSimpleVariable = 'testValue';
609
610 $this->assertTrue($this->matchCondition->match('[globalString = TSFE:id = 1234567]'));
611 $this->assertTrue($this->matchCondition->match('[globalString = TSFE:testSimpleObject|testSimpleVariable = testValue]'));
612 }
613
614 /**
615 * Tests whether the generic fetching of variables works with the namespace 'session'.
616 *
617 * @test
618 */
619 public function genericGetVariablesSucceedsWithNamespaceSession(): void
620 {
621 $prophecy = $this->prophesize(FrontendUserAuthentication::class);
622 $prophecy->getSessionData(Argument::exact('foo'))->willReturn(['bar' => 1234567]);
623 $GLOBALS['TSFE']->fe_user = $prophecy->reveal();
624
625 $this->assertTrue($this->matchCondition->match('[globalString = session:foo|bar = 1234567]'));
626 }
627
628 /**
629 * Tests whether the generic fetching of variables works with the namespace 'ENV'.
630 *
631 * @test
632 */
633 public function genericGetVariablesSucceedsWithNamespaceENV(): void
634 {
635 $testKey = $this->getUniqueId('test');
636 putenv($testKey . '=testValue');
637 $this->assertTrue($this->matchCondition->match('[globalString = ENV:' . $testKey . ' = testValue]'));
638 }
639
640 /**
641 * Tests whether the generic fetching of variables works with the namespace 'IENV'.
642 *
643 * @test
644 */
645 public function genericGetVariablesSucceedsWithNamespaceIENV(): void
646 {
647 $_SERVER['HTTP_HOST'] = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY') . ':1234567';
648 $this->assertTrue($this->matchCondition->match('[globalString = IENV:TYPO3_PORT = 1234567]'));
649 }
650
651 /**
652 * Tests whether the generic fetching of variables works with any global namespace.
653 *
654 * @test
655 */
656 public function genericGetVariablesSucceedsWithAnyGlobalNamespace(): void
657 {
658 $GLOBALS[$this->testGlobalNamespace] = [
659 'first' => 'testFirst',
660 'second' => ['third' => 'testThird']
661 ];
662 $this->assertTrue($this->matchCondition->match('[globalString = ' . $this->testGlobalNamespace . '|first = testFirst]'));
663 $this->assertTrue($this->matchCondition->match('[globalString = ' . $this->testGlobalNamespace . '|second|third = testThird]'));
664 }
665
666 /**
667 * @test
668 */
669 public function matchThrowsExceptionIfConditionClassDoesNotInheritFromAbstractCondition(): void
670 {
671 $this->expectException(InvalidTypoScriptConditionException::class);
672 $this->expectExceptionCode(1410286153);
673 $this->matchCondition->match('[stdClass = foo]');
674 }
675
676 /**
677 * @test
678 */
679 public function matchCallsTestConditionAndHandsOverParameters(): void
680 {
681 $this->expectException(TestConditionException::class);
682 $this->expectExceptionCode(1411581139);
683 $this->matchCondition->match('[TYPO3\\CMS\\Frontend\\Tests\\Unit\\Configuration\\TypoScript\\ConditionMatching\\Fixtures\\TestCondition = 7, != 6]');
684 }
685 }