‪TYPO3CMS  10.4
RichtextTest.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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪RichtextTest extends UnitTestCase
27 {
32  {
33  $fieldConfig = [
34  'type' => 'text',
35  'enableRichtext' => true,
36  ];
37  $pageTsConfig = [
38  'classes.' => [
39  'aClass' => 'aConfig',
40  ],
41  'default.' => [
42  'removeComments' => '1',
43  ],
44  'config.' => [
45  'aTable.' => [
46  'aField.' => [
47  'types.' => [
48  'textmedia.' => [
49  'proc.' => [
50  'overruleMode' => 'myTransformation',
51  ],
52  ]
53  ]
54  ]
55  ]
56  ]
57  ];
58  $expected = [
59  'classes.' => [
60  'aClass' => 'aConfig',
61  ],
62  'removeComments' => '1',
63  'proc.' => [
64  'overruleMode' => 'myTransformation',
65  ],
66  'preset' => 'default',
67  'classes' => [
68  'aClass' => 'aConfig',
69  ],
70  'proc' => [
71  'overruleMode' => 'myTransformation',
72  ],
73  ];
74  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
75  // which can't be mocked in a sane way
76  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
77  $subject->expects(self::once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
78  ‪$output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
79  self::assertSame($expected, ‪$output);
80  }
81 
86  {
87  $fieldConfig = [
88  'type' => 'text',
89  'enableRichtext' => true,
90  ];
91  $pageTsConfig = [
92  'classes.' => [
93  'aClass' => 'aConfig',
94  ],
95  'default.' => [
96  'removeComments' => '1',
97  ],
98  'config.' => [
99  'aTable.' => [
100  'aField.' => [
101  'proc.' => [
102  'overruleMode' => 'myTransformation',
103  ],
104  ]
105  ]
106  ]
107  ];
108  $expected = [
109  'classes.' => [
110  'aClass' => 'aConfig',
111  ],
112  'removeComments' => '1',
113  'proc.' => [
114  'overruleMode' => 'myTransformation',
115  ],
116  'preset' => 'default',
117  'classes' => [
118  'aClass' => 'aConfig',
119  ],
120  'proc' => [
121  'overruleMode' => 'myTransformation',
122  ],
123  ];
124  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
125  // which can't be mocked in a sane way
126  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
127  $subject->expects(self::once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
128  ‪$output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
129  self::assertSame($expected, ‪$output);
130  }
131 
136  {
137  $fieldConfig = [
138  'type' => 'text',
139  'enableRichtext' => true,
140  ];
141  $pageTsConfig = [
142  'classes.' => [
143  'aClass' => 'aConfig',
144  ],
145  'default.' => [
146  'removeComments' => '1',
147  ],
148  ];
149  $expected = [
150  'classes.' => [
151  'aClass' => 'aConfig',
152  ],
153  'removeComments' => '1',
154  'preset' => 'default',
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(self::once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
166  ‪$output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
167  self::assertSame($expected, ‪$output);
168  }
169 
174  {
175  $fieldConfig = [
176  'type' => 'text',
177  'enableRichtext' => true,
178  ];
179  $pageTsConfig = [
180  'classes.' => [
181  'aClass' => 'aConfig',
182  ],
183  'default.' => [
184  'classes.' => [
185  'aClass' => 'anotherConfig',
186  ],
187  'editor.' => [
188  'config.' => [
189  'contentsCss' => 'my.css'
190  ]
191  ],
192  ],
193  ];
194  $expected = [
195  'classes.' => [
196  'aClass' => 'anotherConfig',
197  ],
198  'editor.' => [
199  'config.' => [
200  'contentsCss' => 'my.css'
201  ]
202  ],
203  'preset' => 'default',
204  'classes' => [
205  'aClass' => 'anotherConfig',
206  ],
207  'editor' => [
208  'config' => [
209  'contentsCss' => 'my.css'
210  ]
211  ],
212  'proc.' => [
213  'overruleMode' => 'default',
214  ],
215  ];
216  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
217  // which can't be mocked in a sane way
218  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
219  $subject->expects(self::once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
220  ‪$output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
221  self::assertSame($expected, ‪$output);
222  }
223 
228  {
229  $fieldConfig = [
230  'type' => 'text',
231  'enableRichtext' => true,
232  ];
233  $pageTsConfig = [
234  'classes.' => [
235  'aClass' => 'aConfig',
236  ],
237  'default.' => [
238  'classes.' => [
239  'aClass' => 'anotherConfig',
240  ],
241  ],
242  'config.' => [
243  'aTable.' => [
244  'aField.' => [
245  'classes.' => [
246  'aClass' => 'aThirdConfig',
247  ],
248  'editor.' => [
249  'config.' => [
250  'contentsCss' => 'my.css'
251  ]
252  ],
253  ],
254  ],
255  ],
256  ];
257  $expected = [
258  // Config with pagets dots
259  'classes.' => [
260  'aClass' => 'aThirdConfig',
261  ],
262  'editor.' => [
263  'config.' => [
264  'contentsCss' => 'my.css'
265  ]
266  ],
267  'preset' => 'default',
268  // Config without pagets dots
269  'classes' => [
270  'aClass' => 'aThirdConfig',
271  ],
272  'editor' => [
273  'config' => [
274  'contentsCss' => 'my.css'
275  ]
276  ],
277  'proc.' => [
278  'overruleMode' => 'default',
279  ],
280  ];
281  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
282  // which can't be mocked in a sane way
283  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
284  $subject->expects(self::once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
285  ‪$output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
286  self::assertSame($expected, ‪$output);
287  }
288 
293  {
294  $fieldConfig = [
295  'type' => 'text',
296  'enableRichtext' => true,
297  ];
298  $pageTsConfig = [
299  'classes.' => [
300  'aClass' => 'aConfig',
301  ],
302  'default.' => [
303  'classes.' => [
304  'aClass' => 'anotherConfig',
305  ],
306  ],
307  'config.' => [
308  'aTable.' => [
309  'aField.' => [
310  'classes.' => [
311  'aClass' => 'aThirdConfig',
312  ],
313  'editor.' => [
314  'config.' => [
315  'contentsCss' => 'my.css'
316  ]
317  ],
318  'types.' => [
319  'textmedia.' => [
320  'classes.' => [
321  'aClass' => 'aTypeSpecificConfig',
322  ],
323  'editor.' => [
324  'config.' => [
325  'contentsCss' => 'your.css'
326  ]
327  ],
328  ]
329  ]
330  ],
331  ],
332  ],
333  ];
334  $expected = [
335  // Config with pagets dots
336  'classes.' => [
337  'aClass' => 'aTypeSpecificConfig',
338  ],
339  'editor.' => [
340  'config.' => [
341  'contentsCss' => 'your.css'
342  ]
343  ],
344  'preset' => 'default',
345  // Config without pagets dots
346  'classes' => [
347  'aClass' => 'aTypeSpecificConfig',
348  ],
349  'editor' => [
350  'config' => [
351  'contentsCss' => 'your.css'
352  ]
353  ],
354  'proc.' => [
355  'overruleMode' => 'default',
356  ],
357  ];
358  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
359  // which can't be mocked in a sane way
360  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
361  $subject->expects(self::once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
362  ‪$output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
363  self::assertSame($expected, ‪$output);
364  }
365 
370  {
371  $pageId = 42;
372  $presetKey = 'default';
373 
374  $preset = [
375  'editor' => [
376  'config' => [
377  'width' => 100
378  ],
379  ],
380  ];
381 
382  $pageTsConfigArray = [
383  'preset' => $presetKey,
384  'editor.' => [
385  'config.' => [
386  'width' => 200
387  ],
388  ],
389  ];
390 
391  $subject = $this->getAccessibleMock(
392  Richtext::class,
393  ['loadConfigurationFromPreset', 'getRtePageTsConfigOfPid'],
394  [],
395  '',
396  false
397  );
398  $subject->expects(self::once())->method('loadConfigurationFromPreset')->with($presetKey)->willReturn($preset);
399  $subject->expects(self::once())->method('getRtePageTsConfigOfPid')->with($pageId)->willReturn($pageTsConfigArray);
400 
401  ‪$output = $subject->getConfiguration('tt_content', 'bodytext', $pageId, 'textmedia', $pageTsConfigArray);
402 
403  $expected = [
404  'editor' => [
405  'config' => [
406  'width' => 200
407  ],
408  ],
409  'editor.' => [
410  'config.' => [
411  'width' => 200
412  ],
413  ],
414  'preset' => 'default',
415  'proc.' => [
416  'overruleMode' => 'default',
417  ],
418  ];
419 
420  self::assertSame($expected, ‪$output);
421  }
422 
427  {
428  return [
429  [
430  'fieldConfig' => [
431  'type' => 'text',
432  'enableRichtext' => true,
433  'richtextConfiguration' => 'testRteConfigTca'
434  ],
435  'pageTsConfig' => [
436  'classes.' => [
437  'aClass' => 'aConfig',
438  ],
439  'default.' => [
440  'preset' => 'testRteConfigTsconfigDefault',
441  ],
442  'config.' => [
443  'aTable.' => [
444  'aField.' => [
445  'preset' => 'testRteConfigTsconfigAField'
446  ]
447  ]
448  ]
449  ],
450  'expected' => [
451  'classes.' => [
452  'aClass' => 'aConfig',
453  ],
454  'preset' => 'testRteConfigTsconfigAField',
455  'classes' => [
456  'aClass' => 'aConfig',
457  ],
458  'proc.' => [
459  'overruleMode' => 'default',
460  ],
461  ],
462  'message' => 'Preset of testRteConfig* in three place TCA',
463  ],
464  [
465  'fieldConfig' => [
466  'type' => 'text',
467  'enableRichtext' => true,
468  ],
469  'pageTsConfig' => [
470  'classes.' => [
471  'aClass' => 'aConfig',
472  ],
473  'default.' => [
474  'preset' => 'testRteConfigTsconfigDefault',
475  ],
476  'config.' => [
477  'aTable.' => [
478  'aField.' => [
479  'preset' => 'testRteConfigTsconfigAField'
480  ]
481  ]
482  ]
483  ],
484  'expected' => [
485  'classes.' => [
486  'aClass' => 'aConfig',
487  ],
488  'preset' => 'testRteConfigTsconfigAField',
489  'classes' => [
490  'aClass' => 'aConfig',
491  ],
492  'proc.' => [
493  'overruleMode' => 'default',
494  ],
495  ],
496  'message' => 'Preset of testRteConfig* in two place TCA, lowest is pagetsconfig definition for field of table',
497 
498  ],
499  [
500  'fieldConfig' => [
501  'type' => 'text',
502  'enableRichtext' => true,
503  'richtextConfiguration' => 'testRteConfigTca'
504  ],
505  'pageTsConfig' => [
506  'classes.' => [
507  'aClass' => 'aConfig',
508  ],
509  'default.' => [
510  'preset' => 'testRteConfigTsconfigDefault',
511  ],
512  ],
513  'expected' => [
514  'classes.' => [
515  'aClass' => 'aConfig',
516  ],
517  'preset' => 'testRteConfigTca',
518  'classes' => [
519  'aClass' => 'aConfig',
520  ],
521  'proc.' => [
522  'overruleMode' => 'default',
523  ],
524  ],
525  'message' => 'Preset of testRteConfig* in two place TCA, lowest is definition in tca',
526 
527  ],
528  [
529  'fieldConfig' => [
530  'type' => 'text',
531  'enableRichtext' => true,
532  'richtextConfiguration' => 'testRteConfigTca'
533  ],
534  'pageTsConfig' => [
535  'classes.' => [
536  'aClass' => 'aConfig',
537  ],
538  ],
539  'expected' => [
540  'classes.' => [
541  'aClass' => 'aConfig',
542  ],
543  'preset' => 'testRteConfigTca',
544  'classes' => [
545  'aClass' => 'aConfig',
546  ],
547  'proc.' => [
548  'overruleMode' => 'default',
549  ],
550  ],
551  'message' => 'single Preset of testRteConfig* defined in TCA',
552 
553  ],
554  [
555  'fieldConfig' => [
556  'type' => 'text',
557  'enableRichtext' => true,
558  ],
559  'pageTsConfig' => [
560  'classes.' => [
561  'aClass' => 'aConfig',
562  ],
563  'default.' => [
564  'preset' => 'testRteConfigTsconfigDefault',
565  ],
566  ],
567  'expected' => [
568  'classes.' => [
569  'aClass' => 'aConfig',
570  ],
571  'preset' => 'testRteConfigTsconfigDefault',
572  'classes' => [
573  'aClass' => 'aConfig',
574  ],
575  'proc.' => [
576  'overruleMode' => 'default',
577  ],
578  ],
579  'message' => 'single Preset of testRteConfig* defined in PageTSconfig for default of RTE',
580  ],
581  [
582  'fieldConfig' => [
583  'type' => 'text',
584  'enableRichtext' => true,
585  'richtextConfiguration' => 'testRteConfigTca'
586  ],
587  'pageTsConfig' => [
588  'classes.' => [
589  'aClass' => 'aConfig',
590  ],
591  'config.' => [
592  'aTable.' => [
593  'aField.' => [
594  'preset' => 'testRteConfigTsconfigAField'
595  ]
596  ]
597  ]
598  ],
599  'expected' => [
600  'classes.' => [
601  'aClass' => 'aConfig',
602  ],
603  'preset' => 'testRteConfigTsconfigAField',
604  'classes' => [
605  'aClass' => 'aConfig',
606  ],
607  'proc.' => [
608  'overruleMode' => 'default',
609  ],
610  ],
611  'message' => 'single Preset of testRteConfig* defined in PageTSconfig for field of table ',
612  ],
613  [
614  'fieldConfig' => [
615  'type' => 'text',
616  'enableRichtext' => true,
617  'richtextConfiguration' => 'testRteConfigTca'
618  ],
619  'pageTsConfig' => [
620  'classes.' => [
621  'aClass' => 'aConfig',
622  ],
623  'default.' => [
624  'preset' => 'testRteConfigTsconfigDefault',
625  ],
626  'config.' => [
627  'aTable.' => [
628  'aField.' => [
629  'preset' => 'testRteConfigTsconfigAField',
630  'types.' => [
631  'textmedia.' => [
632  'preset' => 'testRteConfigTsconfigATypes',
633  ],
634  ],
635  ]
636  ]
637  ],
638  ],
639  'expected' => [
640  'classes.' => [
641  'aClass' => 'aConfig',
642  ],
643  'preset' => 'testRteConfigTsconfigATypes',
644  'classes' => [
645  'aClass' => 'aConfig',
646  ],
647  'proc.' => [
648  'overruleMode' => 'default',
649  ],
650  ],
651  'message' => 'Preset of testRteConfigTsconfigA* in four place TCA',
652  ],
653  [
654  'fieldConfig' => [
655  'type' => 'text',
656  'enableRichtext' => true,
657  ],
658  'pageTsConfig' => [
659  'classes.' => [
660  'aClass' => 'aConfig',
661  ],
662  'config.' => [
663  'aTable.' => [
664  'aField.' => [
665  'preset' => 'testRteConfigTsconfigAField',
666  'types.' => [
667  'textmedia.' => [
668  'preset' => 'testRteConfigTsconfigATypes',
669  ],
670  ],
671  ]
672  ]
673  ],
674  ],
675  'expected' => [
676  'classes.' => [
677  'aClass' => 'aConfig',
678  ],
679  'preset' => 'testRteConfigTsconfigATypes',
680  'classes' => [
681  'aClass' => 'aConfig',
682  ],
683  'proc.' => [
684  'overruleMode' => 'default',
685  ],
686  ],
687  'message' => 'the preset for CType in pagetsconfig is more reliable than preset for field of tables',
688  ],
689 
690  [
691  'fieldConfig' => [
692  'type' => 'text',
693  'enableRichtext' => true,
694  ],
695  'pageTsConfig' => [
696  'classes.' => [
697  'aClass' => 'aConfig',
698  ],
699  'config.' => [
700  'aTable.' => [
701  'aField.' => [
702  'preset' => 'testRteConfigTsconfigAField',
703  'types.' => [
704  'textmedia.' => [
705  'preset' => 'testRteConfigTsconfigATypes',
706  ],
707  ],
708  ]
709  ],
710  ],
711  ],
712  'expected' => [
713  'classes.' => [
714  'aClass' => 'aConfig',
715  ],
716  'preset' => 'testRteConfigTsconfigATypes',
717  'classes' => [
718  'aClass' => 'aConfig',
719  ],
720  'proc.' => [
721  'overruleMode' => 'default',
722  ],
723  ],
724  'message' => 'the recordtype overrules the definition of an table-field',
725  ],
726 
727  ];
728  }
729 
734  public function ‪getConfigurationFindPresetInPageTsOverridesPreset($fieldConfig, $pageTsConfig, $expected, $message)
735  {
736  // Accessible mock to $subject since getRtePageTsConfigOfPid calls BackendUtility::getPagesTSconfig()
737  // which can't be mocked in a sane way
738  $subject = $this->getAccessibleMock(Richtext::class, ['getRtePageTsConfigOfPid'], [], '', false);
739  $subject->expects(self::once())->method('getRtePageTsConfigOfPid')->with(42)->willReturn($pageTsConfig);
740  ‪$output = $subject->getConfiguration('aTable', 'aField', 42, 'textmedia', $fieldConfig);
741  self::assertSame($expected, ‪$output);
742  }
743 }
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest
Definition: RichtextTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\getConfigurationOverridesByFieldAndTypeSpecificConfig
‪getConfigurationOverridesByFieldAndTypeSpecificConfig()
Definition: RichtextTest.php:292
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\getConfigurationUsesOverruleModeFromConfig
‪getConfigurationUsesOverruleModeFromConfig()
Definition: RichtextTest.php:85
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\getConfigurationOverridesByFieldSpecificConfig
‪getConfigurationOverridesByFieldSpecificConfig()
Definition: RichtextTest.php:227
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\getConfigurationSetsOverruleModeIfMissing
‪getConfigurationSetsOverruleModeIfMissing()
Definition: RichtextTest.php:135
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\dataProviderGetConfigurationFindPresetInPageTsOverridesPreset
‪array dataProviderGetConfigurationFindPresetInPageTsOverridesPreset()
Definition: RichtextTest.php:426
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\getConfigurationPageTsOverridesPreset
‪getConfigurationPageTsOverridesPreset()
Definition: RichtextTest.php:369
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\getConfigurationFindPresetInPageTsOverridesPreset
‪getConfigurationFindPresetInPageTsOverridesPreset($fieldConfig, $pageTsConfig, $expected, $message)
Definition: RichtextTest.php:734
‪TYPO3\CMS\Core\Configuration\Richtext
Definition: Richtext.php:33
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\getConfigurationUsesOverruleModeFromType
‪getConfigurationUsesOverruleModeFromType()
Definition: RichtextTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Configuration\RichtextTest\getConfigurationOverridesByDefault
‪getConfigurationOverridesByDefault()
Definition: RichtextTest.php:173
‪TYPO3\CMS\Core\Tests\Unit\Configuration
Definition: ConfigurationManagerTest.php:18