‪TYPO3CMS  ‪main
IncludeTreeSetupConditionConstantSubstitutionVisitorTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 
19 
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
29 {
30  protected bool ‪$initializeDatabase = false;
31 
32  public static function ‪visitDataProvider(): iterable
33  {
34  yield 'nothing to substitute, no condition' => [
35  [],
36  new ‪FileInclude(),
37  new ‪FileInclude(),
38  ];
39 
40  $inputNode = new ‪ConditionInclude();
41  $inputNode->setConditionToken(new ‪Token(TokenType::T_VALUE, 'foo = foo', 0, 0));
42  yield 'nothing to substitute, no constant' => [
43  [],
44  $inputNode,
45  $inputNode,
46  ];
47 
48  $inputNode = new ‪ConditionInclude();
49  $inputNode->setConditionToken(new ‪Token(TokenType::T_VALUE, '{$foo} = bar', 0, 0));
50  $expectedNode = new ‪ConditionInclude();
51  $expectedNode->setConditionToken(new ‪Token(TokenType::T_VALUE, 'fooValue = bar', 0, 0));
52  $expectedNode->setOriginalConditionToken(new ‪Token(TokenType::T_VALUE, '{$foo} = bar', 0, 0));
53  yield 'single substitution' => [
54  ['foo' => 'fooValue'],
55  $inputNode,
56  $expectedNode,
57  ];
58 
59  $inputNode = new ‪ConditionInclude();
60  $inputNode->setConditionToken(new ‪Token(TokenType::T_VALUE, '{$foo} = bar', 0, 0));
61  yield 'single substitution, but no match in constants' => [
62  ['notFoo' => 'fooValue'],
63  $inputNode,
64  $inputNode,
65  ];
66 
67  $inputNode = new ‪ConditionInclude();
68  $inputNode->setConditionToken(new ‪Token(TokenType::T_VALUE, '{$foo} = {$bar}', 0, 0));
69  $expectedNode = new ‪ConditionInclude();
70  $expectedNode->setConditionToken(new ‪Token(TokenType::T_VALUE, 'fooValue = barValue', 0, 0));
71  $expectedNode->setOriginalConditionToken(new ‪Token(TokenType::T_VALUE, '{$foo} = {$bar}', 0, 0));
72  yield 'double substitution' => [
73  ['foo' => 'fooValue', 'bar' => 'barValue'],
74  $inputNode,
75  $expectedNode,
76  ];
77 
78  $inputNode = new ‪ConditionInclude();
79  $inputNode->setConditionToken(new ‪Token(TokenType::T_VALUE, '{$foo.bar} = {$foo\.baz}', 0, 0));
80  $expectedNode = new ‪ConditionInclude();
81  $expectedNode->setConditionToken(new ‪Token(TokenType::T_VALUE, 'barValue = bazValue', 0, 0));
82  $expectedNode->setOriginalConditionToken(new ‪Token(TokenType::T_VALUE, '{$foo.bar} = {$foo\.baz}', 0, 0));
83  yield 'double substitution with dots and quotes' => [
84  ['foo.bar' => 'barValue', 'foo\.baz' => 'bazValue'],
85  $inputNode,
86  $expectedNode,
87  ];
88 
89  $inputNode = new ‪ConditionInclude();
90  $inputNode->setConditionToken(new ‪Token(TokenType::T_VALUE, '{$foo}{$bar} = {$baz}', 0, 0));
91  $expectedNode = new ‪ConditionInclude();
92  $expectedNode->setConditionToken(new ‪Token(TokenType::T_VALUE, 'fooValuebarValue = bazValue', 0, 0));
93  $expectedNode->setOriginalConditionToken(new ‪Token(TokenType::T_VALUE, '{$foo}{$bar} = {$baz}', 0, 0));
94  yield 'triple substitution' => [
95  ['foo' => 'fooValue', 'bar' => 'barValue', 'baz' => 'bazValue'],
96  $inputNode,
97  $expectedNode,
98  ];
99 
100  $inputNode = new ‪ConditionInclude();
101  $inputNode->setConditionToken(new ‪Token(TokenType::T_VALUE, '{$foo}{$bar} = {$baz}', 0, 0));
102  $expectedNode = new ‪ConditionInclude();
103  $expectedNode->setConditionToken(new ‪Token(TokenType::T_VALUE, 'fooValue{$bar} = bazValue', 0, 0));
104  $expectedNode->setOriginalConditionToken(new ‪Token(TokenType::T_VALUE, '{$foo}{$bar} = {$baz}', 0, 0));
105  yield 'triple substitution, one without match' => [
106  ['foo' => 'fooValue', 'baz' => 'bazValue'],
107  $inputNode,
108  $expectedNode,
109  ];
110  }
111 
116  public function ‪visit(array $flattenedConstants, ‪IncludeInterface $node, ‪IncludeInterface $expectedNode): void
117  {
119  $subject->setFlattenedConstants($flattenedConstants);
120  $subject->visitBeforeChildren($node, 0);
121  self::assertEquals($expectedNode, $node);
122  }
123 }
‪TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeSetupConditionConstantSubstitutionVisitor
Definition: IncludeTreeSetupConditionConstantSubstitutionVisitor.php:36
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\Token
Definition: Token.php:29
‪TYPO3\CMS\Core\Tests\Functional\TypoScript\IncludeTree\Visitor\IncludeTreeSetupConditionConstantSubstitutionVisitorTest\visit
‪visit(array $flattenedConstants, IncludeInterface $node, IncludeInterface $expectedNode)
Definition: IncludeTreeSetupConditionConstantSubstitutionVisitorTest.php:116
‪TYPO3\CMS\Core\TypoScript\Tokenizer\Token\TokenType
‪TokenType
Definition: TokenType.php:26
‪TYPO3\CMS\Core\Tests\Functional\TypoScript\IncludeTree\Visitor\IncludeTreeSetupConditionConstantSubstitutionVisitorTest\visitDataProvider
‪static visitDataProvider()
Definition: IncludeTreeSetupConditionConstantSubstitutionVisitorTest.php:32
‪TYPO3\CMS\Core\Tests\Functional\TypoScript\IncludeTree\Visitor\IncludeTreeSetupConditionConstantSubstitutionVisitorTest
Definition: IncludeTreeSetupConditionConstantSubstitutionVisitorTest.php:29
‪TYPO3\CMS\Core\Tests\Functional\TypoScript\IncludeTree\Visitor\IncludeTreeSetupConditionConstantSubstitutionVisitorTest\$initializeDatabase
‪bool $initializeDatabase
Definition: IncludeTreeSetupConditionConstantSubstitutionVisitorTest.php:30
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\IncludeInterface
Definition: IncludeInterface.php:39
‪TYPO3\CMS\Core\Tests\Functional\TypoScript\IncludeTree\Visitor
Definition: IncludeTreeSetupConditionConstantSubstitutionVisitorTest.php:18
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\FileInclude
Definition: FileInclude.php:28
‪TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\ConditionInclude
Definition: ConditionInclude.php:29