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