‪TYPO3CMS  10.4
TcaTextTest.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 
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪TcaTextTest extends UnitTestCase
31 {
36  {
37  $beUserProphecy = $this->prophesize(BackendUserAuthentication::class);
38  $beUserProphecy->isRTE()->willReturn(true);
39  ‪$GLOBALS['BE_USER'] = $beUserProphecy->reveal();
40 
41  $input = [
42  'tableName' => 'aTable',
43  'effectivePid' => 42,
44  'recordTypeValue' => 23,
45  'databaseRow' => [
46  'aField' => 'notProcessedContent',
47  ],
48  'processedTca' => [
49  'columns' => [
50  'aField' => [
51  'config' => [
52  'type' => 'text',
53  'enableRichtext' => true,
54  ],
55  ],
56  ],
57  ],
58  ];
59  $expected = [
60  'tableName' => 'aTable',
61  'effectivePid' => 42,
62  'recordTypeValue' => 23,
63  'databaseRow' => [
64  'aField' => 'processedContent',
65  ],
66  'processedTca' => [
67  'columns' => [
68  'aField' => [
69  'config' => [
70  'type' => 'text',
71  'enableRichtext' => true,
72  'richtextConfigurationName' => '',
73  'richtextConfiguration' => [
74  'aConfig' => 'option',
75  ],
76  ],
77  ],
78  ],
79  ],
80  ];
81 
82  $richtextConfigurationProphecy = $this->prophesize(Richtext::class);
83  GeneralUtility::addInstance(Richtext::class, $richtextConfigurationProphecy->reveal());
84  $rteHtmlParserProphecy = $this->prophesize(RteHtmlParser::class);
85  GeneralUtility::addInstance(RteHtmlParser::class, $rteHtmlParserProphecy->reveal());
86 
87  $richtextConfigurationProphecy
88  ->getConfiguration(
89  'aTable',
90  'aField',
91  42,
92  23,
93  [
94  'type' => 'text',
95  'enableRichtext' => true,
96  ]
97  )
98  ->willReturn([ 'aConfig' => 'option']);
99  $rteHtmlParserProphecy
100  ->transformTextForRichTextEditor(
101  'notProcessedContent',
102  []
103  )
104  ->willReturn('processedContent');
105 
106  self::assertSame($expected, (new ‪TcaText())->addData($input));
107  }
108 
113  {
114  $beUserProphecy = $this->prophesize(BackendUserAuthentication::class);
115  $beUserProphecy->isRTE()->willReturn(true);
116  ‪$GLOBALS['BE_USER'] = $beUserProphecy->reveal();
117 
118  $input = [
119  'tableName' => 'aTable',
120  'effectivePid' => 42,
121  'recordTypeValue' => 23,
122  'databaseRow' => [
123  'aField' => 'notProcessedContent',
124  ],
125  'processedTca' => [
126  'columns' => [
127  'aField' => [
128  'config' => [
129  'type' => 'text',
130  ]
131  ],
132  ],
133  ],
134  ];
135 
136  // No processing should be performed
137  $expected = $input;
138  self::assertSame($expected, (new ‪TcaText())->addData($input));
139  }
140 
145  {
146  $beUserProphecy = $this->prophesize(BackendUserAuthentication::class);
147  $beUserProphecy->isRTE()->willReturn(true);
148  ‪$GLOBALS['BE_USER'] = $beUserProphecy->reveal();
149 
150  $input = [
151  'tableName' => 'aTable',
152  'effectivePid' => 42,
153  'recordTypeValue' => 23,
154  'databaseRow' => [
155  'aField' => 'notProcessedContent',
156  ],
157  'processedTca' => [
158  'columns' => [
159  'aField' => [
160  'config' => [
161  'type' => 'text',
162  'enableRichtext' => true,
163  ],
164  ],
165  ],
166  ],
167  ];
168 
169  $richtextConfigurationProphecy = $this->prophesize(Richtext::class);
170  GeneralUtility::addInstance(Richtext::class, $richtextConfigurationProphecy->reveal());
171 
172  $richtextConfigurationProphecy
173  ->getConfiguration(
174  'aTable',
175  'aField',
176  42,
177  23,
178  [
179  'type' => 'text',
180  'enableRichtext' => true,
181  ]
182  )
183  ->willReturn(['disabled' => '1']);
184 
185  // No processing should be performed
186  $expected = $input;
187  self::assertSame($expected, (new ‪TcaText())->addData($input));
188  }
189 
194  {
195  $beUserProphecy = $this->prophesize(BackendUserAuthentication::class);
196  $beUserProphecy->isRTE()->willReturn(false);
197  ‪$GLOBALS['BE_USER'] = $beUserProphecy->reveal();
198 
199  $input = [
200  'tableName' => 'aTable',
201  'effectivePid' => 42,
202  'recordTypeValue' => 23,
203  'databaseRow' => [
204  'aField' => 'notProcessedContent',
205  ],
206  'processedTca' => [
207  'columns' => [
208  'aField' => [
209  'config' => [
210  'type' => 'text',
211  'enableRichtext' => true,
212  ],
213  ],
214  ],
215  ],
216  ];
217 
218  // No processing should be performed
219  $expected = $input;
220  self::assertSame($expected, (new ‪TcaText())->addData($input));
221  }
222 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaTextTest\addDataDoesNotTransformsContentWhenRichtextIsNotSet
‪addDataDoesNotTransformsContentWhenRichtextIsNotSet()
Definition: TcaTextTest.php:112
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaTextTest\addDataSetsRichtextConfigurationAndTransformsContent
‪addDataSetsRichtextConfigurationAndTransformsContent()
Definition: TcaTextTest.php:35
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaTextTest\addDataDoesNotTransformsContentWhenRichtextIsDisabledInConfiguration
‪addDataDoesNotTransformsContentWhenRichtextIsDisabledInConfiguration()
Definition: TcaTextTest.php:144
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaTextTest\addDataDoesNotTransformsContentWhenRichtextIsDisabledForUser
‪addDataDoesNotTransformsContentWhenRichtextIsDisabledForUser()
Definition: TcaTextTest.php:193
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaTextTest
Definition: TcaTextTest.php:31
‪TYPO3\CMS\Core\Html\RteHtmlParser
Definition: RteHtmlParser.php:38
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaText
Definition: TcaText.php:31
‪TYPO3\CMS\Core\Configuration\Richtext
Definition: Richtext.php:33
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18