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