TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
DatabaseRecordTypeValueTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
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 
17 use Prophecy\Prophecy\ObjectProphecy;
21 
26 {
30  protected $subject;
31 
35  protected $dbProphecy;
36 
37  protected function setUp()
38  {
39  $this->subject = $this->getMockBuilder(DatabaseRecordTypeValue::class)
40  ->setMethods(['getDatabaseRow'])
41  ->getMock();
42  }
43 
48  {
49  $input = [
50  'processedTca' => [
51  'types' => [],
52  ],
53  ];
54 
55  $this->expectException(\UnexpectedValueException::class);
56  $this->expectExceptionCode(1438185331);
57 
58  $this->subject->addData($input);
59  }
60 
65  {
66  $input = [
67  'recordTypeValue' => 'egon',
68  'processedTca' => [
69  'types' => [
70  '1' => 'foo',
71  ],
72  ],
73  ];
74  $expected = $input;
75  $this->assertSame($expected, $this->subject->addData($input));
76  }
77 
82  {
83  $input = [
84  'recordTypeValue' => 0,
85  'processedTca' => [
86  'types' => [
87  '1' => 'foo',
88  ],
89  ],
90  ];
91  $expected = $input;
92  $this->assertSame($expected, $this->subject->addData($input));
93  }
94 
99  {
100  $input = [
101  'recordTypeValue' => '',
102  'processedTca' => [
103  'types' => [
104  '1' => 'foo',
105  ],
106  ],
107  ];
108  $expected = $input;
109  $expected['recordTypeValue'] = '1';
110  $this->assertSame($expected, $this->subject->addData($input));
111  }
112 
117  {
118  $input = [
119  'recordTypeValue' => '',
120  'processedTca' => [
121  'types' => [
122  '0' => 'foo',
123  ],
124  ],
125  ];
126 
127  $expected = $input;
128  $expected['recordTypeValue'] = '0';
129 
130  $this->assertSame($expected, $this->subject->addData($input));
131  }
132 
137  {
138  $input = [
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  $this->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  $this->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  $this->assertSame($expected, $this->subject->addData($input));
235  }
236 
241  {
242  $input = [
243  'recordTypeValue' => '',
244  'processedTca' => [
245  'ctrl' => [
246  'type' => 'aField',
247  ],
248  'types' => [
249  '42' => 'foo',
250  ],
251  ],
252  'databaseRow' => [
253  'aField' => 23,
254  ],
255  ];
256 
257  $this->expectException(\UnexpectedValueException::class);
258  $this->expectExceptionCode(1438185437);
259 
260  $this->subject->addData($input);
261  }
262 
267  {
268  $input = [
269  'recordTypeValue' => '',
270  'processedTca' => [
271  'ctrl' => [
272  'languageField' => 'sys_language_uid',
273  'type' => 'aField',
274  ],
275  'columns' => [
276  'aField' => [
277  'l10n_mode' => 'exclude',
278  ],
279  ],
280  'types' => [
281  '3' => 'foo',
282  ],
283  ],
284  'databaseRow' => [
285  'sys_language_uid' => 2,
286  'aField' => 4,
287  ],
288  'defaultLanguageRow' => [
289  'aField' => 3,
290  ],
291  ];
292 
293  $expected = $input;
294  $expected['recordTypeValue'] = '3';
295 
296  $this->assertSame($expected, $this->subject->addData($input));
297  }
298 
303  {
304  $input = [
305  'recordTypeValue' => '',
306  'processedTca' => [
307  'ctrl' => [
308  'languageField' => 'sys_language_uid',
309  'type' => 'aField',
310  ],
311  'columns' => [
312  'aField' => [
313  'l10n_mode' => 'mergeIfNotBlank',
314  ],
315  ],
316  'types' => [
317  '3' => 'foo',
318  ],
319  ],
320  'databaseRow' => [
321  'sys_language_uid' => 2,
322  'aField' => '',
323  ],
324  'defaultLanguageRow' => [
325  'aField' => 3,
326  ],
327  ];
328 
329  $expected = $input;
330  $expected['recordTypeValue'] = '3';
331 
332  $this->assertSame($expected, $this->subject->addData($input));
333  }
334 
339  {
340  $input = [
341  'recordTypeValue' => '',
342  'processedTca' => [
343  'ctrl' => [
344  'languageField' => 'sys_language_uid',
345  'type' => 'aField',
346  ],
347  'columns' => [
348  'aField' => [
349  'l10n_mode' => 'mergeIfNotBlank',
350  ],
351  ],
352  'types' => [
353  '3' => 'foo',
354  ],
355  ],
356  'databaseRow' => [
357  'sys_language_uid' => 2,
358  'aField' => 3,
359  ],
360  'defaultLanguageRow' => [
361  'aField' => 4,
362  ],
363  ];
364 
365  $expected = $input;
366  $expected['recordTypeValue'] = '3';
367 
368  $this->assertSame($expected, $this->subject->addData($input));
369  }
370 
375  {
376  $input = [
377  'recordTypeValue' => '',
378  'processedTca' => [
379  'ctrl' => [
380  'type' => 'localField:foreignField',
381  ],
382  'columns' => [
383  'localField' => [
384  'config' => [
385  'type' => 'input',
386  ],
387  ],
388  ],
389  'types' => [
390  '3' => 'foo',
391  ],
392  ],
393  ];
394 
395  $this->expectException(\UnexpectedValueException::class);
396  $this->expectExceptionCode(1325862241);
397 
398  $this->subject->addData($input);
399  }
400 
405  {
406  $input = [
407  'recordTypeValue' => '',
408  'processedTca' => [
409  'ctrl' => [
410  'type' => 'localField:foreignField',
411  ],
412  'columns' => [
413  'localField' => [
414  'config' => [
415  'type' => 'select',
416  ],
417  ],
418  ],
419  'types' => [
420  '3' => 'foo',
421  ],
422  ],
423  'databaseRow' => [
424  'localField' => 3,
425  ],
426  ];
427 
428  $this->expectException(\UnexpectedValueException::class);
429  $this->expectExceptionCode(1438253614);
430 
431  $this->subject->addData($input);
432  }
433 
438  {
439  $input = [
440  'recordTypeValue' => '',
441  'processedTca' => [
442  'ctrl' => [
443  'type' => 'localField:foreignField',
444  ],
445  'columns' => [
446  'localField' => [
447  'config' => [
448  'type' => 'select',
449  'foreign_table' => 'foreignTable',
450  ],
451  ],
452  ],
453  'types' => [
454  '3' => 'foo',
455  ],
456  ],
457  'databaseRow' => [
458  // Point to record 42 in foreignTable
459  'localField' => 42,
460  ],
461  ];
462 
463  $foreignRecordResult = [
464  'foreignField' => 3,
465  ];
466 
467  $this->subject->expects($this->once())
468  ->method('getDatabaseRow')
469  ->with('foreignTable', 42, 'foreignField')
470  ->willReturn($foreignRecordResult);
471 
472  $expected = $input;
473  $expected['recordTypeValue'] = '3';
474 
475  $this->assertSame($expected, $this->subject->addData($input));
476  }
477 
482  {
483  $input = [
484  'recordTypeValue' => '',
485  'processedTca' => [
486  'ctrl' => [
487  'type' => 'uid_local:type',
488  ],
489  'columns' => [
490  'uid_local' => [
491  'config' => [
492  'type' => 'group',
493  'internal_type' => 'db',
494  'size' => 1,
495  'maxitems' => 1,
496  'minitems' => 0,
497  'allowed' => 'sys_file'
498  ],
499  ],
500  ],
501  'types' => [
502  '2' => 'foo',
503  ],
504  ],
505  'databaseRow' => [
506  // Processed group field
507  'uid_local' => 'sys_file_222|my_test.jpg',
508  ],
509  ];
510 
511  $foreignRecordResult = [
512  'type' => 2,
513  ];
514 
515  $this->subject->expects($this->once())
516  ->method('getDatabaseRow')
517  ->with('sys_file', 222, 'type')
518  ->willReturn($foreignRecordResult);
519 
520  $expected = $input;
521  $expected['recordTypeValue'] = '2';
522 
523  $this->assertSame($expected, $this->subject->addData($input));
524  }
525 }