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