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