‪TYPO3CMS  ‪main
PageTsConfigParserTest.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 
20 use Psr\Log\NullLogger;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
31 final class ‪PageTsConfigParserTest extends UnitTestCase
32 {
36  public function ‪invalidCacheAlwaysExecutesMatcher(): void
37  {
38  $input = 'mod.web_layout = disabled';
39  $expectedParsedTsConfig = ['mod' => ['web_layout' => 'disabled']];
40  $matcherMock = $this->createMock(ConditionMatcherInterface::class);
41  $typoScriptParserMock = $this->createMock(TypoScriptParser::class);
42  $parseClosure = function (string $string, object|string $matchObj) use ($expectedParsedTsConfig): void {
44  $this->setup = $expectedParsedTsConfig;
45  };
46  $typoScriptParserMock->expects(self::once())->method('parse')->with($input, $matcherMock)->willReturnCallback(\Closure::bind($parseClosure, $typoScriptParserMock));
47  $cache = new ‪NullFrontend('runtime');
48  $subject = new ‪PageTsConfigParser(
49  $typoScriptParserMock,
50  $cache
51  );
52  $parsedTsConfig = $subject->parse($input, $matcherMock);
53  self::assertEquals($expectedParsedTsConfig, $parsedTsConfig);
54  }
55 
59  public function ‪cachedHitOnlyExecutesMatcher(): void
60  {
61  $cachedSection = 'mod.web_layout = disabled';
62  $input = 'mod.web_layout = disabled';
63  $expectedParsedTsConfig = ['mod' => ['web_layout' => 'disabled']];
64  $matcherMock = $this->createMock(ConditionMatcherInterface::class);
65  $matcherMock->expects(self::once())->method('match')->with($cachedSection)->willReturn(true);
66  $typoScriptParserMock = $this->createMock(TypoScriptParser::class);
67  $typoScriptParserMock->expects(self::never())->method('parse')->with($input, $matcherMock);
68  $cache = new ‪VariableFrontend('runtime', new ‪TransientMemoryBackend('nothing', ['logger' => new NullLogger()]));
69  $cache->set(
70  '1d0a3029a36cc56a82bfdb0642fcd912',
71  [
72  0 => [
73  'sections' => [$cachedSection],
74  'TSconfig' => ['mod' => ['web_layout' => 'disabled']],
75  ],
76  1 => 'fb3c41ea55f42a993fc143a54e09bbdd', ]
77  );
78  $subject = new ‪PageTsConfigParser(
79  $typoScriptParserMock,
80  $cache
81  );
82  $parsedTsConfig = $subject->parse($input, $matcherMock);
83  self::assertEquals($expectedParsedTsConfig, $parsedTsConfig);
84  }
85 
89  public function ‪parseReplacesSiteSettings(): void
90  {
91  $input = 'mod.web_layout = {$numberedThings.1}' . "\n" .
92  'mod.no-replace = {$styles.content}' . "\n" .
93  'mod.content = {$styles.content.loginform.pid}';
94  $expectedParsedTsConfig = [
95  'mod.' => [
96  'web_layout' => 'foo',
97  'no-replace' => '{$styles.content}',
98  'content' => '123',
99  ],
100  ];
101 
102  $matcherMock = $this->createMock(ConditionMatcherInterface::class);
103  $cache = new ‪NullFrontend('runtime');
104  $site = new ‪Site(
105  'dummy',
106  13,
107  [
108  'base' => 'https://example.com',
109  ],
110  new ‪SiteSettings(
111  [
112  'random' => 'value',
113  'styles' => [
114  'content' => [
115  'loginform' => [
116  'pid' => 123,
117  ],
118  ],
119  ],
120  'numberedThings' => [
121  1 => 'foo',
122  99 => 'bar',
123  ],
124  ]
125  )
126  );
127  $subject = new ‪PageTsConfigParser(
128  new ‪TypoScriptParser(),
129  $cache
130  );
131  $parsedTsConfig = $subject->parse($input, $matcherMock, $site);
132  self::assertEquals($expectedParsedTsConfig, $parsedTsConfig);
133  }
134 
139  {
140  $input = 'mod.web_layout = {$numberedThings.1}';
141  $expectedParsedTsConfig = [
142  'mod.' => [
143  'web_layout' => 'foo',
144  ],
145  ];
146  $expectedParsedTsConfig2 = [
147  'mod.' => [
148  'web_layout' => 'bar',
149  ],
150  ];
151 
152  $matcherMock = $this->createMock(ConditionMatcherInterface::class);
153  $cache = new ‪VariableFrontend('runtime', new ‪TransientMemoryBackend('nothing', ['logger' => new NullLogger()]));
154 
155  $site = new ‪Site('dummy', 13, [
156  'base' => 'https://example.com',
157  'settings' => [
158  'numberedThings' => [
159  1 => 'foo',
160  ],
161  ],
162  ]);
163  $subject = new ‪PageTsConfigParser(
164  new ‪TypoScriptParser(),
165  $cache
166  );
167  $parsedTsConfig = $subject->parse($input, $matcherMock, $site);
168  self::assertEquals($expectedParsedTsConfig, $parsedTsConfig);
169 
170  $site2 = new ‪Site('dummy2', 14, [
171  'base' => 'https://example2.com',
172  'settings' => [
173  'numberedThings' => [
174  1 => 'bar',
175  ],
176  ],
177  ]);
178  $subject2 = new ‪PageTsConfigParser(
179  new ‪TypoScriptParser(),
180  $cache
181  );
182  $parsedTsConfig2 = $subject2->parse($input, $matcherMock, $site2);
183  self::assertEquals($expectedParsedTsConfig2, $parsedTsConfig2);
184  }
185 }
‪TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend
Definition: TransientMemoryBackend.php:25
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Configuration\Parser\PageTsConfigParserTest
Definition: PageTsConfigParserTest.php:32
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Configuration\Parser
Definition: PageTsConfigParserTest.php:18
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
Definition: TypoScriptParser.php:38
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Configuration\Parser\PageTsConfigParserTest\parseReplacesSiteSettingsWithMultipleSitesAndCache
‪parseReplacesSiteSettingsWithMultipleSitesAndCache()
Definition: PageTsConfigParserTest.php:138
‪TYPO3\CMS\Core\Cache\Frontend\NullFrontend
Definition: NullFrontend.php:30
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Configuration\Parser\PageTsConfigParserTest\cachedHitOnlyExecutesMatcher
‪cachedHitOnlyExecutesMatcher()
Definition: PageTsConfigParserTest.php:59
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:42
‪TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\ConditionMatcherInterface
Definition: ConditionMatcherInterface.php:26
‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
Definition: VariableFrontend.php:25
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Configuration\Parser\PageTsConfigParserTest\invalidCacheAlwaysExecutesMatcher
‪invalidCacheAlwaysExecutesMatcher()
Definition: PageTsConfigParserTest.php:36
‪TYPO3\CMS\Core\Configuration\Parser\PageTsConfigParser
Definition: PageTsConfigParser.php:35
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Configuration\Parser\PageTsConfigParserTest\parseReplacesSiteSettings
‪parseReplacesSiteSettings()
Definition: PageTsConfigParserTest.php:89
‪TYPO3\CMS\Core\Site\Entity\SiteSettings
Definition: SiteSettings.php:28