‪TYPO3CMS  9.5
RichtextTest.php
Go to the documentation of this file.
1 <?php
2 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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪RichtextTest extends UnitTestCase
25 {
30  {
31  $fieldConfig = [
32  'type' => 'text',
33  'enableRichtext' => true,
34  ];
35  $pageTsConfig = [
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  $expected = [
57  'classes.' => [
58  'aClass' => 'aConfig',
59  ],
60  'removeComments' => '1',
61  'proc.' => [
62  'overruleMode' => 'myTransformation',
63  ],
64  'classes' => [
65  'aClass' => 'aConfig',
66  ],
67  'proc' => [
68  'overruleMode' => 'myTransformation',
69  ],
70  ];
71  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
72  // which can't be mocked in a sane way
73  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
74  $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
75  ‪$output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
76  $this->assertSame($expected, ‪$output);
77  }
78 
83  {
84  $fieldConfig = [
85  'type' => 'text',
86  'enableRichtext' => true,
87  ];
88  $pageTsConfig = [
89  'classes.' => [
90  'aClass' => 'aConfig',
91  ],
92  'default.' => [
93  'removeComments' => '1',
94  ],
95  'config.' => [
96  'aTable.' => [
97  'aField.' => [
98  'proc.' => [
99  'overruleMode' => 'myTransformation',
100  ],
101  ]
102  ]
103  ]
104  ];
105  $expected = [
106  'classes.' => [
107  'aClass' => 'aConfig',
108  ],
109  'removeComments' => '1',
110  'proc.' => [
111  'overruleMode' => 'myTransformation',
112  ],
113  'classes' => [
114  'aClass' => 'aConfig',
115  ],
116  'proc' => [
117  'overruleMode' => 'myTransformation',
118  ],
119  ];
120  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
121  // which can't be mocked in a sane way
122  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
123  $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
124  ‪$output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
125  $this->assertSame($expected, ‪$output);
126  }
127 
132  {
133  $fieldConfig = [
134  'type' => 'text',
135  'enableRichtext' => true,
136  ];
137  $pageTsConfig = [
138  'classes.' => [
139  'aClass' => 'aConfig',
140  ],
141  'default.' => [
142  'removeComments' => '1',
143  ],
144  ];
145  $expected = [
146  'classes.' => [
147  'aClass' => 'aConfig',
148  ],
149  'removeComments' => '1',
150  'classes' => [
151  'aClass' => 'aConfig',
152  ],
153  'proc.' => [
154  'overruleMode' => 'default',
155  ],
156  ];
157  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
158  // which can't be mocked in a sane way
159  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
160  $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
161  ‪$output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
162  $this->assertSame($expected, ‪$output);
163  }
164 
169  {
170  $fieldConfig = [
171  'type' => 'text',
172  'enableRichtext' => true,
173  ];
174  $pageTsConfig = [
175  'classes.' => [
176  'aClass' => 'aConfig',
177  ],
178  'default.' => [
179  'classes.' => [
180  'aClass' => 'anotherConfig',
181  ],
182  'editor.' => [
183  'config.' => [
184  'contentsCss' => 'my.css'
185  ]
186  ],
187  ],
188  ];
189  $expected = [
190  'classes.' => [
191  'aClass' => 'anotherConfig',
192  ],
193  'editor.' => [
194  'config.' => [
195  'contentsCss' => 'my.css'
196  ]
197  ],
198  'classes' => [
199  'aClass' => 'anotherConfig',
200  ],
201  'editor' => [
202  'config' => [
203  'contentsCss' => 'my.css'
204  ]
205  ],
206  'proc.' => [
207  'overruleMode' => 'default',
208  ],
209  ];
210  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
211  // which can't be mocked in a sane way
212  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
213  $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
214  ‪$output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
215  $this->assertSame($expected, ‪$output);
216  }
217 
222  {
223  $fieldConfig = [
224  'type' => 'text',
225  'enableRichtext' => true,
226  ];
227  $pageTsConfig = [
228  'classes.' => [
229  'aClass' => 'aConfig',
230  ],
231  'default.' => [
232  'classes.' => [
233  'aClass' => 'anotherConfig',
234  ],
235  ],
236  'config.' => [
237  'aTable.' => [
238  'aField.' => [
239  'classes.' => [
240  'aClass' => 'aThirdConfig',
241  ],
242  'editor.' => [
243  'config.' => [
244  'contentsCss' => 'my.css'
245  ]
246  ],
247  ],
248  ],
249  ],
250  ];
251  $expected = [
252  // Config with pagets dots
253  'classes.' => [
254  'aClass' => 'aThirdConfig',
255  ],
256  'editor.' => [
257  'config.' => [
258  'contentsCss' => 'my.css'
259  ]
260  ],
261  // Config without pagets dots
262  'classes' => [
263  'aClass' => 'aThirdConfig',
264  ],
265  'editor' => [
266  'config' => [
267  'contentsCss' => 'my.css'
268  ]
269  ],
270  'proc.' => [
271  'overruleMode' => 'default',
272  ],
273  ];
274  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
275  // which can't be mocked in a sane way
276  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
277  $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
278  ‪$output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
279  $this->assertSame($expected, ‪$output);
280  }
281 
286  {
287  $fieldConfig = [
288  'type' => 'text',
289  'enableRichtext' => true,
290  ];
291  $pageTsConfig = [
292  'classes.' => [
293  'aClass' => 'aConfig',
294  ],
295  'default.' => [
296  'classes.' => [
297  'aClass' => 'anotherConfig',
298  ],
299  ],
300  'config.' => [
301  'aTable.' => [
302  'aField.' => [
303  'classes.' => [
304  'aClass' => 'aThirdConfig',
305  ],
306  'editor.' => [
307  'config.' => [
308  'contentsCss' => 'my.css'
309  ]
310  ],
311  'types.' => [
312  'textmedia.' => [
313  'classes.' => [
314  'aClass' => 'aTypeSpecifcConfig',
315  ],
316  'editor.' => [
317  'config.' => [
318  'contentsCss' => 'your.css'
319  ]
320  ],
321  ]
322  ]
323  ],
324  ],
325  ],
326  ];
327  $expected = [
328  // Config with pagets dots
329  'classes.' => [
330  'aClass' => 'aTypeSpecifcConfig',
331  ],
332  'editor.' => [
333  'config.' => [
334  'contentsCss' => 'your.css'
335  ]
336  ],
337  // Config without pagets dots
338  'classes' => [
339  'aClass' => 'aTypeSpecifcConfig',
340  ],
341  'editor' => [
342  'config' => [
343  'contentsCss' => 'your.css'
344  ]
345  ],
346  'proc.' => [
347  'overruleMode' => 'default',
348  ],
349  ];
350  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
351  // which can't be mocked in a sane way
352  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
353  $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
354  ‪$output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
355  $this->assertSame($expected, ‪$output);
356  }
357 
362  {
363  $pageId = 42;
364  $presetKey = 'default';
365 
366  $preset = [
367  'editor' => [
368  'config' => [
369  'width' => 100
370  ],
371  ],
372  ];
373 
374  $pageTsConfigArray = [
375  'preset' => $presetKey,
376  'editor.' => [
377  'config.' => [
378  'width' => 200
379  ],
380  ],
381  ];
382 
383  $subject = $this->getAccessibleMock(
384  Richtext::class,
385  ['loadConfigurationFromPreset', 'getRtePageTsConfigOfPid'],
386  [],
387  '',
388  false
389  );
390  $subject->expects($this->once())->method('loadConfigurationFromPreset')->with($presetKey)->willReturn($preset);
391  $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with($pageId)->willReturn($pageTsConfigArray);
392 
393  ‪$output = $subject->getConfiguration('tt_content', 'bodytext', $pageId, 'textmedia', $pageTsConfigArray);
394 
395  $expected = [
396  'editor' => [
397  'config' => [
398  'width' => 200
399  ],
400  ],
401  'preset' => 'default',
402  'editor.' => [
403  'config.' => [
404  'width' => 200
405  ],
406  ],
407  'proc.' => [
408  'overruleMode' => 'default',
409  ],
410  ];
411 
412  $this->assertSame($expected, ‪$output);
413  }
414 }
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest
Definition: RichtextTest.php:25
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\getConfigurationOverridesByFieldAndTypeSpecificConfig
‪getConfigurationOverridesByFieldAndTypeSpecificConfig()
Definition: RichtextTest.php:285
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\getConfigurationUsesOverruleModeFromConfig
‪getConfigurationUsesOverruleModeFromConfig()
Definition: RichtextTest.php:82
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\getConfigurationOverridesByFieldSpecificConfig
‪getConfigurationOverridesByFieldSpecificConfig()
Definition: RichtextTest.php:221
‪$output
‪$output
Definition: annotationChecker.php:113
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\getConfigurationSetsOverruleModeIfMissing
‪getConfigurationSetsOverruleModeIfMissing()
Definition: RichtextTest.php:131
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\getConfigurationPageTsOverridesPreset
‪getConfigurationPageTsOverridesPreset()
Definition: RichtextTest.php:361
‪TYPO3\CMS\Core\Configuration\Richtext
Definition: Richtext.php:31
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\getConfigurationUsesOverruleModeFromType
‪getConfigurationUsesOverruleModeFromType()
Definition: RichtextTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\getConfigurationOverridesByDefault
‪getConfigurationOverridesByDefault()
Definition: RichtextTest.php:168
‪TYPO3\CMS\Core\Tests\Unit\Configuration
Definition: ConfigurationManagerTest.php:4