‪TYPO3CMS  9.5
DatabaseRecordTypeValueTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
19 
23 class ‪DatabaseRecordTypeValueTest extends UnitTestCase
24 {
28  protected ‪$subject;
29 
30  protected function ‪setUp()
31  {
32  $this->subject = $this->getMockBuilder(DatabaseRecordTypeValue::class)
33  ->setMethods(['getDatabaseRow'])
34  ->getMock();
35  }
36 
41  {
42  $input = [
43  'tableName' => 'aTable',
44  'processedTca' => [
45  'types' => [],
46  ],
47  ];
48 
49  $this->expectException(\UnexpectedValueException::class);
50  $this->expectExceptionCode(1438185331);
51 
52  $this->subject->addData($input);
53  }
54 
59  {
60  $input = [
61  'recordTypeValue' => 'egon',
62  'processedTca' => [
63  'types' => [
64  '1' => 'foo',
65  ],
66  ],
67  ];
68  $expected = $input;
69  $this->assertSame($expected, $this->subject->addData($input));
70  }
71 
76  {
77  $input = [
78  'recordTypeValue' => 0,
79  'processedTca' => [
80  'types' => [
81  '1' => 'foo',
82  ],
83  ],
84  ];
85  $expected = $input;
86  $this->assertSame($expected, $this->subject->addData($input));
87  }
88 
93  {
94  $input = [
95  'recordTypeValue' => '',
96  'processedTca' => [
97  'types' => [
98  '1' => 'foo',
99  ],
100  ],
101  ];
102  $expected = $input;
103  $expected['recordTypeValue'] = '1';
104  $this->assertSame($expected, $this->subject->addData($input));
105  }
106 
110  public function ‪addDataSetsRecordTypeValueToZero()
111  {
112  $input = [
113  'recordTypeValue' => '',
114  'processedTca' => [
115  'types' => [
116  '0' => 'foo',
117  ],
118  ],
119  ];
120 
121  $expected = $input;
122  $expected['recordTypeValue'] = '0';
123 
124  $this->assertSame($expected, $this->subject->addData($input));
125  }
126 
131  {
132  $input = [
133  'tableName' => 'aTable',
134  'recordTypeValue' => '',
135  'processedTca' => [
136  'ctrl' => [
137  'type' => 'notExists',
138  ],
139  'types' => [
140  '0' => 'foo',
141  ],
142  ],
143  'databaseRow' => [
144  'uid' => 23,
145  ],
146  ];
147 
148  $this->expectException(\UnexpectedValueException::class);
149  $this->expectExceptionCode(1438183881);
150 
151  $this->subject->addData($input);
152  }
153 
158  {
159  $input = [
160  'recordTypeValue' => '',
161  'processedTca' => [
162  'ctrl' => [
163  'type' => 'aField',
164  ],
165  'types' => [
166  '3' => 'foo',
167  ],
168  ],
169  'databaseRow' => [
170  'aField' => 3,
171  ],
172  ];
173 
174  $expected = $input;
175  $expected['recordTypeValue'] = '3';
176 
177  $this->assertSame($expected, $this->subject->addData($input));
178  }
179 
184  {
185  $input = [
186  'recordTypeValue' => '',
187  'processedTca' => [
188  'ctrl' => [
189  'type' => 'aField',
190  ],
191  'types' => [
192  '0' => 'foo',
193  ],
194  ],
195  'databaseRow' => [
196  'aField' => 3,
197  ],
198  ];
199 
200  $expected = $input;
201  $expected['recordTypeValue'] = '0';
202 
203  $this->assertSame($expected, $this->subject->addData($input));
204  }
205 
210  {
211  $input = [
212  'recordTypeValue' => '',
213  'processedTca' => [
214  'ctrl' => [
215  'type' => 'aField',
216  ],
217  'types' => [
218  '0' => 'foo',
219  ],
220  ],
221  'databaseRow' => [
222  'aField' => '',
223  ],
224  ];
225 
226  $expected = $input;
227  $expected['recordTypeValue'] = '0';
228 
229  $this->assertSame($expected, $this->subject->addData($input));
230  }
231 
236  {
237  $input = [
238  'tableName' => 'aTable',
239  'recordTypeValue' => '',
240  'processedTca' => [
241  'ctrl' => [
242  'type' => 'aField',
243  ],
244  'types' => [
245  '42' => 'foo',
246  ],
247  ],
248  'databaseRow' => [
249  'aField' => 23,
250  ],
251  ];
252 
253  $this->expectException(\UnexpectedValueException::class);
254  $this->expectExceptionCode(1438185437);
255 
256  $this->subject->addData($input);
257  }
258 
263  {
264  $input = [
265  'recordTypeValue' => '',
266  'processedTca' => [
267  'ctrl' => [
268  'type' => 'localField:foreignField',
269  ],
270  'columns' => [
271  'localField' => [
272  'config' => [
273  'type' => 'input',
274  ],
275  ],
276  ],
277  'types' => [
278  '3' => 'foo',
279  ],
280  ],
281  ];
282 
283  $this->expectException(\UnexpectedValueException::class);
284  $this->expectExceptionCode(1325862241);
285 
286  $this->subject->addData($input);
287  }
288 
293  {
294  $input = [
295  'tableName' => 'aTable',
296  'recordTypeValue' => '',
297  'processedTca' => [
298  'ctrl' => [
299  'type' => 'localField:foreignField',
300  ],
301  'columns' => [
302  'localField' => [
303  'config' => [
304  'type' => 'select',
305  ],
306  ],
307  ],
308  'types' => [
309  '3' => 'foo',
310  ],
311  ],
312  'databaseRow' => [
313  'localField' => 3,
314  ],
315  ];
316 
317  $this->expectException(\UnexpectedValueException::class);
318  $this->expectExceptionCode(1438253614);
319 
320  $this->subject->addData($input);
321  }
322 
327  {
328  $input = [
329  'recordTypeValue' => '',
330  'processedTca' => [
331  'ctrl' => [
332  'type' => 'localField:foreignField',
333  ],
334  'columns' => [
335  'localField' => [
336  'config' => [
337  'type' => 'select',
338  'foreign_table' => 'foreignTable',
339  ],
340  ],
341  ],
342  'types' => [
343  '3' => 'foo',
344  ],
345  ],
346  'databaseRow' => [
347  // Point to record 42 in foreignTable
348  'localField' => 42,
349  ],
350  ];
351 
352  $foreignRecordResult = [
353  'foreignField' => 3,
354  ];
355 
356  $this->subject->expects($this->once())
357  ->method('getDatabaseRow')
358  ->with('foreignTable', 42, 'foreignField')
359  ->willReturn($foreignRecordResult);
360 
361  $expected = $input;
362  $expected['recordTypeValue'] = '3';
363 
364  $this->assertSame($expected, $this->subject->addData($input));
365  }
366 
371  {
372  $input = [
373  'recordTypeValue' => '',
374  'processedTca' => [
375  'ctrl' => [
376  'type' => 'uid_local:type',
377  ],
378  'columns' => [
379  'uid_local' => [
380  'config' => [
381  'type' => 'group',
382  'internal_type' => 'db',
383  'size' => 1,
384  'maxitems' => 1,
385  'minitems' => 0,
386  'allowed' => 'sys_file'
387  ],
388  ],
389  ],
390  'types' => [
391  '2' => 'foo',
392  ],
393  ],
394  'databaseRow' => [
395  // Processed group field
396  'uid_local' => [
397  [
398  'uid' => 222,
399  ],
400  ],
401  ],
402  ];
403 
404  $foreignRecordResult = [
405  'type' => 2,
406  ];
407 
408  $this->subject->expects($this->once())
409  ->method('getDatabaseRow')
410  ->with('sys_file', 222, 'type')
411  ->willReturn($foreignRecordResult);
412 
413  $expected = $input;
414  $expected['recordTypeValue'] = '2';
415 
416  $this->assertSame($expected, $this->subject->addData($input));
417  }
418 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataThrowsExceptionIfTcaTypesAreEmpty
‪addDataThrowsExceptionIfTcaTypesAreEmpty()
Definition: DatabaseRecordTypeValueTest.php:39
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataKeepsExistingTcaRecordTypeValueWithValueZero
‪addDataKeepsExistingTcaRecordTypeValueWithValueZero()
Definition: DatabaseRecordTypeValueTest.php:74
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataKeepsExistingTcaRecordTypeValue
‪addDataKeepsExistingTcaRecordTypeValue()
Definition: DatabaseRecordTypeValueTest.php:57
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataSetsRecordTypeValueToZeroIfValueOfDatabaseFieldIsNotDefinedInTca
‪addDataSetsRecordTypeValueToZeroIfValueOfDatabaseFieldIsNotDefinedInTca()
Definition: DatabaseRecordTypeValueTest.php:182
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\$subject
‪DatabaseRecordTypeValue PHPUnit_Framework_MockObject_MockObject $subject
Definition: DatabaseRecordTypeValueTest.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataSetsTypeValueFromForeignTableRecord
‪addDataSetsTypeValueFromForeignTableRecord()
Definition: DatabaseRecordTypeValueTest.php:325
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataSetsRecordTypeValueToHistoricalOneIfTypeZeroIsNotDefined
‪addDataSetsRecordTypeValueToHistoricalOneIfTypeZeroIsNotDefined()
Definition: DatabaseRecordTypeValueTest.php:91
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataThrowsExceptionIfTypePointsToANotExistingField
‪addDataThrowsExceptionIfTypePointsToANotExistingField()
Definition: DatabaseRecordTypeValueTest.php:129
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataSetsRecordTypeValueToZero
‪addDataSetsRecordTypeValueToZero()
Definition: DatabaseRecordTypeValueTest.php:109
‪TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRecordTypeValue
Definition: DatabaseRecordTypeValue.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataThrowsExceptionForForeignTypeConfigurationNotAsSelectOrGroup
‪addDataThrowsExceptionForForeignTypeConfigurationNotAsSelectOrGroup()
Definition: DatabaseRecordTypeValueTest.php:261
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataSetsRecordTypeValueToZeroIfValueOfDatabaseFieldIsEmptyString
‪addDataSetsRecordTypeValueToZeroIfValueOfDatabaseFieldIsEmptyString()
Definition: DatabaseRecordTypeValueTest.php:208
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataSetsTypeValueFromNestedTcaGroupField
‪addDataSetsTypeValueFromNestedTcaGroupField()
Definition: DatabaseRecordTypeValueTest.php:369
‪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:234
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest
Definition: DatabaseRecordTypeValueTest.php:24
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataThrowsExceptionForForeignTypeIfPointerConfigurationHasNoTable
‪addDataThrowsExceptionForForeignTypeIfPointerConfigurationHasNoTable()
Definition: DatabaseRecordTypeValueTest.php:291
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:3
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\DatabaseRecordTypeValueTest\addDataSetsRecordTypeValueToValueOfDatabaseField
‪addDataSetsRecordTypeValueToValueOfDatabaseField()
Definition: DatabaseRecordTypeValueTest.php:156