TYPO3 CMS  TYPO3_8-7
TcaRecordTitleTest.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 
21 
25 class TcaRecordTitleTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
26 {
30  protected $subject;
31 
35  protected $timeZone;
36 
37  public function setUp()
38  {
39  $this->subject = new TcaRecordTitle();
40  $this->timeZone = date_default_timezone_get();
41  date_default_timezone_set('UTC');
42  }
43 
44  protected function tearDown()
45  {
46  date_default_timezone_set($this->timeZone);
47  parent::tearDown();
48  }
49 
54  {
55  $input = [
56  'tableName' => 'aTable',
57  'databaseRew' => [],
58  'processedTca' => [
59  'ctrl' => [],
60  ],
61  ];
62  $this->expectException(\UnexpectedValueException::class);
63  $this->expectExceptionCode(1443706103);
64  $this->subject->addData($input);
65  }
66 
71  {
72  $input = [
73  'tableName' => 'aTable',
74  'databaseRow' => [],
75  'processedTca' => [
76  'ctrl' => [
77  'label' => 'uid',
78  'label_userFunc' => function (&$parameters) {
79  $parameters['title'] = 'Test';
80  }
81  ],
82  'columns' => [],
83  ],
84  ];
85 
86  $expected = $input;
87  $expected['recordTitle'] = 'Test';
88 
89  $this->assertSame($expected, $this->subject->addData($input));
90  }
91 
96  {
97  $input = [
98  'tableName' => 'aTable',
99  'databaseRow' => [],
100  'isInlineChild' => true,
101  'processedTca' => [
102  'ctrl' => [
103  'label' => 'uid',
104  'formattedLabel_userFunc' => function (&$parameters) {
105  $parameters['title'] = 'Test';
106  }
107  ],
108  'columns' => [],
109  ],
110  ];
111 
112  $expected = $input;
113  $expected['recordTitle'] = 'Test';
114 
115  $this->assertSame($expected, $this->subject->addData($input));
116  }
117 
122  {
123  $input = [
124  'tableName' => 'aTable',
125  'databaseRow' => [
126  'aField' => 'aValue',
127  ],
128  'processedTca' => [
129  'ctrl' => [
130  'label' => 'foo',
131  'label_userFunc' => function (&$parameters) {
132  $parameters['title'] = 'Value that MUST NOT be used, otherwise the code is broken.';
133  }
134  ],
135  'columns' => [
136  'aField' => [
137  'config' => [
138  'type' => 'input',
139  ],
140  ],
141  ],
142  ],
143  'isInlineChild' => true,
144  'inlineParentConfig' => [
145  'foreign_label' => 'aField',
146  ],
147  ];
148  $expected = $input;
149  $expected['recordTitle'] = 'aValue';
150  $this->assertSame($expected, $this->subject->addData($input));
151  }
152 
157  {
158  $input = [
159  'tableName' => 'aTable',
160  'databaseRow' => [
161  'aField' => 'aValue',
162  ],
163  'processedTca' => [
164  'ctrl' => [
165  'label' => 'foo',
166  'formattedLabel_userFunc' => function (&$parameters) {
167  $parameters['title'] = 'aFormattedLabel';
168  },
169  ],
170  'columns' => [
171  'aField' => [
172  'config' => [
173  'type' => 'input',
174  ],
175  ],
176  ],
177  ],
178  'isInlineChild' => true,
179  'inlineParentConfig' => [
180  'foreign_label' => 'aField',
181  ],
182  ];
183  $expected = $input;
184  $expected['recordTitle'] = 'aFormattedLabel';
185  $this->assertSame($expected, $this->subject->addData($input));
186  }
187 
192  {
193  $input = [
194  'tableName' => 'aTable',
195  'databaseRow' => [
196  'aField' => 'aValue',
197  ],
198  'processedTca' => [
199  'ctrl' => [
200  'label' => 'foo',
201  ],
202  'columns' => [
203  'aField' => [
204  'config' => [
205  'type' => 'input',
206  ],
207  ],
208  ],
209  ],
210  'isInlineChild' => true,
211  'inlineParentConfig' => [
212  'symmetric_label' => 'aField',
213  ],
214  'isOnSymmetricSide' => true,
215  ];
216  $expected = $input;
217  $expected['recordTitle'] = 'aValue';
218  $this->assertSame($expected, $this->subject->addData($input));
219  }
220 
224  public function addDataReturnsRecordTitleForUid()
225  {
226  $input = [
227  'tableName' => 'aTable',
228  'databaseRow' => [
229  'uid' => 'NEW56017ee37d10e587251374',
230  ],
231  'processedTca' => [
232  'ctrl' => [
233  'label' => 'uid'
234  ],
235  'columns' => [],
236  ]
237  ];
238 
240  $languageService = $this->prophesize(LanguageService::class);
241  $GLOBALS['LANG'] = $languageService->reveal();
242  $languageService->sL(Argument::cetera())->willReturnArgument(0);
243 
244  $expected = $input;
245  $expected['recordTitle'] = 'NEW56017ee37d10e587251374';
246  $this->assertSame($expected, $this->subject->addData($input));
247  }
248 
259  {
260  return [
261  'new record' => [
262  [
263  'type' => 'input',
264  ],
265  '',
266  '',
267  ],
268  'plain text input' => [
269  [
270  'type' => 'input',
271  ],
272  'aValue',
273  'aValue',
274  ],
275  'date input' => [
276  [
277  'type' => 'input',
278  'eval' => 'date'
279  ],
280  '978307261',
281  '01-01-01 (-7 days)',
282  ],
283  'date input (dbType: date)' => [
284  [
285  'type' => 'input',
286  'eval' => 'date',
287  'dbType' => 'date'
288  ],
289  '2001-01-01',
290  '01-01-01 (-7 days)',
291  ],
292  'date input (disableAgeDisplay: TRUE)' => [
293  [
294  'type' => 'input',
295  'eval' => 'date',
296  'disableAgeDisplay' => true
297  ],
298  '978307261',
299  '01-01-01',
300  ],
301  'time input' => [
302  [
303  'type' => 'input',
304  'eval' => 'time',
305  ],
306  '44100',
307  '12:15',
308  ],
309  'timesec input' => [
310  [
311  'type' => 'input',
312  'eval' => 'timesec',
313  ],
314  '44130',
315  '12:15:30',
316  ],
317  'datetime input' => [
318  [
319  'type' => 'input',
320  'eval' => 'datetime',
321  'dbType' => 'date'
322  ],
323  '978307261',
324  '01-01-01 00:01',
325  ],
326  'datetime input (dbType: datetime)' => [
327  [
328  'type' => 'input',
329  'eval' => 'datetime',
330  'dbType' => 'datetime'
331  ],
332  '2014-12-31 23:59:59',
333  '31-12-14 23:59',
334  ],
335  ];
336  }
337 
346  public function addDataReturnsRecordTitleForInputType($fieldConfig, $fieldValue, $expectedTitle)
347  {
348  $input = [
349  'tableName' => 'aTable',
350  'databaseRow' => [
351  'uid' => '1',
352  'aField' => $fieldValue,
353  ],
354  'processedTca' => [
355  'ctrl' => [
356  'label' => 'aField'
357  ],
358  'columns' => [
359  'aField' => [
360  'config' => $fieldConfig,
361  ]
362  ],
363  ]
364  ];
365 
367  $languageService = $this->prophesize(LanguageService::class);
368  $GLOBALS['LANG'] = $languageService->reveal();
369  $languageService->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears')
370  ->willReturn(' min| hrs| days| yrs| min| hour| day| year');
371  $languageService->sL(Argument::cetera())->willReturnArgument(0);
372  $GLOBALS['EXEC_TIME'] = 978912061;
373 
374  $expected = $input;
375  $expected['recordTitle'] = $expectedTitle;
376  $this->assertSame($expected, $this->subject->addData($input));
377  }
378 
383  {
384  $input = [
385  'tableName' => 'aTable',
386  'databaseRow' => [
387  'uid' => '1',
388  'aField' => '',
389  'anotherField' => 'anotherValue',
390  ],
391  'processedTca' => [
392  'ctrl' => [
393  'label' => 'aField',
394  'label_alt' => 'anotherField',
395  ],
396  'columns' => [
397  'aField' => [
398  'config' => [
399  'type' => 'input'
400  ]
401  ],
402  'anotherField' => [
403  'config' => [
404  'type' => 'input'
405  ]
406  ]
407  ],
408  ]
409  ];
410 
411  $expected = $input;
412  $expected['recordTitle'] = 'anotherValue';
413  $this->assertSame($expected, $this->subject->addData($input));
414  }
415 
420  {
421  $input = [
422  'tableName' => 'aTable',
423  'databaseRow' => [
424  'uid' => '1',
425  'aField' => '',
426  'anotherField' => '',
427  'additionalField' => 'additionalValue'
428  ],
429  'processedTca' => [
430  'ctrl' => [
431  'label' => 'aField',
432  'label_alt' => 'anotherField,additionalField',
433  ],
434  'columns' => [
435  'aField' => [
436  'config' => [
437  'type' => 'input'
438  ]
439  ],
440  'anotherField' => [
441  'config' => [
442  'type' => 'input'
443  ]
444  ],
445  'additionalField' => [
446  'config' => [
447  'type' => 'input'
448  ]
449  ],
450  ],
451  ]
452  ];
453 
454  $expected = $input;
455  $expected['recordTitle'] = 'additionalValue';
456  $this->assertSame($expected, $this->subject->addData($input));
457  }
458 
463  {
464  $input = [
465  'tableName' => 'aTable',
466  'databaseRow' => [
467  'uid' => '1',
468  'aField' => 'aField',
469  'anotherField' => 'anotherField'
470  ],
471  'processedTca' => [
472  'ctrl' => [
473  'label' => 'aField',
474  'label_alt' => 'anotherField',
475  'label_alt_force' => true,
476  ],
477  'columns' => [
478  'aField' => [
479  'config' => [
480  'type' => 'input'
481  ]
482  ],
483  'anotherField' => [
484  'config' => [
485  'type' => 'input'
486  ]
487  ],
488  ],
489  ]
490  ];
491 
492  $expected = $input;
493  $expected['recordTitle'] = 'aField, anotherField';
494  $this->assertSame($expected, $this->subject->addData($input));
495  }
496 
501  {
502  $input = [
503  'tableName' => 'aTable',
504  'databaseRow' => [
505  'uid' => '1',
506  'aField' => 'aField',
507  'anotherField' => 'anotherField',
508  'additionalField' => 'additionalValue'
509  ],
510  'processedTca' => [
511  'ctrl' => [
512  'label' => 'aField',
513  'label_alt' => 'anotherField,additionalField',
514  'label_alt_force' => true,
515  ],
516  'columns' => [
517  'aField' => [
518  'config' => [
519  'type' => 'input'
520  ]
521  ],
522  'anotherField' => [
523  'config' => [
524  'type' => 'input'
525  ]
526  ],
527  'additionalField' => [
528  'config' => [
529  'type' => 'input'
530  ]
531  ],
532  ],
533  ]
534  ];
535 
536  $expected = $input;
537  $expected['recordTitle'] = 'aField, anotherField, additionalValue';
538  $this->assertSame($expected, $this->subject->addData($input));
539  }
540 
545  {
546  $input = [
547  'tableName' => 'aTable',
548  'databaseRow' => [
549  'uid' => '1',
550  'aField' => 'aField',
551  'anotherField' => '',
552  'additionalField' => 'additionalValue'
553  ],
554  'processedTca' => [
555  'ctrl' => [
556  'label' => 'aField',
557  'label_alt' => 'anotherField,additionalField',
558  'label_alt_force' => true,
559  ],
560  'columns' => [
561  'aField' => [
562  'config' => [
563  'type' => 'input'
564  ]
565  ],
566  'anotherField' => [
567  'config' => [
568  'type' => 'input'
569  ]
570  ],
571  'additionalField' => [
572  'config' => [
573  'type' => 'input'
574  ]
575  ],
576  ],
577  ]
578  ];
579 
580  $expected = $input;
581  $expected['recordTitle'] = 'aField, additionalValue';
582  $this->assertSame($expected, $this->subject->addData($input));
583  }
584 
589  {
590  $input = [
591  'tableName' => 'aTable',
592  'databaseRow' => [
593  'uid' => '1',
594  'aField' => '2',
595  ],
596  'processedTca' => [
597  'ctrl' => [
598  'label' => 'aField'
599  ],
600  'columns' => [
601  'aField' => [
602  'config' => [
603  'type' => 'radio',
604  'items' => [
605  ['foo', 1],
606  ['bar', 2],
607  ['baz', 3],
608  ]
609  ]
610  ]
611  ],
612  ]
613  ];
614 
615  $expected = $input;
616  $expected['recordTitle'] = 'bar';
617  $this->assertSame($expected, $this->subject->addData($input));
618  }
619 
624  {
625  $input = [
626  'tableName' => 'aTable',
627  'databaseRow' => [
628  'uid' => '1',
629  'aField' => '2',
630  ],
631  'processedTca' => [
632  'ctrl' => [
633  'label' => 'aField'
634  ],
635  'columns' => [
636  'aField' => [
637  'config' => [
638  'type' => 'inline'
639  ],
640  'children' => [
641  [
642  'recordTitle' => 'foo',
643  'vanillaUid' => 2
644  ]
645  ]
646  ]
647  ],
648  ]
649  ];
650 
651  $expected = $input;
652  $expected['recordTitle'] = 'foo';
653  $this->assertSame($expected, $this->subject->addData($input));
654  }
655 
666  {
667  return [
668  'new record' => [
669  [
670  'internal_type' => 'db',
671  ],
672  [],
673  ''
674  ],
675  'internal_type: file' => [
676  [
677  'internal_type' => 'file',
678  ],
679  [
680  [
681  'uidOrPath' => 'somePath/aFile.jpg',
682  ],
683  [
684  'uidOrPath' => 'someOtherPath/anotherFile.png',
685  ],
686  ],
687  'somePath/aFile.jpg, someOtherPath/anotherFile.png',
688  ],
689  'internal_type: db, single table, single record' => [
690  [
691  'internal_type' => 'db',
692  'allowed' => 'aTable'
693  ],
694  [
695  [
696  'title' => 'aValue',
697  ],
698  ],
699  'aValue',
700  ],
701  'internal_type: db, single table, multiple records' => [
702  [
703  'internal_type' => 'db',
704  'allowed' => 'aTable'
705  ],
706  [
707  [
708  'title' => 'aValue',
709  ],
710  [
711  'title' => 'anotherValue',
712  ],
713  ],
714  'aValue, anotherValue',
715  ],
716  'internal_type: db, multiple tables, single record' => [
717  [
718  'internal_type' => 'db',
719  'allowed' => 'aTable,anotherTable'
720  ],
721  [
722  [
723  'uid' => 1,
724  'table' => 'anotherTable',
725  'title' => 'anotherValue',
726  ],
727  ],
728  'anotherValue',
729  ],
730  'internal_type: db, multiple tables, multiple records' => [
731  [
732  'internal_type' => 'db',
733  'allowed' => 'aTable,anotherTable'
734  ],
735  [
736  [
737  'uid' => 1,
738  'table' => 'aTable',
739  'title' => 'aValue',
740  ],
741  [
742  'uid' => 2,
743  'table' => 'anotherTable',
744  'title' => 'anotherValue',
745  ],
746  ],
747  'aValue, anotherValue',
748  ],
749  ];
750  }
751 
760  public function addDataReturnsRecordTitleForGroupType($fieldConfig, $fieldValue, $expectedTitle)
761  {
762  $input = [
763  'tableName' => 'aTable',
764  'databaseRow' => [
765  'uid' => '1',
766  'aField' => $fieldValue,
767  ],
768  'processedTca' => [
769  'ctrl' => [
770  'label' => 'aField'
771  ],
772  'columns' => [
773  'aField' => [
774  'config' => array_merge(
775  [
776  'type' => 'group',
777  ],
778  $fieldConfig
779  ),
780  ]
781  ],
782  ]
783  ];
784 
786  $languageService = $this->prophesize(LanguageService::class);
787  $GLOBALS['LANG'] = $languageService->reveal();
788  $languageService->sL(Argument::cetera())->willReturnArgument(0);
789 
790  $expected = $input;
791  $expected['recordTitle'] = $expectedTitle;
792  $this->assertSame($expected, $this->subject->addData($input));
793  }
794 
799  {
800  $input = [
801  'tableName' => 'aTable',
802  'databaseRow' => [
803  'uid' => '1',
804  'aField' => [
805  [
806  'uid' => 1,
807  'table' => 'aTable',
808  'title' => 'aValue',
809  ],
810  [
811  'uid' => 2,
812  'table' => 'anotherTable',
813  'title' => 'anotherValue',
814  ],
815  ],
816  ],
817  'processedTca' => [
818  'ctrl' => [
819  'label' => 'aField'
820  ],
821  'columns' => [
822  'aField' => [
823  'config' => [
824  'type' => 'group',
825  'internal_type' => 'db',
826  'allowed' => 'aTable,anotherTable',
827  ]
828  ]
829  ],
830  ]
831  ];
832 
833  $expected = $input;
834  $expected['recordTitle'] = 'aValue, anotherValue';
835  $this->assertSame($expected, $this->subject->addData($input));
836  }
837 
841  public function addDataReturnsRecordTitleForSingleCheckboxType()
842  {
843  $input = [
844  'tableName' => 'aTable',
845  'databaseRow' => [
846  'aField' => 1,
847  ],
848  'processedTca' => [
849  'ctrl' => [
850  'label' => 'aField'
851  ],
852  'columns' => [
853  'aField' => [
854  'config' => [
855  'type' => 'check',
856  ]
857  ]
858  ],
859  ]
860  ];
861 
863  $languageService = $this->prophesize(LanguageService::class);
864  $GLOBALS['LANG'] = $languageService->reveal();
865  $languageService->sL(Argument::cetera())->willReturnArgument(0)->shouldBeCalled();
866 
867  $expected = $input;
868  $expected['recordTitle'] = 'LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:yes';
869  $this->assertSame($expected, $this->subject->addData($input));
870  }
871 
876  {
877  $input = [
878  'tableName' => 'aTable',
879  'databaseRow' => [
880  'aField' => '5'
881  ],
882  'processedTca' => [
883  'ctrl' => [
884  'label' => 'aField'
885  ],
886  'columns' => [
887  'aField' => [
888  'config' => [
889  'type' => 'check',
890  'items' => [
891  ['foo', ''],
892  ['bar', ''],
893  ['baz', ''],
894  ]
895  ]
896  ]
897  ],
898  ]
899  ];
900 
901  $expected = $input;
902  $expected['recordTitle'] = 'foo, baz';
903  $this->assertSame($expected, $this->subject->addData($input));
904  }
905 
910  {
911  $input = [
912  'tableName' => 'aTable',
913  'databaseRow' => [
914  'aField' => [
915  'data' => [
916  'sDEF' => [
917  'lDEF' => [
918  'aFlexField' => [
919  'vDEF' => 'aFlexValue',
920  ]
921  ]
922  ]
923  ]
924  ]
925  ],
926  'processedTca' => [
927  'ctrl' => [
928  'label' => 'aField'
929  ],
930  'columns' => [
931  'aField' => [
932  'config' => [
933  'type' => 'flex',
934  'ds' => [
935  'sheets' => [
936  'sDEF' => [
937  'ROOT' => [
938  'type' => 'array',
939  'el' => [
940  'aFlexField' => [
941  'label' => 'Some input field',
942  'config' => [
943  'type' => 'input',
944  ],
945  ],
946  ],
947  ],
948  ],
949  ],
950  ]
951 
952  ]
953  ]
954  ],
955  ]
956  ];
957 
958  $expected = $input;
959  $expected['recordTitle'] = '';
960  $this->assertSame($expected, $this->subject->addData($input));
961  }
962 
967  {
968  $input = [
969  'tableName' => 'aTable',
970  'databaseRow' => [
971  'aField' => [
972  '1',
973  '2'
974  ]
975  ],
976  'processedTca' => [
977  'ctrl' => [
978  'label' => 'aField'
979  ],
980  'columns' => [
981  'aField' => [
982  'config' => [
983  'type' => 'select',
984  'items' => [
985  ['foo', 1, null, null],
986  ['bar', 2, null, null],
987  ['baz', 4, null, null],
988  ]
989  ]
990  ]
991  ],
992  ]
993  ];
994 
995  $expected = $input;
996  $expected['recordTitle'] = 'foo, bar';
997  $this->assertSame($expected, $this->subject->addData($input));
998  }
999 
1004  {
1005  $input = [
1006  'tableName' => 'aTable',
1007  'databaseRow' => [
1008  'aField' => '<p> text </p>',
1009  ],
1010  'processedTca' => [
1011  'ctrl' => [
1012  'label' => 'aField',
1013  ],
1014  'columns' => [
1015  'aField' => [
1016  'config' => [
1017  'type' => 'text',
1018  ],
1019  ],
1020  ],
1021  ],
1022  ];
1023 
1024  $expected = $input;
1025  $expected['recordTitle'] = 'text';
1026  $this->assertSame($expected, $this->subject->addData($input));
1027  }
1028 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']