[BUGFIX] Ensure pageTS is overriding on top-level RTE syntax
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Configuration / RichtextTest.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Configuration;
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
18 use TYPO3\CMS\Core\Configuration\Richtext;
19
20 /**
21 * Test case
22 */
23 class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
24 {
25 /**
26 * @test
27 */
28 public function getConfigurationUsesOverruleModeFromType()
29 {
30 $fieldConfig = [
31 'type' => 'text',
32 'enableRichtext' => true,
33 ];
34 $pageTsConfig = [
35 'properties' => [
36 'classes.' => [
37 'aClass.' => 'aConfig',
38 ],
39 'default.' => [
40 'removeComments' => '1',
41 ],
42 'config.' => [
43 'aTable.' => [
44 'aField.' => [
45 'types.' => [
46 'textmedia.' => [
47 'proc.' => [
48 'overruleMode' => 'myTransformation',
49 ],
50 ]
51 ]
52 ]
53 ]
54 ]
55 ]
56 ];
57 $expected = [
58 'classes.' => [
59 'aClass.' => 'aConfig',
60 ],
61 'removeComments' => '1',
62 'proc.' => [
63 'overruleMode' => 'myTransformation',
64 ],
65 ];
66 // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
67 // which can't be mocked in a sane way
68 $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
69 $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
70 $output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
71 $this->assertSame($expected, $output);
72 }
73
74 /**
75 * @test
76 */
77 public function getConfigurationUsesOverruleModeFromConfig()
78 {
79 $fieldConfig = [
80 'type' => 'text',
81 'enableRichtext' => true,
82 ];
83 $pageTsConfig = [
84 'properties' => [
85 'classes.' => [
86 'aClass.' => 'aConfig',
87 ],
88 'default.' => [
89 'removeComments' => '1',
90 ],
91 'config.' => [
92 'aTable.' => [
93 'aField.' => [
94 'proc.' => [
95 'overruleMode' => 'myTransformation',
96 ],
97 ]
98 ]
99 ]
100 ]
101 ];
102 $expected = [
103 'classes.' => [
104 'aClass.' => 'aConfig',
105 ],
106 'removeComments' => '1',
107 'proc.' => [
108 'overruleMode' => 'myTransformation',
109 ],
110 ];
111 // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
112 // which can't be mocked in a sane way
113 $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
114 $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
115 $output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
116 $this->assertSame($expected, $output);
117 }
118
119 /**
120 * @test
121 */
122 public function getConfigurationSetsOverruleModeIfMissing()
123 {
124 $fieldConfig = [
125 'type' => 'text',
126 'enableRichtext' => true,
127 ];
128 $pageTsConfig = [
129 'properties' => [
130 'classes.' => [
131 'aClass.' => 'aConfig',
132 ],
133 'default.' => [
134 'removeComments' => '1',
135 ],
136 ]
137 ];
138 $expected = [
139 'classes.' => [
140 'aClass.' => 'aConfig',
141 ],
142 'removeComments' => '1',
143 'proc.' => [
144 'overruleMode' => 'default',
145 ],
146 ];
147 // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
148 // which can't be mocked in a sane way
149 $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
150 $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
151 $output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
152 $this->assertSame($expected, $output);
153 }
154
155 /**
156 * @test
157 */
158 public function getConfigurationMigratesTsCss()
159 {
160 $fieldConfig = [
161 'type' => 'text',
162 'enableRichtext' => true,
163 ];
164 $pageTsConfig = [
165 'properties' => [
166 'classes.' => [
167 'aClass.' => 'aConfig',
168 ],
169 'default.' => [
170 'proc.' => [
171 'overruleMode' => 'ts_css',
172 ],
173 ],
174 ],
175 ];
176 $expected = [
177 'classes.' => [
178 'aClass.' => 'aConfig',
179 ],
180 'proc.' => [
181 'overruleMode' => 'default',
182 ],
183 ];
184 // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
185 // which can't be mocked in a sane way
186 $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
187 $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
188 $output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
189 $this->assertSame($expected, $output);
190 }
191
192 /**
193 * @test
194 */
195 public function getConfigurationOverridesByDefault()
196 {
197 $fieldConfig = [
198 'type' => 'text',
199 'enableRichtext' => true,
200 ];
201 $pageTsConfig = [
202 'properties' => [
203 'classes.' => [
204 'aClass.' => 'aConfig',
205 ],
206 'default.' => [
207 'classes.' => [
208 'aClass.' => 'anotherConfig',
209 ],
210 ],
211 ],
212 ];
213 $expected = [
214 'classes.' => [
215 'aClass.' => 'anotherConfig',
216 ],
217 'proc.' => [
218 'overruleMode' => 'default',
219 ],
220 ];
221 // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
222 // which can't be mocked in a sane way
223 $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
224 $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
225 $output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
226 $this->assertSame($expected, $output);
227 }
228
229 /**
230 * @test
231 */
232 public function getConfigurationOverridesByFieldSpecificConfig()
233 {
234 $fieldConfig = [
235 'type' => 'text',
236 'enableRichtext' => true,
237 ];
238 $pageTsConfig = [
239 'properties' => [
240 'classes.' => [
241 'aClass.' => 'aConfig',
242 ],
243 'default.' => [
244 'classes.' => [
245 'aClass.' => 'anotherConfig',
246 ],
247 ],
248 'config.' => [
249 'aTable.' => [
250 'aField.' => [
251 'classes.' => [
252 'aClass.' => 'aThirdConfig',
253 ],
254 ],
255 ],
256 ],
257 ],
258 ];
259 $expected = [
260 'classes.' => [
261 'aClass.' => 'aThirdConfig',
262 ],
263 'proc.' => [
264 'overruleMode' => 'default',
265 ],
266 ];
267 // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
268 // which can't be mocked in a sane way
269 $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
270 $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
271 $output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
272 $this->assertSame($expected, $output);
273 }
274
275 /**
276 * @test
277 */
278 public function getConfigurationOverridesByFieldAndTypeSpecificConfig()
279 {
280 $fieldConfig = [
281 'type' => 'text',
282 'enableRichtext' => true,
283 ];
284 $pageTsConfig = [
285 'properties' => [
286 'classes.' => [
287 'aClass.' => 'aConfig',
288 ],
289 'default.' => [
290 'classes.' => [
291 'aClass.' => 'anotherConfig',
292 ],
293 ],
294 'config.' => [
295 'aTable.' => [
296 'aField.' => [
297 'classes.' => [
298 'aClass.' => 'aThirdConfig',
299 ],
300 'types.' => [
301 'textmedia.' => [
302 'classes.' => [
303 'aClass.' => 'aTypeSpecifcConfig',
304 ],
305 ]
306 ]
307 ],
308 ],
309 ],
310 ],
311 ];
312 $expected = [
313 'classes.' => [
314 'aClass.' => 'aTypeSpecifcConfig',
315 ],
316 'proc.' => [
317 'overruleMode' => 'default',
318 ],
319 ];
320 // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
321 // which can't be mocked in a sane way
322 $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
323 $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
324 $output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
325 $this->assertSame($expected, $output);
326 }
327 }