TYPO3  7.6
DatabaseRowInitializeNewTest.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 TYPO3\CMS\Core\Tests\UnitTestCase;
19 
23 class DatabaseRowInitializeNewTest extends UnitTestCase
24 {
28  protected $subject;
29 
30  protected function setUp()
31  {
32  $this->subject = new DatabaseRowInitializeNew();
33  }
34 
39  {
40  $input = [
41  'command' => 'edit',
42  'tableName' => 'aTable',
43  'vanillaUid' => 23,
44  'databaseRow' => [
45  'uid' => 42,
46  ],
47  'userTsConfig' => [
48  'TCAdefaults.' => [
49  'aTable.' => [
50  'uid' => 23,
51  ],
52  ],
53  ],
54  ];
55  $this->assertSame($input, $this->subject->addData($input));
56  }
57 
62  {
63  $input = [
64  'command' => 'new',
65  'databaseRow' => 'not-an-array',
66  ];
67  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1444431128);
68  $this->subject->addData($input);
69  }
70 
75  {
76  $input = [
77  'command' => 'new',
78  'tableName' => 'aTable',
79  'vanillaUid' => 23,
80  'databaseRow' => [
81  'aField' => 42,
82  ],
83  ];
84  $expected = $input;
85  $expected['databaseRow']['pid'] = 23;
86  $this->assertSame($expected, $this->subject->addData($input));
87  }
88 
93  {
94  $input = [
95  'command' => 'new',
96  'tableName' => 'aTable',
97  'vanillaUid' => 23,
98  'databaseRow' => [],
99  'userTsConfig' => [
100  'TCAdefaults.' => [
101  'aTable.' => [
102  'aField' => 'userTsValue',
103  ],
104  ],
105  ],
106  'processedTca' => [
107  'columns' => [
108  'aField' => [],
109  ],
110  ]
111  ];
112  $expected = [
113  'aField' => 'userTsValue',
114  'pid' => 23,
115  ];
116  $result = $this->subject->addData($input);
117  $this->assertSame($expected, $result['databaseRow']);
118  }
119 
124  {
125  $input = [
126  'command' => 'new',
127  'tableName' => 'aTable',
128  'vanillaUid' => 23,
129  'databaseRow' => [],
130  'userTsConfig' => [
131  'TCAdefaults.' => [
132  'aTable.' => [
133  'aField' => 'userTsValue',
134  ],
135  ],
136  ],
137  'processedTca' => [
138  'columns' => [],
139  ]
140  ];
141  $expected = [
142  'pid' => 23,
143  ];
144  $result = $this->subject->addData($input);
145  $this->assertSame($expected, $result['databaseRow']);
146  }
147 
152  {
153  $input = [
154  'command' => 'new',
155  'tableName' => 'aTable',
156  'vanillaUid' => 23,
157  'databaseRow' => [],
158  'pageTsConfig' => [
159  'TCAdefaults.' => [
160  'aTable.' => [
161  'aField' => 'pageTsValue',
162  ],
163  ],
164  ],
165  'processedTca' => [
166  'columns' => [
167  'aField' => [],
168  ],
169  ]
170  ];
171  $expected = [
172  'aField' => 'pageTsValue',
173  'pid' => 23,
174  ];
175  $result = $this->subject->addData($input);
176  $this->assertSame($expected, $result['databaseRow']);
177  }
178 
183  {
184  $input = [
185  'command' => 'new',
186  'tableName' => 'aTable',
187  'vanillaUid' => 23,
188  'databaseRow' => [],
189  'pageTsConfig' => [
190  'TCAdefaults.' => [
191  'aTable.' => [
192  'aField' => 'pageTsValue',
193  ],
194  ],
195  ],
196  'processedTca' => [
197  'columns' => [],
198  ]
199  ];
200  $expected = [
201  'pid' => 23,
202  ];
203  $result = $this->subject->addData($input);
204  $this->assertSame($expected, $result['databaseRow']);
205  }
206 
211  {
212  $input = [
213  'command' => 'new',
214  'tableName' => 'aTable',
215  'vanillaUid' => 23,
216  'databaseRow' => [],
217  'pageTsConfig' => [
218  'TCAdefaults.' => [
219  'aTable.' => [
220  'aField' => 'pageTsValue',
221  ],
222  ],
223  ],
224  'userTsConfig' => [
225  'TCAdefaults.' => [
226  'aTable.' => [
227  'aField' => 'userTsValue',
228  ],
229  ],
230  ],
231  'processedTca' => [
232  'columns' => [
233  'aField' => [],
234  ],
235  ]
236  ];
237  $expected = [
238  'aField' => 'pageTsValue',
239  'pid' => 23,
240  ];
241  $result = $this->subject->addData($input);
242  $this->assertSame($expected, $result['databaseRow']);
243  }
244 
249  {
250  $input = [
251  'command' => 'new',
252  'tableName' => 'aTable',
253  'vanillaUid' => 23,
254  'databaseRow' => [],
255  'neighborRow' => [
256  'aField' => 'valueFromNeighbor',
257  ],
258  'processedTca' => [
259  'ctrl' => [
260  'useColumnsForDefaultValues' => 'aField',
261  ],
262  'columns' => [
263  'aField' => [],
264  ],
265  ],
266  ];
267  $expected = [
268  'aField' => 'valueFromNeighbor',
269  'pid' => 23,
270  ];
271  $result = $this->subject->addData($input);
272  $this->assertSame($expected, $result['databaseRow']);
273  }
274 
279  {
280  $input = [
281  'command' => 'new',
282  'tableName' => 'aTable',
283  'vanillaUid' => 23,
284  'databaseRow' => [],
285  'neighborRow' => [
286  'aField' => 'valueFromNeighbor',
287  ],
288  'pageTsConfig' => [
289  'TCAdefaults.' => [
290  'aTable.' => [
291  'aField' => 'pageTsValue',
292  ],
293  ],
294  ],
295  'userTsConfig' => [
296  'TCAdefaults.' => [
297  'aTable.' => [
298  'aField' => 'userTsValue',
299  ],
300  ],
301  ],
302  'processedTca' => [
303  'ctrl' => [
304  'useColumnsForDefaultValues' => 'aField',
305  ],
306  'columns' => [
307  'aField' => [],
308  ],
309  ],
310  ];
311  $expected = [
312  'aField' => 'valueFromNeighbor',
313  'pid' => 23,
314  ];
315  $result = $this->subject->addData($input);
316  $this->assertSame($expected, $result['databaseRow']);
317  }
318 
323  {
324  $input = [
325  'command' => 'new',
326  'tableName' => 'aTable',
327  'vanillaUid' => 23,
328  'databaseRow' => [],
329  'processedTca' => [
330  'columns' => [
331  'aField' => [],
332  ],
333  ]
334  ];
335  $GLOBALS['_GET'] = [
336  'defVals' => [
337  'aTable' => [
338  'aField' => 'getValue',
339  ],
340  ],
341  ];
342  $expected = [
343  'aField' => 'getValue',
344  'pid' => 23,
345  ];
346  $result = $this->subject->addData($input);
347  $this->assertSame($expected, $result['databaseRow']);
348  }
349 
354  {
355  $input = [
356  'command' => 'new',
357  'tableName' => 'aTable',
358  'vanillaUid' => 23,
359  'databaseRow' => [],
360  'processedTca' => [
361  'columns' => [
362  'aField' => [],
363  ],
364  ]
365  ];
366  $GLOBALS['_POST'] = [
367  'defVals' => [
368  'aTable' => [
369  'aField' => 'postValue',
370  ],
371  ],
372  ];
373  $expected = [
374  'aField' => 'postValue',
375  'pid' => 23,
376  ];
377  $result = $this->subject->addData($input);
378  $this->assertSame($expected, $result['databaseRow']);
379  }
380 
385  {
386  $input = [
387  'command' => 'new',
388  'tableName' => 'aTable',
389  'vanillaUid' => 23,
390  'databaseRow' => [],
391  'processedTca' => [
392  'columns' => [
393  'aField' => [],
394  ],
395  ]
396  ];
397  $GLOBALS['_GET'] = [
398  'defVals' => [
399  'aTable' => [
400  'aField' => 'getValue',
401  ],
402  ],
403  ];
404  $GLOBALS['_POST'] = [
405  'defVals' => [
406  'aTable' => [
407  'aField' => 'postValue',
408  ],
409  ],
410  ];
411  $expected = [
412  'aField' => 'postValue',
413  'pid' => 23,
414  ];
415  $result = $this->subject->addData($input);
416  $this->assertSame($expected, $result['databaseRow']);
417  }
418 
423  {
424  $input = [
425  'command' => 'new',
426  'tableName' => 'aTable',
427  'vanillaUid' => 23,
428  'databaseRow' => [],
429  'userTsConfig' => [
430  'TCAdefaults.' => [
431  'aTable.' => [
432  'aField' => 'pageTsValue',
433  ],
434  ],
435  ],
436  'processedTca' => [
437  'columns' => [],
438  ]
439  ];
440  $GLOBALS['_GET'] = [
441  'defVals' => [
442  'aTable' => [
443  'aField' => 'getValue',
444  ],
445  ],
446  ];
447  $GLOBALS['_POST'] = [
448  'defVals' => [
449  'aTable' => [
450  'aField' => 'postValue',
451  ],
452  ],
453  ];
454  $expected = [
455  'pid' => 23,
456  ];
457  $result = $this->subject->addData($input);
458  $this->assertSame($expected, $result['databaseRow']);
459  }
460 
465  {
466  $input = [
467  'command' => 'new',
468  'tableName' => 'aTable',
469  'vanillaUid' => 23,
470  'databaseRow' => [],
471  'neighborRow' => [
472  'aField' => 'valueFromNeighbor',
473  ],
474  'pageTsConfig' => [
475  'TCAdefaults.' => [
476  'aTable.' => [
477  'aField' => 'pageTsValue',
478  ],
479  ],
480  ],
481  'userTsConfig' => [
482  'TCAdefaults.' => [
483  'aTable.' => [
484  'aField' => 'userTsValue',
485  ],
486  ],
487  ],
488  'processedTca' => [
489  'ctrl' => [
490  'useColumnsForDefaultValues' => 'aField',
491  ],
492  'columns' => [
493  'aField' => [],
494  ],
495  ],
496  ];
497  $GLOBALS['_POST'] = [
498  'defVals' => [
499  'aTable' => [
500  'aField' => 'postValue',
501  ],
502  ],
503  ];
504  $expected = [
505  'aField' => 'postValue',
506  'pid' => 23,
507  ];
508  $result = $this->subject->addData($input);
509  $this->assertSame($expected, $result['databaseRow']);
510  }
511 
516  {
517  $input = [
518  'command' => 'new',
519  'databaseRow' => [],
520  'inlineChildChildUid' => 42,
521  ];
522  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1444434102);
523  $this->subject->addData($input);
524  }
525 
530  {
531  $input = [
532  'command' => 'new',
533  'databaseRow' => [],
534  'inlineChildChildUid' => '42',
535  ];
536  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1444434103);
537  $this->subject->addData($input);
538  }
539 
544  {
545  $input = [
546  'command' => 'new',
547  'tableName' => 'aTable',
548  'databaseRow' => [],
549  'inlineChildChildUid' => 42,
550  'inlineParentConfig' => [
551  'foreign_selector' => 'theForeignSelectorField',
552  ],
553  'processedTca' => [
554  'columns' => [
555  'theForeignSelectorField' => [
556  'config' => [
557  'type' => 'group',
558  ],
559  ],
560  ],
561  ],
562  ];
563  $expected = $input;
564  $expected['databaseRow']['theForeignSelectorField'] = 42;
565  $expected['databaseRow']['pid'] = null;
566  $this->assertSame($expected, $this->subject->addData($input));
567  }
568 
573  {
574  $input = [
575  'command' => 'new',
576  'tableName' => 'aTable',
577  'databaseRow' => [],
578  'inlineChildChildUid' => 42,
579  'inlineParentConfig' => [
580  'foreign_selector' => 'theForeignSelectorField',
581  ],
582  'processedTca' => [
583  'columns' => [
584  'theForeignSelectorField' => [
585  'config' => [
586  'type' => 'input',
587  ],
588  ],
589  ],
590  ],
591  ];
592  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1444434104);
593  $this->subject->addData($input);
594  }
595 
599  public function addDataSetsPidToVanillaUid()
600  {
601  $input = [
602  'command' => 'new',
603  'tableName' => 'aTable',
604  'vanillaUid' => 23,
605  'databaseRow' => [],
606  ];
607  $expected['pid'] = 23;
608  $result = $this->subject->addData($input);
609  $this->assertSame($expected, $result['databaseRow']);
610  }
611 }