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