TYPO3 CMS  TYPO3_8-7
DatabaseRowInitializeNewTest.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 
22 class DatabaseRowInitializeNewTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
23 {
27  protected $subject;
28 
29  protected function setUp()
30  {
31  $this->subject = new DatabaseRowInitializeNew();
32  }
33 
38  {
39  $input = [
40  'command' => 'edit',
41  'tableName' => 'aTable',
42  'vanillaUid' => 23,
43  'databaseRow' => [
44  'uid' => 42,
45  ],
46  'userTsConfig' => [
47  'TCAdefaults.' => [
48  'aTable.' => [
49  'uid' => 23,
50  ],
51  ],
52  ],
53  ];
54  $this->assertSame($input, $this->subject->addData($input));
55  }
56 
61  {
62  $input = [
63  'command' => 'new',
64  'databaseRow' => 'not-an-array',
65  ];
66  $this->expectException(\UnexpectedValueException::class);
67  $this->expectExceptionCode(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->expectException(\UnexpectedValueException::class);
523  $this->expectExceptionCode(1444434102);
524  $this->subject->addData($input);
525  }
526 
531  {
532  $input = [
533  'command' => 'new',
534  'databaseRow' => [],
535  'inlineChildChildUid' => '42',
536  ];
537  $this->expectException(\UnexpectedValueException::class);
538  $this->expectExceptionCode(1444434103);
539  $this->subject->addData($input);
540  }
541 
546  {
547  $input = [
548  'command' => 'new',
549  'tableName' => 'aTable',
550  'databaseRow' => [],
551  'inlineChildChildUid' => 42,
552  'inlineParentConfig' => [
553  'foreign_selector' => 'theForeignSelectorField',
554  ],
555  'processedTca' => [
556  'columns' => [
557  'theForeignSelectorField' => [
558  'config' => [
559  'type' => 'group',
560  ],
561  ],
562  ],
563  ],
564  ];
565  $expected = $input;
566  $expected['databaseRow']['theForeignSelectorField'] = 42;
567  $expected['databaseRow']['pid'] = null;
568  $this->assertSame($expected, $this->subject->addData($input));
569  }
570 
575  {
576  $input = [
577  'command' => 'new',
578  'tableName' => 'aTable',
579  'databaseRow' => [],
580  'inlineChildChildUid' => 42,
581  'inlineParentConfig' => [
582  'foreign_selector' => 'theForeignSelectorField',
583  ],
584  'processedTca' => [
585  'columns' => [
586  'theForeignSelectorField' => [
587  'config' => [
588  'type' => 'input',
589  ],
590  ],
591  ],
592  ],
593  ];
594  $this->expectException(\UnexpectedValueException::class);
595  $this->expectExceptionCode(1444434104);
596  $this->subject->addData($input);
597  }
598 
603  {
604  $input = [
605  'command' => 'new',
606  'tableName' => 'aTable',
607  'databaseRow' => [],
608  'inlineParentConfig' => [
609  'inline' => [
610  'parentSysLanguageUid' => 'not-an-integer',
611  ],
612  ],
613  'processedTca' => [
614  'ctrl' => [
615  'languageField' => 'sys_language_uid',
616  'transOrigPointerField' => 'l10n_parent',
617  ],
618  'columns' => [],
619  ],
620  ];
621  $this->expectException(\UnexpectedValueException::class);
622  $this->expectExceptionCode(1490360772);
623  $this->subject->addData($input);
624  }
625 
630  {
631  $input = [
632  'command' => 'new',
633  'tableName' => 'aTable',
634  'vanillaUid' => 1,
635  'databaseRow' => [],
636  'inlineParentConfig' => [
637  'inline' => [
638  'parentSysLanguageUid' => '42',
639  ],
640  ],
641  'processedTca' => [
642  'ctrl' => [
643  'languageField' => 'sys_language_uid',
644  'transOrigPointerField' => 'l10n_parent',
645  ],
646  'columns' => [],
647  ],
648  ];
649  $expected = $input;
650  $expected['databaseRow'] = [
651  'sys_language_uid' => 42,
652  'pid' => 1,
653  ];
654  $result = $this->subject->addData($input);
655  $this->assertSame($expected, $result);
656  }
657 
661  public function addDataSetsPidToVanillaUid()
662  {
663  $input = [
664  'command' => 'new',
665  'tableName' => 'aTable',
666  'vanillaUid' => 23,
667  'databaseRow' => [],
668  ];
669  $expected['pid'] = 23;
670  $result = $this->subject->addData($input);
671  $this->assertSame($expected, $result['databaseRow']);
672  }
673 
678  {
679  $input = [
680  'command' => 'new',
681  'tableName' => 'aTable',
682  'vanillaUid' => 23,
683  'databaseRow' => [],
684  'pageTsConfig' => [
685  'TCAdefaults.' => [
686  'aTable.' => [
687  'pid' => '42',
688  ],
689  ],
690  ],
691  'isInlineChild' => false,
692  ];
693  $expected = $input;
694  $expected['databaseRow']['pid'] = 23;
695  $this->assertSame($expected, $this->subject->addData($input));
696  }
697 
702  {
703  $input = [
704  'command' => 'new',
705  'tableName' => 'aTable',
706  'vanillaUid' => 23,
707  'databaseRow' => [],
708  'pageTsConfig' => [
709  'TCAdefaults.' => [
710  'aTable.' => [
711  'pid' => 'notAnInteger',
712  ],
713  ],
714  ],
715  'isInlineChild' => true,
716  ];
717  $this->expectException(\UnexpectedValueException::class);
718  $this->expectExceptionCode(1461598332);
719  $this->subject->addData($input);
720  }
721 
726  {
727  $input = [
728  'command' => 'new',
729  'tableName' => 'aTable',
730  'vanillaUid' => 23,
731  'databaseRow' => [],
732  'pageTsConfig' => [
733  'TCAdefaults.' => [
734  'aTable.' => [
735  'pid' => '42',
736  ],
737  ],
738  ],
739  'isInlineChild' => true,
740  ];
741  $expected = $input;
742  $expected['databaseRow']['pid'] = 42;
743  $this->assertSame($expected, $this->subject->addData($input));
744  }
745 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']