TYPO3  7.6
TcaRecordTitleTest.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\Argument;
18 use Prophecy\Prophecy\ObjectProphecy;
20 use TYPO3\CMS\Core\Tests\UnitTestCase;
22 
26 class TcaRecordTitleTest extends UnitTestCase
27 {
31  protected $subject;
32 
36  protected $timeZone;
37 
38  public function setUp()
39  {
40  $this->subject = new TcaRecordTitle();
41  $this->timeZone = date_default_timezone_get();
42  date_default_timezone_set('UTC');
43  }
44 
45  protected function tearDown()
46  {
47  date_default_timezone_set($this->timeZone);
48  }
49 
54  {
55  $input = [
56  'tableName' => 'aTable',
57  'databaseRew' => [],
58  'processedTca' => [
59  'ctrl' => [],
60  ],
61  ];
62  $this->setExpectedException(\UnexpectedValueException::class, $this->any(), 1443706103);
63  $this->subject->addData($input);
64  }
65 
70  {
71  $input = [
72  'tableName' => 'aTable',
73  'databaseRow' => [],
74  'processedTca' => [
75  'ctrl' => [
76  'label' => 'uid',
77  'label_userFunc' => function (&$parameters) {
78  $parameters['title'] = 'Test';
79  }
80  ],
81  'columns' => [],
82  ],
83  ];
84 
85  $expected = $input;
86  $expected['recordTitle'] = 'Test';
87 
88  $this->assertSame($expected, $this->subject->addData($input));
89  }
90 
95  {
96  $input = [
97  'tableName' => 'aTable',
98  'databaseRow' => [],
99  'isInlineChild' => true,
100  'processedTca' => [
101  'ctrl' => [
102  'label' => 'uid',
103  'formattedLabel_userFunc' => function (&$parameters) {
104  $parameters['title'] = 'Test';
105  }
106  ],
107  'columns' => [],
108  ],
109  ];
110 
111  $expected = $input;
112  $expected['recordTitle'] = 'Test';
113 
114  $this->assertSame($expected, $this->subject->addData($input));
115  }
116 
121  {
122  $input = [
123  'tableName' => 'aTable',
124  'databaseRow' => [
125  'aField' => 'aValue',
126  ],
127  'processedTca' => [
128  'ctrl' => [
129  'label' => 'foo',
130  ],
131  'columns' => [
132  'aField' => [
133  'config' => [
134  'type' => 'input',
135  ],
136  ],
137  ],
138  ],
139  'isInlineChild' => true,
140  'inlineParentConfig' => [
141  'foreign_label' => 'aField',
142  ],
143  ];
144  $expected = $input;
145  $expected['recordTitle'] = 'aValue';
146  $this->assertSame($expected, $this->subject->addData($input));
147  }
148 
153  {
154  $input = [
155  'tableName' => 'aTable',
156  'databaseRow' => [
157  'aField' => 'aValue',
158  ],
159  'processedTca' => [
160  'ctrl' => [
161  'label' => 'foo',
162  ],
163  'columns' => [
164  'aField' => [
165  'config' => [
166  'type' => 'input',
167  ],
168  ],
169  ],
170  ],
171  'isInlineChild' => true,
172  'inlineParentConfig' => [
173  'symmetric_label' => 'aField',
174  ],
175  'isOnSymmetricSide' => true,
176  ];
177  $expected = $input;
178  $expected['recordTitle'] = 'aValue';
179  $this->assertSame($expected, $this->subject->addData($input));
180  }
181 
185  public function addDataReturnsRecordTitleForUid()
186  {
187  $input = [
188  'tableName' => 'aTable',
189  'databaseRow' => [
190  'uid' => 'NEW56017ee37d10e587251374',
191  ],
192  'processedTca' => [
193  'ctrl' => [
194  'label' => 'uid'
195  ],
196  'columns' => [],
197  ]
198  ];
199 
201  $languageService = $this->prophesize(LanguageService::class);
202  $GLOBALS['LANG'] = $languageService->reveal();
203  $languageService->sL(Argument::cetera())->willReturnArgument(0);
204 
205  $expected = $input;
206  $expected['recordTitle'] = 'NEW56017ee37d10e587251374';
207  $this->assertSame($expected, $this->subject->addData($input));
208  }
209 
220  {
221  return [
222  'new record' => [
223  [
224  'type' => 'input',
225  ],
226  '',
227  '',
228  ],
229  'plain text input' => [
230  [
231  'type' => 'input',
232  ],
233  'aValue',
234  'aValue',
235  ],
236  'date input' => [
237  [
238  'type' => 'input',
239  'eval' => 'date'
240  ],
241  '978307261',
242  '01-01-01 (-7 days)',
243  ],
244  'date input (dbType: date)' => [
245  [
246  'type' => 'input',
247  'eval' => 'date',
248  'dbType' => 'date'
249  ],
250  '2001-01-01',
251  '01-01-01 (-7 days)',
252  ],
253  'date input (disableAgeDisplay: TRUE)' => [
254  [
255  'type' => 'input',
256  'eval' => 'date',
257  'disableAgeDisplay' => true
258  ],
259  '978307261',
260  '01-01-01',
261  ],
262  'time input' => [
263  [
264  'type' => 'input',
265  'eval' => 'time',
266  ],
267  '44100',
268  '12:15',
269  ],
270  'timesec input' => [
271  [
272  'type' => 'input',
273  'eval' => 'timesec',
274  ],
275  '44130',
276  '12:15:30',
277  ],
278  'datetime input' => [
279  [
280  'type' => 'input',
281  'eval' => 'datetime',
282  'dbType' => 'date'
283  ],
284  '978307261',
285  '01-01-01 00:01',
286  ],
287  'datetime input (dbType: datetime)' => [
288  [
289  'type' => 'input',
290  'eval' => 'datetime',
291  'dbType' => 'datetime'
292  ],
293  '2014-12-31 23:59:59',
294  '31-12-14 23:59',
295  ],
296  ];
297  }
298 
307  public function addDataReturnsRecordTitleForInputType($fieldConfig, $fieldValue, $expectedTitle)
308  {
309  $input = [
310  'tableName' => 'aTable',
311  'databaseRow' => [
312  'uid' => '1',
313  'aField' => $fieldValue,
314  ],
315  'processedTca' => [
316  'ctrl' => [
317  'label' => 'aField'
318  ],
319  'columns' => [
320  'aField' => [
321  'config' => $fieldConfig,
322  ]
323  ],
324  ]
325  ];
326 
328  $languageService = $this->prophesize(LanguageService::class);
329  $GLOBALS['LANG'] = $languageService->reveal();
330  $languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')
331  ->willReturn(' min| hrs| days| yrs| min| hour| day| year');
332  $languageService->sL(Argument::cetera())->willReturnArgument(0);
333  $GLOBALS['EXEC_TIME'] = 978912061;
334 
335  $expected = $input;
336  $expected['recordTitle'] = $expectedTitle;
337  $this->assertSame($expected, $this->subject->addData($input));
338  }
339 
344  {
345  $input = [
346  'tableName' => 'aTable',
347  'databaseRow' => [
348  'uid' => '1',
349  'aField' => '',
350  'anotherField' => 'anotherValue',
351  ],
352  'processedTca' => [
353  'ctrl' => [
354  'label' => 'aField',
355  'label_alt' => 'anotherField',
356  ],
357  'columns' => [
358  'aField' => [
359  'config' => [
360  'type' => 'input'
361  ]
362  ],
363  'anotherField' => [
364  'config' => [
365  'type' => 'input'
366  ]
367  ]
368  ],
369  ]
370  ];
371 
372  $expected = $input;
373  $expected['recordTitle'] = 'anotherValue';
374  $this->assertSame($expected, $this->subject->addData($input));
375  }
376 
381  {
382  $input = [
383  'tableName' => 'aTable',
384  'databaseRow' => [
385  'uid' => '1',
386  'aField' => '',
387  'anotherField' => '',
388  'additionalField' => 'additionalValue'
389  ],
390  'processedTca' => [
391  'ctrl' => [
392  'label' => 'aField',
393  'label_alt' => 'anotherField,additionalField',
394  ],
395  'columns' => [
396  'aField' => [
397  'config' => [
398  'type' => 'input'
399  ]
400  ],
401  'anotherField' => [
402  'config' => [
403  'type' => 'input'
404  ]
405  ],
406  'additionalField' => [
407  'config' => [
408  'type' => 'input'
409  ]
410  ],
411  ],
412  ]
413  ];
414 
415  $expected = $input;
416  $expected['recordTitle'] = 'additionalValue';
417  $this->assertSame($expected, $this->subject->addData($input));
418  }
419 
424  {
425  $input = [
426  'tableName' => 'aTable',
427  'databaseRow' => [
428  'uid' => '1',
429  'aField' => 'aField',
430  'anotherField' => 'anotherField'
431  ],
432  'processedTca' => [
433  'ctrl' => [
434  'label' => 'aField',
435  'label_alt' => 'anotherField',
436  'label_alt_force' => true,
437  ],
438  'columns' => [
439  'aField' => [
440  'config' => [
441  'type' => 'input'
442  ]
443  ],
444  'anotherField' => [
445  'config' => [
446  'type' => 'input'
447  ]
448  ],
449  ],
450  ]
451  ];
452 
453  $expected = $input;
454  $expected['recordTitle'] = 'aField, anotherField';
455  $this->assertSame($expected, $this->subject->addData($input));
456  }
457 
462  {
463  $input = [
464  'tableName' => 'aTable',
465  'databaseRow' => [
466  'uid' => '1',
467  'aField' => 'aField',
468  'anotherField' => 'anotherField',
469  'additionalField' => 'additionalValue'
470  ],
471  'processedTca' => [
472  'ctrl' => [
473  'label' => 'aField',
474  'label_alt' => 'anotherField,additionalField',
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  'additionalField' => [
489  'config' => [
490  'type' => 'input'
491  ]
492  ],
493  ],
494  ]
495  ];
496 
497  $expected = $input;
498  $expected['recordTitle'] = 'aField, anotherField, additionalValue';
499  $this->assertSame($expected, $this->subject->addData($input));
500  }
501 
506  {
507  $input = [
508  'tableName' => 'aTable',
509  'databaseRow' => [
510  'uid' => '1',
511  'aField' => 'aField',
512  'anotherField' => '',
513  'additionalField' => 'additionalValue'
514  ],
515  'processedTca' => [
516  'ctrl' => [
517  'label' => 'aField',
518  'label_alt' => 'anotherField,additionalField',
519  'label_alt_force' => true,
520  ],
521  'columns' => [
522  'aField' => [
523  'config' => [
524  'type' => 'input'
525  ]
526  ],
527  'anotherField' => [
528  'config' => [
529  'type' => 'input'
530  ]
531  ],
532  'additionalField' => [
533  'config' => [
534  'type' => 'input'
535  ]
536  ],
537  ],
538  ]
539  ];
540 
541  $expected = $input;
542  $expected['recordTitle'] = 'aField, additionalValue';
543  $this->assertSame($expected, $this->subject->addData($input));
544  }
545 
550  {
551  $input = [
552  'tableName' => 'aTable',
553  'databaseRow' => [
554  'uid' => '1',
555  'aField' => '2',
556  ],
557  'processedTca' => [
558  'ctrl' => [
559  'label' => 'aField'
560  ],
561  'columns' => [
562  'aField' => [
563  'config' => [
564  'type' => 'radio',
565  'items' => [
566  ['foo', 1],
567  ['bar', 2],
568  ['baz', 3],
569  ]
570  ]
571  ]
572  ],
573  ]
574  ];
575 
576  $expected = $input;
577  $expected['recordTitle'] = 'bar';
578  $this->assertSame($expected, $this->subject->addData($input));
579  }
580 
591  {
592  return [
593  'new record' => [
594  [
595  'internal_type' => 'db',
596  ],
597  '',
598  ''
599  ],
600  'internal_type: file' => [
601  [
602  'internal_type' => 'file',
603  ],
604  'somePath/aFile.jpg,someOtherPath/anotherFile.png',
605  'somePath/aFile.jpg, someOtherPath/anotherFile.png',
606  ],
607  'internal_type: db, single table, single record' => [
608  [
609  'internal_type' => 'db',
610  'allowed' => 'aTable'
611  ],
612  '1|aValue',
613  'aValue',
614  ],
615  'internal_type: db, single table, multiple records' => [
616  [
617  'internal_type' => 'db',
618  'allowed' => 'aTable'
619  ],
620  '1|aValue,3|anotherValue',
621  'aValue, anotherValue',
622  ],
623  'internal_type: db, multiple tables, single record' => [
624  [
625  'internal_type' => 'db',
626  'allowed' => 'aTable,anotherTable'
627  ],
628  'anotherTable_1|anotherValue',
629  'anotherValue',
630  ],
631  'internal_type: db, multiple tables, multiple records' => [
632  [
633  'internal_type' => 'db',
634  'allowed' => 'aTable,anotherTable'
635  ],
636  'anotherTable_1|anotherValue,aTable_1|aValue',
637  'aValue, anotherValue',
638  ],
639  ];
640  }
641 
650  public function addDataReturnsRecordTitleForGroupType($fieldConfig, $fieldValue, $expectedTitle)
651  {
652  $input = [
653  'tableName' => 'aTable',
654  'databaseRow' => [
655  'uid' => '1',
656  'aField' => $fieldValue,
657  ],
658  'processedTca' => [
659  'ctrl' => [
660  'label' => 'aField'
661  ],
662  'columns' => [
663  'aField' => [
664  'config' => array_merge(
665  [
666  'type' => 'group',
667  ],
668  $fieldConfig
669  ),
670  ]
671  ],
672  ]
673  ];
674 
676  $languageService = $this->prophesize(LanguageService::class);
677  $GLOBALS['LANG'] = $languageService->reveal();
678  $languageService->sL(Argument::cetera())->willReturnArgument(0);
679 
680  $expected = $input;
681  $expected['recordTitle'] = $expectedTitle;
682  $this->assertSame($expected, $this->subject->addData($input));
683  }
684 
689  {
690  $input = [
691  'tableName' => 'aTable',
692  'databaseRow' => [
693  'uid' => '1',
694  'aField' => 'aTable_1|aValue,anotherTable_2|anotherValue',
695  ],
696  'processedTca' => [
697  'ctrl' => [
698  'label' => 'aField'
699  ],
700  'columns' => [
701  'aField' => [
702  'config' => [
703  'type' => 'group',
704  'internal_type' => 'db',
705  'allowed' => 'aTable,anotherTable',
706  ]
707  ]
708  ],
709  ]
710  ];
711 
712  $expected = $input;
713  $expected['recordTitle'] = 'aValue, anotherValue';
714  $this->assertSame($expected, $this->subject->addData($input));
715  }
716 
720  public function addDataReturnsRecordTitleForSingleCheckboxType()
721  {
722  $input = [
723  'tableName' => 'aTable',
724  'databaseRow' => [
725  'aField' => 1,
726  ],
727  'processedTca' => [
728  'ctrl' => [
729  'label' => 'aField'
730  ],
731  'columns' => [
732  'aField' => [
733  'config' => [
734  'type' => 'check',
735  ]
736  ]
737  ],
738  ]
739  ];
740 
742  $languageService = $this->prophesize(LanguageService::class);
743  $GLOBALS['LANG'] = $languageService->reveal();
744  $languageService->sL(Argument::cetera())->willReturnArgument(0)->shouldBeCalled();
745 
746  $expected = $input;
747  $expected['recordTitle'] = 'LLL:EXT:lang/locallang_common.xlf:yes';
748  $this->assertSame($expected, $this->subject->addData($input));
749  }
750 
755  {
756  $input = [
757  'tableName' => 'aTable',
758  'databaseRow' => [
759  'aField' => '5'
760  ],
761  'processedTca' => [
762  'ctrl' => [
763  'label' => 'aField'
764  ],
765  'columns' => [
766  'aField' => [
767  'config' => [
768  'type' => 'check',
769  'items' => [
770  ['foo', ''],
771  ['bar', ''],
772  ['baz', ''],
773  ]
774  ]
775  ]
776  ],
777  ]
778  ];
779 
780  $expected = $input;
781  $expected['recordTitle'] = 'foo, baz';
782  $this->assertSame($expected, $this->subject->addData($input));
783  }
784 
789  {
790  $input = [
791  'tableName' => 'aTable',
792  'databaseRow' => [
793  'aField' => [
794  'data' => [
795  'sDEF' => [
796  'lDEF' => [
797  'aFlexField' => [
798  'vDEF' => 'aFlexValue',
799  ]
800  ]
801  ]
802  ]
803  ]
804  ],
805  'processedTca' => [
806  'ctrl' => [
807  'label' => 'aField'
808  ],
809  'columns' => [
810  'aField' => [
811  'config' => [
812  'type' => 'flex',
813  'ds' => [
814  'sheets' => [
815  'sDEF' => [
816  'ROOT' => [
817  'type' => 'array',
818  'el' => [
819  'aFlexField' => [
820  'label' => 'Some input field',
821  'config' => [
822  'type' => 'input',
823  ],
824  ],
825  ],
826  ],
827  ],
828  ],
829  ]
830 
831  ]
832  ]
833  ],
834  ]
835  ];
836 
837  $expected = $input;
838  $expected['recordTitle'] = '';
839  $this->assertSame($expected, $this->subject->addData($input));
840  }
841 
846  {
847  $input = [
848  'tableName' => 'aTable',
849  'databaseRow' => [
850  'aField' => [
851  '1',
852  '2'
853  ]
854  ],
855  'processedTca' => [
856  'ctrl' => [
857  'label' => 'aField'
858  ],
859  'columns' => [
860  'aField' => [
861  'config' => [
862  'type' => 'select',
863  'items' => [
864  ['foo', 1, null, null],
865  ['bar', 2, null, null],
866  ['baz', 4, null, null],
867  ]
868  ]
869  ]
870  ],
871  ]
872  ];
873 
874  $expected = $input;
875  $expected['recordTitle'] = 'foo, bar';
876  $this->assertSame($expected, $this->subject->addData($input));
877  }
878 
883  {
884  $input = [
885  'tableName' => 'aTable',
886  'databaseRow' => [
887  'aField' => '<p> text </p>',
888  ],
889  'processedTca' => [
890  'ctrl' => [
891  'label' => 'aField',
892  ],
893  'columns' => [
894  'aField' => [
895  'config' => [
896  'type' => 'text',
897  ],
898  ],
899  ],
900  ],
901  ];
902 
903  $expected = $input;
904  $expected['recordTitle'] = 'text';
905  $this->assertSame($expected, $this->subject->addData($input));
906  }
907 }