TYPO3 CMS  TYPO3_8-7
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 
23 class RichtextTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
24 {
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  'classes' => [
66  'aClass' => 'aConfig',
67  ],
68  'proc' => [
69  'overruleMode' => 'myTransformation',
70  ],
71  ];
72  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
73  // which can't be mocked in a sane way
74  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
75  $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
76  $output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
77  $this->assertSame($expected, $output);
78  }
79 
84  {
85  $fieldConfig = [
86  'type' => 'text',
87  'enableRichtext' => true,
88  ];
89  $pageTsConfig = [
90  'properties' => [
91  'classes.' => [
92  'aClass' => 'aConfig',
93  ],
94  'default.' => [
95  'removeComments' => '1',
96  ],
97  'config.' => [
98  'aTable.' => [
99  'aField.' => [
100  'proc.' => [
101  'overruleMode' => 'myTransformation',
102  ],
103  ]
104  ]
105  ]
106  ]
107  ];
108  $expected = [
109  'classes.' => [
110  'aClass' => 'aConfig',
111  ],
112  'removeComments' => '1',
113  'proc.' => [
114  'overruleMode' => 'myTransformation',
115  ],
116  'classes' => [
117  'aClass' => 'aConfig',
118  ],
119  'proc' => [
120  'overruleMode' => 'myTransformation',
121  ],
122  ];
123  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
124  // which can't be mocked in a sane way
125  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
126  $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
127  $output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
128  $this->assertSame($expected, $output);
129  }
130 
135  {
136  $fieldConfig = [
137  'type' => 'text',
138  'enableRichtext' => true,
139  ];
140  $pageTsConfig = [
141  'properties' => [
142  'classes.' => [
143  'aClass' => 'aConfig',
144  ],
145  'default.' => [
146  'removeComments' => '1',
147  ],
148  ]
149  ];
150  $expected = [
151  'classes.' => [
152  'aClass' => 'aConfig',
153  ],
154  'removeComments' => '1',
155  'classes' => [
156  'aClass' => 'aConfig',
157  ],
158  'proc.' => [
159  'overruleMode' => 'default',
160  ],
161  ];
162  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
163  // which can't be mocked in a sane way
164  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
165  $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
166  $output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
167  $this->assertSame($expected, $output);
168  }
169 
174  {
175  $fieldConfig = [
176  'type' => 'text',
177  'enableRichtext' => true,
178  ];
179  $pageTsConfig = [
180  'properties' => [
181  'classes.' => [
182  'aClass' => 'aConfig',
183  ],
184  'default.' => [
185  'proc.' => [
186  'overruleMode' => 'ts_css',
187  ],
188  ],
189  ],
190  ];
191  $expected = [
192  'classes.' => [
193  'aClass' => 'aConfig',
194  ],
195  'proc.' => [
196  'overruleMode' => 'default',
197  ],
198  'classes' => [
199  'aClass' => 'aConfig',
200  ],
201  'proc' => [
202  'overruleMode' => 'ts_css',
203  ],
204  ];
205  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
206  // which can't be mocked in a sane way
207  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
208  $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
209  $output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
210  $this->assertSame($expected, $output);
211  }
212 
217  {
218  $fieldConfig = [
219  'type' => 'text',
220  'enableRichtext' => true,
221  ];
222  $pageTsConfig = [
223  'properties' => [
224  'classes.' => [
225  'aClass' => 'aConfig',
226  ],
227  'default.' => [
228  'classes.' => [
229  'aClass' => 'anotherConfig',
230  ],
231  'editor.' => [
232  'config.' => [
233  'contentsCss' => 'my.css'
234  ]
235  ],
236  ],
237  ],
238  ];
239  $expected = [
240  'classes.' => [
241  'aClass' => 'anotherConfig',
242  ],
243  'editor.' => [
244  'config.' => [
245  'contentsCss' => 'my.css'
246  ]
247  ],
248  'classes' => [
249  'aClass' => 'anotherConfig',
250  ],
251  'editor' => [
252  'config' => [
253  'contentsCss' => 'my.css'
254  ]
255  ],
256  'proc.' => [
257  'overruleMode' => 'default',
258  ],
259  ];
260  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
261  // which can't be mocked in a sane way
262  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
263  $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
264  $output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
265  $this->assertSame($expected, $output);
266  }
267 
272  {
273  $fieldConfig = [
274  'type' => 'text',
275  'enableRichtext' => true,
276  ];
277  $pageTsConfig = [
278  'properties' => [
279  'classes.' => [
280  'aClass' => 'aConfig',
281  ],
282  'default.' => [
283  'classes.' => [
284  'aClass' => 'anotherConfig',
285  ],
286  ],
287  'config.' => [
288  'aTable.' => [
289  'aField.' => [
290  'classes.' => [
291  'aClass' => 'aThirdConfig',
292  ],
293  'editor.' => [
294  'config.' => [
295  'contentsCss' => 'my.css'
296  ]
297  ],
298  ],
299  ],
300  ],
301  ],
302  ];
303  $expected = [
304  // Config with pagets dots
305  'classes.' => [
306  'aClass' => 'aThirdConfig',
307  ],
308  'editor.' => [
309  'config.' => [
310  'contentsCss' => 'my.css'
311  ]
312  ],
313  // Config without pagets dots
314  'classes' => [
315  'aClass' => 'aThirdConfig',
316  ],
317  'editor' => [
318  'config' => [
319  'contentsCss' => 'my.css'
320  ]
321  ],
322  'proc.' => [
323  'overruleMode' => 'default',
324  ],
325  ];
326  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
327  // which can't be mocked in a sane way
328  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
329  $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
330  $output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
331  $this->assertSame($expected, $output);
332  }
333 
338  {
339  $fieldConfig = [
340  'type' => 'text',
341  'enableRichtext' => true,
342  ];
343  $pageTsConfig = [
344  'properties' => [
345  'classes.' => [
346  'aClass' => 'aConfig',
347  ],
348  'default.' => [
349  'classes.' => [
350  'aClass' => 'anotherConfig',
351  ],
352  ],
353  'config.' => [
354  'aTable.' => [
355  'aField.' => [
356  'classes.' => [
357  'aClass' => 'aThirdConfig',
358  ],
359  'editor.' => [
360  'config.' => [
361  'contentsCss' => 'my.css'
362  ]
363  ],
364  'types.' => [
365  'textmedia.' => [
366  'classes.' => [
367  'aClass' => 'aTypeSpecifcConfig',
368  ],
369  'editor.' => [
370  'config.' => [
371  'contentsCss' => 'your.css'
372  ]
373  ],
374  ]
375  ]
376  ],
377  ],
378  ],
379  ],
380  ];
381  $expected = [
382  // Config with pagets dots
383  'classes.' => [
384  'aClass' => 'aTypeSpecifcConfig',
385  ],
386  'editor.' => [
387  'config.' => [
388  'contentsCss' => 'your.css'
389  ]
390  ],
391  // Config without pagets dots
392  'classes' => [
393  'aClass' => 'aTypeSpecifcConfig',
394  ],
395  'editor' => [
396  'config' => [
397  'contentsCss' => 'your.css'
398  ]
399  ],
400  'proc.' => [
401  'overruleMode' => 'default',
402  ],
403  ];
404  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
405  // which can't be mocked in a sane way
406  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
407  $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
408  $output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
409  $this->assertSame($expected, $output);
410  }
411 
416  {
417  $pageId = 42;
418  $presetKey = 'default';
419 
420  $preset = [
421  'editor' => [
422  'config' => [
423  'width' => 100
424  ],
425  ],
426  ];
427 
428  $pageTsConfigArray = [
429  'properties' => [
430  'preset' => $presetKey,
431  'editor.' => [
432  'config.' => [
433  'width' => 200
434  ],
435  ],
436  ],
437  ];
438 
439  $subject = $this->getAccessibleMock(
440  Richtext::class,
441  ['loadConfigurationFromPreset', 'getRtePageTsConfigOfPid'],
442  [],
443  '',
444  false
445  );
446  $subject->expects($this->once())->method('loadConfigurationFromPreset')->with($presetKey)->willReturn($preset);
447  $subject->expects($this->once())->method('getRtePageTsConfigOfPid')->with($pageId)->willReturn($pageTsConfigArray);
448 
449  $output = $subject->getConfiguration('tt_content', 'bodytext', $pageId, 'textmedia', $pageTsConfigArray);
450 
451  $expected = [
452  'editor' => [
453  'config' => [
454  'width' => 200
455  ],
456  ],
457  'preset' => 'default',
458  'editor.' => [
459  'config.' => [
460  'width' => 200
461  ],
462  ],
463  'proc.' => [
464  'overruleMode' => 'default',
465  ],
466  ];
467 
468  $this->assertSame($expected, $output);
469  }
470 }