‪TYPO3CMS  ‪main
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 PHPUnit\Framework\Attributes\Test;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
27 final class ‪TcaTextTest extends UnitTestCase
28 {
29  #[Test]
31  {
32  $input = [
33  'tableName' => 'aTable',
34  'effectivePid' => 42,
35  'recordTypeValue' => 23,
36  'databaseRow' => [
37  'aField' => 'notProcessedContent',
38  ],
39  'processedTca' => [
40  'columns' => [
41  'aField' => [
42  'config' => [
43  'type' => 'text',
44  'enableRichtext' => true,
45  ],
46  ],
47  ],
48  ],
49  ];
50  $expected = [
51  'tableName' => 'aTable',
52  'effectivePid' => 42,
53  'recordTypeValue' => 23,
54  'databaseRow' => [
55  'aField' => 'processedContent',
56  ],
57  'processedTca' => [
58  'columns' => [
59  'aField' => [
60  'config' => [
61  'type' => 'text',
62  'enableRichtext' => true,
63  'richtextConfigurationName' => '',
64  'richtextConfiguration' => [
65  'aConfig' => 'option',
66  ],
67  ],
68  ],
69  ],
70  ],
71  ];
72 
73  $richtextConfigurationMock = $this->createMock(Richtext::class);
74  GeneralUtility::addInstance(Richtext::class, $richtextConfigurationMock);
75  $rteHtmlParserMock = $this->createMock(RteHtmlParser::class);
76  GeneralUtility::addInstance(RteHtmlParser::class, $rteHtmlParserMock);
77 
78  $richtextConfigurationMock
79  ->method('getConfiguration')
80  ->with(
81  'aTable',
82  'aField',
83  42,
84  23,
85  [
86  'type' => 'text',
87  'enableRichtext' => true,
88  ]
89  )
90  ->willReturn([ 'aConfig' => 'option']);
91  $rteHtmlParserMock
92  ->method('transformTextForRichTextEditor')
93  ->with(
94  'notProcessedContent',
95  []
96  )
97  ->willReturn('processedContent');
98 
99  self::assertSame($expected, (new ‪TcaText())->addData($input));
100  }
101 
102  #[Test]
104  {
105  $input = [
106  'tableName' => 'aTable',
107  'effectivePid' => 42,
108  'recordTypeValue' => 23,
109  'databaseRow' => [
110  'aField' => 'notProcessedContent',
111  ],
112  'processedTca' => [
113  'columns' => [
114  'aField' => [
115  'config' => [
116  'type' => 'text',
117  ],
118  ],
119  ],
120  ],
121  ];
122 
123  // No processing should be performed
124  $expected = $input;
125  self::assertSame($expected, (new ‪TcaText())->addData($input));
126  }
127 
128  #[Test]
130  {
131  $input = [
132  'tableName' => 'aTable',
133  'effectivePid' => 42,
134  'recordTypeValue' => 23,
135  'databaseRow' => [
136  'aField' => 'notProcessedContent',
137  ],
138  'processedTca' => [
139  'columns' => [
140  'aField' => [
141  'config' => [
142  'type' => 'text',
143  'enableRichtext' => true,
144  ],
145  ],
146  ],
147  ],
148  ];
149 
150  $richtextConfigurationMock = $this->createMock(Richtext::class);
151  GeneralUtility::addInstance(Richtext::class, $richtextConfigurationMock);
152 
153  $richtextConfigurationMock
154  ->method('getConfiguration')
155  ->with(
156  'aTable',
157  'aField',
158  42,
159  23,
160  [
161  'type' => 'text',
162  'enableRichtext' => true,
163  ]
164  )
165  ->willReturn(['disabled' => '1']);
166 
167  // No processing should be performed
168  $expected = $input;
169  self::assertSame($expected, (new ‪TcaText())->addData($input));
170  }
171 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaTextTest\addDataDoesNotTransformsContentWhenRichtextIsNotSet
‪addDataDoesNotTransformsContentWhenRichtextIsNotSet()
Definition: TcaTextTest.php:103
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaTextTest\addDataSetsRichtextConfigurationAndTransformsContent
‪addDataSetsRichtextConfigurationAndTransformsContent()
Definition: TcaTextTest.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaTextTest\addDataDoesNotTransformsContentWhenRichtextIsDisabledInConfiguration
‪addDataDoesNotTransformsContentWhenRichtextIsDisabledInConfiguration()
Definition: TcaTextTest.php:129
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaTextTest
Definition: TcaTextTest.php:28
‪TYPO3\CMS\Core\Html\RteHtmlParser
Definition: RteHtmlParser.php:40
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaText
Definition: TcaText.php:30
‪TYPO3\CMS\Core\Configuration\Richtext
Definition: Richtext.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18