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