‪TYPO3CMS  ‪main
DatabaseRecordTypeValueTest.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;
21 use PHPUnit\Framework\MockObject\MockObject;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪DatabaseRecordTypeValueTest extends UnitTestCase
26 {
28 
29  protected function ‪setUp(): void
30  {
31  parent::setUp();
32  $this->subject = $this->getMockBuilder(DatabaseRecordTypeValue::class)
33  ->onlyMethods(['getDatabaseRow'])
34  ->getMock();
35  }
36 
37  #[Test]
39  {
40  $input = [
41  'tableName' => 'aTable',
42  'processedTca' => [
43  'types' => [],
44  ],
45  ];
46 
47  $this->expectException(\UnexpectedValueException::class);
48  $this->expectExceptionCode(1438185331);
49 
50  $this->subject->addData($input);
51  }
52 
53  #[Test]
55  {
56  $input = [
57  'recordTypeValue' => 'egon',
58  'processedTca' => [
59  'types' => [
60  '1' => 'foo',
61  ],
62  ],
63  ];
64  $expected = $input;
65  self::assertSame($expected, $this->subject->addData($input));
66  }
67 
68  #[Test]
70  {
71  $input = [
72  'recordTypeValue' => 0,
73  'processedTca' => [
74  'types' => [
75  '1' => 'foo',
76  ],
77  ],
78  ];
79  $expected = $input;
80  self::assertSame($expected, $this->subject->addData($input));
81  }
82 
83  #[Test]
85  {
86  $input = [
87  'recordTypeValue' => '',
88  'processedTca' => [
89  'types' => [
90  '1' => 'foo',
91  ],
92  ],
93  ];
94  $expected = $input;
95  $expected['recordTypeValue'] = '1';
96  self::assertSame($expected, $this->subject->addData($input));
97  }
98 
99  #[Test]
100  public function ‪addDataSetsRecordTypeValueToZero(): void
101  {
102  $input = [
103  'recordTypeValue' => '',
104  'processedTca' => [
105  'types' => [
106  '0' => 'foo',
107  ],
108  ],
109  ];
110 
111  $expected = $input;
112  $expected['recordTypeValue'] = '0';
113 
114  self::assertSame($expected, $this->subject->addData($input));
115  }
116 
117  #[Test]
119  {
120  $input = [
121  'tableName' => 'aTable',
122  'recordTypeValue' => '',
123  'processedTca' => [
124  'ctrl' => [
125  'type' => 'notExists',
126  ],
127  'types' => [
128  '0' => 'foo',
129  ],
130  ],
131  'databaseRow' => [
132  'uid' => 23,
133  ],
134  ];
135 
136  $this->expectException(\UnexpectedValueException::class);
137  $this->expectExceptionCode(1438183881);
138 
139  $this->subject->addData($input);
140  }
141 
142  #[Test]
144  {
145  $input = [
146  'recordTypeValue' => '',
147  'processedTca' => [
148  'ctrl' => [
149  'type' => 'aField',
150  ],
151  'types' => [
152  '3' => 'foo',
153  ],
154  ],
155  'databaseRow' => [
156  'aField' => 3,
157  ],
158  ];
159 
160  $expected = $input;
161  $expected['recordTypeValue'] = '3';
162 
163  self::assertSame($expected, $this->subject->addData($input));
164  }
165 
166  #[Test]
168  {
169  $input = [
170  'recordTypeValue' => '',
171  'processedTca' => [
172  'ctrl' => [
173  'type' => 'aField',
174  ],
175  'types' => [
176  '0' => 'foo',
177  ],
178  ],
179  'databaseRow' => [
180  'aField' => 3,
181  ],
182  ];
183 
184  $expected = $input;
185  $expected['recordTypeValue'] = '0';
186 
187  self::assertSame($expected, $this->subject->addData($input));
188  }
189 
190  #[Test]
192  {
193  $input = [
194  'recordTypeValue' => '',
195  'processedTca' => [
196  'ctrl' => [
197  'type' => 'aField',
198  ],
199  'types' => [
200  '0' => 'foo',
201  ],
202  ],
203  'databaseRow' => [
204  'aField' => '',
205  ],
206  ];
207 
208  $expected = $input;
209  $expected['recordTypeValue'] = '0';
210 
211  self::assertSame($expected, $this->subject->addData($input));
212  }
213 
214  #[Test]
216  {
217  $input = [
218  'tableName' => 'aTable',
219  'recordTypeValue' => '',
220  'processedTca' => [
221  'ctrl' => [
222  'type' => 'aField',
223  ],
224  'types' => [
225  '42' => 'foo',
226  ],
227  ],
228  'databaseRow' => [
229  'aField' => 23,
230  ],
231  ];
232 
233  $this->expectException(\UnexpectedValueException::class);
234  $this->expectExceptionCode(1438185437);
235 
236  $this->subject->addData($input);
237  }
238 
239  #[Test]
241  {
242  $input = [
243  'recordTypeValue' => '',
244  'processedTca' => [
245  'ctrl' => [
246  'type' => 'localField:foreignField',
247  ],
248  'columns' => [
249  'localField' => [
250  'config' => [
251  'type' => 'input',
252  ],
253  ],
254  ],
255  'types' => [
256  '3' => 'foo',
257  ],
258  ],
259  ];
260 
261  $this->expectException(\UnexpectedValueException::class);
262  $this->expectExceptionCode(1325862241);
263 
264  $this->subject->addData($input);
265  }
266 
267  #[Test]
269  {
270  $input = [
271  'tableName' => 'aTable',
272  'recordTypeValue' => '',
273  'processedTca' => [
274  'ctrl' => [
275  'type' => 'localField:foreignField',
276  ],
277  'columns' => [
278  'localField' => [
279  'config' => [
280  'type' => 'select',
281  ],
282  ],
283  ],
284  'types' => [
285  '3' => 'foo',
286  ],
287  ],
288  'databaseRow' => [
289  'localField' => 3,
290  ],
291  ];
292 
293  $this->expectException(\UnexpectedValueException::class);
294  $this->expectExceptionCode(1438253614);
295 
296  $this->subject->addData($input);
297  }
298 
299  #[Test]
301  {
302  $input = [
303  'recordTypeValue' => '',
304  'processedTca' => [
305  'ctrl' => [
306  'type' => 'localField:foreignField',
307  ],
308  'columns' => [
309  'localField' => [
310  'config' => [
311  'type' => 'select',
312  'foreign_table' => 'foreignTable',
313  ],
314  ],
315  ],
316  'types' => [
317  '3' => 'foo',
318  ],
319  ],
320  'databaseRow' => [
321  // Point to record 42 in foreignTable
322  'localField' => 42,
323  ],
324  ];
325 
326  $foreignRecordResult = [
327  'foreignField' => 3,
328  ];
329 
330  $this->subject->expects(self::once())
331  ->method('getDatabaseRow')
332  ->with('foreignTable', 42, 'foreignField')
333  ->willReturn($foreignRecordResult);
334 
335  $expected = $input;
336  $expected['recordTypeValue'] = '3';
337 
338  self::assertSame($expected, $this->subject->addData($input));
339  }
340 
341  #[Test]
343  {
344  $input = [
345  'recordTypeValue' => '',
346  'processedTca' => [
347  'ctrl' => [
348  'type' => 'uid_local:type',
349  ],
350  'columns' => [
351  'uid_local' => [
352  'config' => [
353  'type' => 'group',
354  'size' => 1,
355  'maxitems' => 1,
356  'allowed' => 'sys_file',
357  ],
358  ],
359  ],
360  'types' => [
361  '2' => 'foo',
362  ],
363  ],
364  'databaseRow' => [
365  // Processed group field
366  'uid_local' => [
367  [
368  'uid' => 222,
369  ],
370  ],
371  ],
372  ];
373 
374  $foreignRecordResult = [
375  'type' => 2,
376  ];
377 
378  $this->subject->expects(self::once())
379  ->method('getDatabaseRow')
380  ->with('sys_file', 222, 'type')
381  ->willReturn($foreignRecordResult);
382 
383  $expected = $input;
384  $expected['recordTypeValue'] = '2';
385 
386  self::assertSame($expected, $this->subject->addData($input));
387  }
388 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataThrowsExceptionIfTcaTypesAreEmpty
‪addDataThrowsExceptionIfTcaTypesAreEmpty()
Definition: DatabaseRecordTypeValueTest.php:38
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataKeepsExistingTcaRecordTypeValueWithValueZero
‪addDataKeepsExistingTcaRecordTypeValueWithValueZero()
Definition: DatabaseRecordTypeValueTest.php:69
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataKeepsExistingTcaRecordTypeValue
‪addDataKeepsExistingTcaRecordTypeValue()
Definition: DatabaseRecordTypeValueTest.php:54
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataSetsRecordTypeValueToZeroIfValueOfDatabaseFieldIsNotDefinedInTca
‪addDataSetsRecordTypeValueToZeroIfValueOfDatabaseFieldIsNotDefinedInTca()
Definition: DatabaseRecordTypeValueTest.php:167
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataSetsTypeValueFromForeignTableRecord
‪addDataSetsTypeValueFromForeignTableRecord()
Definition: DatabaseRecordTypeValueTest.php:300
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataSetsRecordTypeValueToHistoricalOneIfTypeZeroIsNotDefined
‪addDataSetsRecordTypeValueToHistoricalOneIfTypeZeroIsNotDefined()
Definition: DatabaseRecordTypeValueTest.php:84
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataThrowsExceptionIfTypePointsToANotExistingField
‪addDataThrowsExceptionIfTypePointsToANotExistingField()
Definition: DatabaseRecordTypeValueTest.php:118
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataSetsRecordTypeValueToZero
‪addDataSetsRecordTypeValueToZero()
Definition: DatabaseRecordTypeValueTest.php:100
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRecordTypeValue
Definition: DatabaseRecordTypeValue.php:26
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataThrowsExceptionForForeignTypeConfigurationNotAsSelectOrGroup
‪addDataThrowsExceptionForForeignTypeConfigurationNotAsSelectOrGroup()
Definition: DatabaseRecordTypeValueTest.php:240
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\$subject
‪DatabaseRecordTypeValue &MockObject $subject
Definition: DatabaseRecordTypeValueTest.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataSetsRecordTypeValueToZeroIfValueOfDatabaseFieldIsEmptyString
‪addDataSetsRecordTypeValueToZeroIfValueOfDatabaseFieldIsEmptyString()
Definition: DatabaseRecordTypeValueTest.php:191
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataSetsTypeValueFromNestedTcaGroupField
‪addDataSetsTypeValueFromNestedTcaGroupField()
Definition: DatabaseRecordTypeValueTest.php:342
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\setUp
‪setUp()
Definition: DatabaseRecordTypeValueTest.php:29
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataThrowsExceptionIfValueTypesNotExistsAndNoFallbackExists
‪addDataThrowsExceptionIfValueTypesNotExistsAndNoFallbackExists()
Definition: DatabaseRecordTypeValueTest.php:215
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest
Definition: DatabaseRecordTypeValueTest.php:26
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataThrowsExceptionForForeignTypeIfPointerConfigurationHasNoTable
‪addDataThrowsExceptionForForeignTypeIfPointerConfigurationHasNoTable()
Definition: DatabaseRecordTypeValueTest.php:268
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataSetsRecordTypeValueToValueOfDatabaseField
‪addDataSetsRecordTypeValueToValueOfDatabaseField()
Definition: DatabaseRecordTypeValueTest.php:143