‪TYPO3CMS  11.5
TcaColumnsOverridesTest.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 ‪TcaColumnsOverridesTest extends UnitTestCase
27 {
29 
30  protected function ‪setUp(): void
31  {
32  parent::setUp();
33  $this->subject = new ‪TcaColumnsOverrides();
34  }
35 
40  {
41  $input = [
42  'command' => 'new',
43  'tableName' => 'aTable',
44  'recordTypeValue' => 'foo',
45  'processedTca' => [
46  'columns' => [],
47  'types' => [
48  'foo' => [
49  'showitem' => [],
50  'columnsOverrides' => [],
51  ],
52  ],
53  ],
54  ];
55 
56  $expected = $input;
57  unset($expected['processedTca']['types']['foo']['columnsOverrides']);
58 
59  self::assertEquals($expected, $this->subject->addData($input));
60  }
61 
66  {
67  $input = [
68  'command' => 'new',
69  'tableName' => 'aTable',
70  'recordTypeValue' => 'foo',
71  'processedTca' => [
72  'columns' => [
73  'aField' => [
74  'aConfig' => 'aValue',
75  'anotherConfig' => 'anotherValue',
76  ],
77  ],
78  'types' => [
79  'foo' => [
80  'showitem' => [],
81  'columnsOverrides' => [
82  'aField' => [
83  'aConfig' => 'aDifferentValue',
84  ],
85  ],
86  ],
87  ],
88  ],
89  ];
90 
91  $expected = $input;
92  $expected['processedTca']['columns']['aField']['aConfig'] = 'aDifferentValue';
93  unset($expected['processedTca']['types']['foo']['columnsOverrides']);
94 
95  self::assertEquals($expected, $this->subject->addData($input));
96  }
97 
102  {
103  $input = [
104  'command' => 'new',
105  'tableName' => 'aTable',
106  'vanillaUid' => 12,
107  'databaseRow' => [
108  'uid' => 42,
109  ],
110  'recordTypeValue' => 'foo',
111  'processedTca' => [
112  'columns' => [
113  'aField' => [
114  'aConfig' => 'aValue',
115  ],
116  ],
117  'types' => [
118  'foo' => [
119  'showitem' => [],
120  'columnsOverrides' => [
121  'aField' => [
122  'config' => [
123  'default' => 'aDefault',
124  ],
125  ],
126  ],
127  ],
128  ],
129  ],
130  ];
131 
132  $expected = $input;
133  $expected['databaseRow']['aField'] = 'aDefault';
134  $expected['processedTca']['columns']['aField']['config']['default'] = 'aDefault';
135  unset($expected['processedTca']['types']['foo']['columnsOverrides']);
136 
137  self::assertEquals($expected, $this->subject->addData($input));
138  }
139 
141  {
142  return [
143  [
144  [
145  'userTsConfig' => [
146  'TCAdefaults.' => [
147  'aTable.' => [
148  'aField' => 'userTsConfigValue',
149  ],
150  ],
151  ],
152  ],
153  ],
154  [
155  [
156  'pageTsConfig' => [
157  'TCAdefaults.' => [
158  'aTable.' => [
159  'aField' => 'pageTsConfigValue',
160  ],
161  ],
162  ],
163  ],
164  ],
165  [
166 
167  [
168  'defaultValues' => [
169  'aTable' => [
170  'aField' => 'defaultValuesValue',
171  ],
172  ],
173  ],
174  ],
175  ];
176  }
177 
182  public function ‪addDataRespectsTSconfigDefaultValuesForNewRecords(array $result): void
183  {
184  $input = array_replace_recursive([
185  'command' => 'new',
186  'tableName' => 'aTable',
187  'vanillaUid' => 12,
188  'databaseRow' => [
189  'uid' => 42,
190  ],
191  'recordTypeValue' => 'foo',
192  'processedTca' => [
193  'columns' => [
194  'aField' => [
195  'aConfig' => 'aValue',
196  ],
197  ],
198  'types' => [
199  'foo' => [
200  'showitem' => [],
201  'columnsOverrides' => [
202  'aField' => [
203  'config' => [
204  'default' => 'aDefault',
205  ],
206  ],
207  ],
208  ],
209  ],
210  ],
211  ], $result);
212 
213  self::assertNotTrue(isset($this->subject->addData($input)['databaseRow']['aField']));
214  }
215 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaColumnsOverridesTest\setUp
‪setUp()
Definition: TcaColumnsOverridesTest.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaColumnsOverridesTest\$subject
‪TcaColumnsOverrides $subject
Definition: TcaColumnsOverridesTest.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaColumnsOverridesTest
Definition: TcaColumnsOverridesTest.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaColumnsOverridesTest\addDataRemovesGivenColumnsOverrides
‪addDataRemovesGivenColumnsOverrides()
Definition: TcaColumnsOverridesTest.php:39
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaColumnsOverridesTest\addDataMergesColumnsOverridesDefaultValueIntoDatabaseRow
‪addDataMergesColumnsOverridesDefaultValueIntoDatabaseRow()
Definition: TcaColumnsOverridesTest.php:101
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaColumnsOverridesTest\addDataRespectsTSconfigDefaultValuesForNewRecords
‪addDataRespectsTSconfigDefaultValuesForNewRecords(array $result)
Definition: TcaColumnsOverridesTest.php:182
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaColumnsOverridesTest\addDataRespectsTSconfigDefaultValuesForNewRecordsDataProvider
‪static addDataRespectsTSconfigDefaultValuesForNewRecordsDataProvider()
Definition: TcaColumnsOverridesTest.php:140
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsOverrides
Definition: TcaColumnsOverrides.php:24
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaColumnsOverridesTest\addDataMergesColumnsOverridesIntoColumns
‪addDataMergesColumnsOverridesIntoColumns()
Definition: TcaColumnsOverridesTest.php:65
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18