TYPO3 CMS  TYPO3_7-6
BackendUtilityTest.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 
31 
36 {
38  // Tests concerning calcAge
40 
45  public function calcAgeDataProvider()
46  {
47  return [
48  'Single year' => [
49  'seconds' => 60 * 60 * 24 * 365,
50  'expectedLabel' => '1 year'
51  ],
52  'Plural years' => [
53  'seconds' => 60 * 60 * 24 * 365 * 2,
54  'expectedLabel' => '2 yrs'
55  ],
56  'Single negative year' => [
57  'seconds' => 60 * 60 * 24 * 365 * -1,
58  'expectedLabel' => '-1 year'
59  ],
60  'Plural negative years' => [
61  'seconds' => 60 * 60 * 24 * 365 * 2 * -1,
62  'expectedLabel' => '-2 yrs'
63  ],
64  'Single day' => [
65  'seconds' => 60 * 60 * 24,
66  'expectedLabel' => '1 day'
67  ],
68  'Plural days' => [
69  'seconds' => 60 * 60 * 24 * 2,
70  'expectedLabel' => '2 days'
71  ],
72  'Single negative day' => [
73  'seconds' => 60 * 60 * 24 * -1,
74  'expectedLabel' => '-1 day'
75  ],
76  'Plural negative days' => [
77  'seconds' => 60 * 60 * 24 * 2 * -1,
78  'expectedLabel' => '-2 days'
79  ],
80  'Single hour' => [
81  'seconds' => 60 * 60,
82  'expectedLabel' => '1 hour'
83  ],
84  'Plural hours' => [
85  'seconds' => 60 * 60 * 2,
86  'expectedLabel' => '2 hrs'
87  ],
88  'Single negative hour' => [
89  'seconds' => 60 * 60 * -1,
90  'expectedLabel' => '-1 hour'
91  ],
92  'Plural negative hours' => [
93  'seconds' => 60 * 60 * 2 * -1,
94  'expectedLabel' => '-2 hrs'
95  ],
96  'Single minute' => [
97  'seconds' => 60,
98  'expectedLabel' => '1 min'
99  ],
100  'Plural minutes' => [
101  'seconds' => 60 * 2,
102  'expectedLabel' => '2 min'
103  ],
104  'Single negative minute' => [
105  'seconds' => 60 * -1,
106  'expectedLabel' => '-1 min'
107  ],
108  'Plural negative minutes' => [
109  'seconds' => 60 * 2 * -1,
110  'expectedLabel' => '-2 min'
111  ],
112  'Zero seconds' => [
113  'seconds' => 0,
114  'expectedLabel' => '0 min'
115  ]
116  ];
117  }
118 
126  public function calcAgeReturnsExpectedValues($seconds, $expectedLabel)
127  {
128  $this->assertSame($expectedLabel, BackendUtility::calcAge($seconds));
129  }
130 
132  // Tests concerning getProcessedValue
134 
139  {
140  $GLOBALS['TCA'] = [
141  'tt_content' => [
142  'columns' => [
143  'header' => [
144  'config' => [
145  'type' => 'input',
146  ],
147  ],
148  ],
149  ],
150  ];
151  $this->assertEquals('0', BackendUtility::getProcessedValue('tt_content', 'header', '0'));
152  }
153 
157  public function getProcessedValueForGroup()
158  {
159  $GLOBALS['TCA'] = [
160  'tt_content' => [
161  'columns' => [
162  'multimedia' => [
163  'config' => [
164  'type' => 'group',
165  ],
166  ],
167  ],
168  ],
169  ];
170  $this->assertSame('1, 2', BackendUtility::getProcessedValue('tt_content', 'multimedia', '1,2'));
171  }
172 
177  {
178  $GLOBALS['TCA'] = [
179  'tt_content' => [
180  'columns' => [
181  'pages' => [
182  'config' => [
183  'type' => 'group',
184  'allowed' => 'pages',
185  'internal_type' => 'db',
186  'maxitems' => 22,
187  'minitems' => 0,
188  'show_thumbs' => 1,
189  'size' => 3,
190  ],
191  ],
192  ],
193  ],
194  ];
195 
196  $this->assertSame('Page 1, Page 2', ProcessedValueForGroupWithOneAllowedTableFixture::getProcessedValue('tt_content', 'pages', '1,2'));
197  }
198 
203  {
204  $GLOBALS['TCA'] = [
205  'index_config' => [
206  'columns' => [
207  'indexcfgs' => [
208  'config' => [
209  'type' => 'group',
210  'internal_type' => 'db',
211  'allowed' => 'index_config,pages',
212  'size' => 5,
213  ],
214  ],
215  ],
216  ],
217  ];
218 
219  $this->assertSame('Page 1, Configuration 2', ProcessedValueForGroupWithMultipleAllowedTablesFixture::getProcessedValue('index_config', 'indexcfgs', 'pages_1,index_config_2'));
220  }
221 
226  {
227  $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection::class, [], [], '', false);
228  $GLOBALS['TYPO3_DB']->expects($this->any())->method('fullQuoteStr')
229  ->will($this->returnCallback(
230  function ($quoteStr) {
231  return "'" . $quoteStr . "'";
232  }
233  )
234  );
235  $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTquery')->will($this->returnValue(0));
236  $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_free_result');
237  $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_fetch_assoc')
238  ->will($this->returnCallback(
239  function () {
240  static $called = 0;
241  ++$called;
242  switch ($called) {
243  // SELECT * FROM sys_category_record_mm
244  case 1:
245  return [
246  'uid_local' => 1, // uid of a sys_category record
247  'uid_foreign' => 1, // uid of a pages record
248  ];
249  case 2:
250  return [
251  'uid_local' => 2, // uid of a sys_category record
252  'uid_foreign' => 1, // uid of a pages record
253  ];
254  case 3:
255  return null;
256  // SELECT * FROM sys_catgory
257  case 4:
258  return [
259  'uid' => 1,
260  'title' => 'Category 1',
261  ];
262  case 5:
263  return [
264  'uid' => 2,
265  'title' => 'Category 2',
266  ];
267  case 6:
268  return null;
269  }
270  return null;
271  }
272  )
273  );
274 
275  $GLOBALS['TCA'] = [
276  'pages' => [
277  'columns' => [
278  'categories' => [
279  'config' => [
280  'type' => 'select',
281  'foreign_table' => 'sys_category',
282  'MM' => 'sys_category_record_mm',
283  'MM_match_fields' => [
284  'fieldname' => 'categories',
285  'tablesnames' => 'pages',
286  ],
287  'MM_opposite_field' => 'items',
288  ],
289  ],
290  ],
291  ],
292  'sys_category' => [
293  'columns' => [
294  'items' => [
295  'config' => [
296  'type' => 'group',
297  'internal_type' => 'db',
298  'allowed' => '*',
299  'MM' => 'sys_category_record_mm',
300  'MM_oppositeUsage' => [],
301  ]
302  ]
303  ],
304  ],
305  ];
306 
307  $this->assertSame('Category 1; Category 2', ProcessedValueForSelectWithMMRelationFixture::getProcessedValue('pages', 'categories', '2', 0, false, false, 1));
308  }
309 
313  public function getProcessedValueDisplaysAgeForDateInputFieldsIfSettingAbsent()
314  {
316  $languageServiceProphecy = $this->prophesize(LanguageService::class);
317  $languageServiceProphecy->sL(Argument::cetera())->willReturn(' min| hrs| days| yrs| min| hour| day| year');
318  $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
319 
320  $GLOBALS['EXEC_TIME'] = mktime(0, 0, 0, 8, 30, 2015);
321 
322  $GLOBALS['TCA'] = [
323  'tt_content' => [
324  'columns' => [
325  'date' => [
326  'config' => [
327  'type' => 'input',
328  'eval' => 'date',
329  ],
330  ],
331  ],
332  ],
333  ];
334  $this->assertSame('28-08-15 (-2 days)', BackendUtility::getProcessedValue('tt_content', 'date', mktime(0, 0, 0, 8, 28, 2015)));
335  }
336 
340  public function inputTypeDateDisplayOptions()
341  {
342  return [
343  'typeSafe Setting' => [
344  true,
345  '28-08-15',
346  ],
347  'non typesafe setting' => [
348  1,
349  '28-08-15',
350  ],
351  'setting disabled typesafe' => [
352  false,
353  '28-08-15 (-2 days)',
354  ],
355  'setting disabled not typesafe' => [
356  0,
357  '28-08-15 (-2 days)',
358  ],
359  ];
360  }
361 
370  public function getProcessedValueHandlesAgeDisplayCorrectly($input, $expected)
371  {
373  $languageServiceProphecy = $this->prophesize(LanguageService::class);
374  $languageServiceProphecy->sL(Argument::cetera())->willReturn(' min| hrs| days| yrs| min| hour| day| year');
375  $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
376 
377  $GLOBALS['EXEC_TIME'] = mktime(0, 0, 0, 8, 30, 2015);
378 
379  $GLOBALS['TCA'] = [
380  'tt_content' => [
381  'columns' => [
382  'date' => [
383  'config' => [
384  'type' => 'input',
385  'eval' => 'date',
386  'disableAgeDisplay' => $input,
387  ],
388  ],
389  ],
390  ],
391  ];
392  $this->assertSame($expected, BackendUtility::getProcessedValue('tt_content', 'date', mktime(0, 0, 0, 8, 28, 2015)));
393  }
394 
405  {
406  return [
407  'only uid' => [
408  'table' => 'test_table',
409  'prefix' => '',
410  'presetFields' => [],
411  'tca' => [],
412  'expectedFields' => 'uid'
413  ],
414  'label set' => [
415  'table' => 'test_table',
416  'prefix' => '',
417  'presetFields' => [],
418  'tca' => [
419  'ctrl' => [
420  'label' => 'label'
421  ]
422  ],
423  'expectedFields' => 'uid,label'
424  ],
425  'label_alt set' => [
426  'table' => 'test_table',
427  'prefix' => '',
428  'presetFields' => [],
429  'tca' => [
430  'ctrl' => [
431  'label_alt' => 'label,label2'
432  ]
433  ],
434  'expectedFields' => 'uid,label,label2'
435  ],
436  'versioningWS set' => [
437  'table' => 'test_table',
438  'prefix' => '',
439  'presetFields' => [],
440  'tca' => [
441  'ctrl' => [
442  'versioningWS' => true
443  ]
444  ],
445  'expectedFields' => 'uid,t3ver_id,t3ver_state,t3ver_wsid,t3ver_count'
446  ],
447  'selicon_field set' => [
448  'table' => 'test_table',
449  'prefix' => '',
450  'presetFields' => [],
451  'tca' => [
452  'ctrl' => [
453  'selicon_field' => 'field'
454  ]
455  ],
456  'expectedFields' => 'uid,field'
457  ],
458  'typeicon_column set' => [
459  'table' => 'test_table',
460  'prefix' => '',
461  'presetFields' => [],
462  'tca' => [
463  'ctrl' => [
464  'typeicon_column' => 'field'
465  ]
466  ],
467  'expectedFields' => 'uid,field'
468  ],
469  'enablecolumns set' => [
470  'table' => 'test_table',
471  'prefix' => '',
472  'presetFields' => [],
473  'tca' => [
474  'ctrl' => [
475  'enablecolumns' => [
476  'disabled' => 'hidden',
477  'starttime' => 'start',
478  'endtime' => 'stop',
479  'fe_group' => 'groups'
480  ]
481  ]
482  ],
483  'expectedFields' => 'uid,hidden,start,stop,groups'
484  ],
485  'label set to uid' => [
486  'table' => 'test_table',
487  'prefix' => '',
488  'presetFields' => [],
489  'tca' => [
490  'ctrl' => [
491  'label' => 'uid'
492  ]
493  ],
494  'expectedFields' => 'uid'
495  ]
496  ];
497  }
498 
509  public function getCommonSelectFieldsReturnsCorrectFields($table, $prefix = '', array $presetFields, array $tca, $expectedFields = '')
510  {
511  $GLOBALS['TCA'][$table] = $tca;
512  $selectFields = BackendUtility::getCommonSelectFields($table, $prefix, $presetFields);
513  $this->assertEquals($selectFields, $expectedFields);
514  }
515 
526  {
527  return [
528  'item set' => [
529  'table' => 'tt_content',
530  'col' => 'menu_type',
531  'key' => '1',
532  'tca' => [
533  'columns' => [
534  'menu_type' => [
535  'config' => [
536  'items' => [
537  ['Item 1', '0'],
538  ['Item 2', '1'],
539  ['Item 3', '3']
540  ]
541  ]
542  ]
543  ]
544  ],
545  'expectedLabel' => 'Item 2'
546  ],
547  'item set twice' => [
548  'table' => 'tt_content',
549  'col' => 'menu_type',
550  'key' => '1',
551  'tca' => [
552  'columns' => [
553  'menu_type' => [
554  'config' => [
555  'items' => [
556  ['Item 1', '0'],
557  ['Item 2a', '1'],
558  ['Item 2b', '1'],
559  ['Item 3', '3']
560  ]
561  ]
562  ]
563  ]
564  ],
565  'expectedLabel' => 'Item 2a'
566  ],
567  'item not found' => [
568  'table' => 'tt_content',
569  'col' => 'menu_type',
570  'key' => '5',
571  'tca' => [
572  'columns' => [
573  'menu_type' => [
574  'config' => [
575  'items' => [
576  ['Item 1', '0'],
577  ['Item 2', '1'],
578  ['Item 3', '2']
579  ]
580  ]
581  ]
582  ]
583  ],
584  'expectedLabel' => null
585  ]
586  ];
587  }
588 
599  public function getLabelFromItemlistReturnsCorrectFields($table, $col = '', $key = '', array $tca, $expectedLabel = '')
600  {
601  $GLOBALS['TCA'][$table] = $tca;
602  $label = BackendUtility::getLabelFromItemlist($table, $col, $key);
603  $this->assertEquals($label, $expectedLabel);
604  }
605 
616  {
617  return [
618  'no field found' => [
619  'pageId' => '123',
620  'table' => 'tt_content',
621  'col' => 'menu_type',
622  'key' => '10',
623  'tca' => [
624  'columns' => [
625  'menu_type' => [
626  'config' => [
627  'items' => [
628  ['Item 1', '0'],
629  ['Item 2', '1'],
630  ['Item 3', '3']
631  ]
632  ]
633  ]
634  ]
635  ],
636  'expectedLabel' => ''
637  ],
638  'no tsconfig set' => [
639  'pageId' => '123',
640  'table' => 'tt_content',
641  'col' => 'menu_type',
642  'key' => '1',
643  'tca' => [
644  'columns' => [
645  'menu_type' => [
646  'config' => [
647  'items' => [
648  ['Item 1', '0'],
649  ['Item 2', '1'],
650  ['Item 3', '3']
651  ]
652  ]
653  ]
654  ]
655  ],
656  'expectedLabel' => 'Item 2'
657  ]
658  ];
659  }
660 
672  public function getLabelFromItemListMergedReturnsCorrectFields($pageId, $table, $column = '', $key = '', array $tca, $expectedLabel = '')
673  {
674  $GLOBALS['TCA'][$table] = $tca;
675 
676  $this->assertEquals($expectedLabel, LabelFromItemListMergedReturnsCorrectFieldsFixture::getLabelFromItemListMerged($pageId, $table, $column, $key));
677  }
678 
687  {
688  $this->assertStringMatchesFormat('<input %Svalue="1"%S/>', BackendUtility::getFuncCheck('params', 'test', true));
689  }
690 
691  /*
692  * Tests concerning getLabelsFromItemsList
693  */
694 
699  {
700  return [
701  'return value if found' => [
702  'foobar', // table
703  'someColumn', // col
704  'foo, bar', // keyList
705  [ // TCA
706  'columns' => [
707  'someColumn' => [
708  'config' => [
709  'items' => [
710  '0' => ['aFooLabel', 'foo'],
711  '1' => ['aBarLabel', 'bar']
712  ]
713  ]
714  ]
715  ]
716  ],
717  [], // page TSconfig
718  'aFooLabel, aBarLabel' // expected
719  ],
720  'page TSconfig overrules TCA' => [
721  'foobar', // table
722  'someColumn', // col
723  'foo,bar, add', // keyList
724  [ // TCA
725  'columns' => [
726  'someColumn' => [
727  'config' => [
728  'items' => [
729  '0' => ['aFooLabel', 'foo'],
730  '1' => ['aBarLabel', 'bar']
731  ]
732  ]
733  ]
734  ]
735  ],
736  [ // page TSconfig
737  'addItems.' => ['add' => 'aNewLabel'],
738  'altLabels.' => ['bar' => 'aBarDiffLabel'],
739  ],
740  'aFooLabel, aBarDiffLabel, aNewLabel' // expected
741  ]
742  ];
743  }
744 
756  public function getLabelsFromItemsListReturnsCorrectValue($table, $col, $keyList, $tca, array $pageTsConfig, $expectedLabel)
757  {
758  // Stub LanguageService and let sL() return the same value that came in again
759  $GLOBALS['LANG'] = $this->getMock(LanguageService::class, [], [], '', false);
760  $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
761 
762  $GLOBALS['TCA'][$table] = $tca;
763  $label = BackendUtility::getLabelsFromItemsList($table, $col, $keyList, $pageTsConfig);
764  $this->assertEquals($expectedLabel, $label);
765  }
766 
771  {
772  $table = 'foobar';
773  $col = 'someColumn';
774  $tca = [
775  'columns' => [
776  'someColumn' => [
777  'config' => [
778  'type' => 'select',
779  'items' => [
780  '0' => ['aFooLabel', 'foo'],
781  '1' => ['aBarLabel', 'bar']
782  ]
783  ]
784  ]
785  ]
786  ];
787  // Stub LanguageService and let sL() return the same value that came in again
788  $GLOBALS['LANG'] = $this->getMock(LanguageService::class, [], [], '', false);
789  $GLOBALS['LANG']->charSet = 'utf-8';
790  $GLOBALS['LANG']->csConvObj = $this->getMock(CharsetConverter::class);
791  $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
792 
793  $GLOBALS['LANG']->csConvObj->expects($this->any())->method('crop')->will($this->returnArgument(1));
794 
795  $GLOBALS['TCA'][$table] = $tca;
796  $label = BackendUtility::getProcessedValue($table, $col, 'foo,invalidKey,bar');
797  $this->assertEquals('aFooLabel, aBarLabel', $label);
798  }
799 
804  {
805  $table = 'foobar';
806  $col = 'someColumn';
807  $tca = [
808  'columns' => [
809  'someColumn' => [
810  'config' => [
811  'type' => 'select',
812  'items' => [
813  '0' => ['aFooLabel', 'foo']
814  ]
815  ]
816  ]
817  ]
818  ];
819  // Stub LanguageService and let sL() return the same value that came in again
820  $GLOBALS['LANG'] = $this->getMock(LanguageService::class, [], [], '', false);
821  $GLOBALS['LANG']->charSet = 'utf-8';
822  $GLOBALS['LANG']->csConvObj = $this->getMock(CharsetConverter::class);
823  $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
824 
825  $GLOBALS['LANG']->csConvObj->expects($this->any())->method('crop')->will($this->returnArgument(1));
826 
827  $GLOBALS['TCA'][$table] = $tca;
828  $label = BackendUtility::getProcessedValue($table, $col, 'invalidKey');
829  $this->assertEquals('invalidKey', $label);
830  }
831 
840  {
841  // Make sure the hook inside viewOnClick is not fired. This may be removed if unit tests
842  // bootstrap does not initialize TYPO3_CONF_VARS anymore.
843  unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']);
844 
845  $alternativeUrl = 'https://typo3.org/about/typo3-the-cms/the-history-of-typo3/#section';
846  $onclickCode = 'var previewWin = window.open(' . GeneralUtility::quoteJSvalue($alternativeUrl) . ',\'newTYPO3frontendWindow\');';
847  $this->assertStringMatchesFormat(
848  $onclickCode,
849  BackendUtility::viewOnClick(null, null, null, null, $alternativeUrl, null, false)
850  );
851  }
852 
857  {
858  $completeConfiguration = [
859  'value' => 'bar',
860  'properties' => [
861  'permissions.' => [
862  'file.' => [
863  'default.' => ['readAction' => '1'],
864  '1.' => ['writeAction' => '1'],
865  '0.' => ['readAction' => '0'],
866  ],
867  ]
868  ]
869  ];
870 
871  $GLOBALS['BE_USER'] = $this->getMock(BackendUserAuthentication::class, [], [], '', false);
872  $GLOBALS['BE_USER']->expects($this->at(0))->method('getTSConfig')->will($this->returnValue($completeConfiguration));
873  $GLOBALS['BE_USER']->expects($this->at(1))->method('getTSConfig')->will($this->returnValue(['value' => null, 'properties' => null]));
874 
875  $this->assertSame($completeConfiguration, BackendUtilityFixture::getModTSconfig(42, 'notrelevant'));
876  }
877 
884  {
885  return [
886  'same table: mergeIfNotBlank' => [
887  'foo',
888  [
889  'origUid' => 1,
890  'field2' => 'fdas',
891  'field3' => 'trans',
892  ],
893  [
894  'foo' => [
895  'ctrl' => [
896  'transOrigPointerTable' => '',
897  'transOrigPointerField' => 'origUid'
898  ],
899  'columns' => [
900  'field2' => ['l10n_mode' => 'mergeIfNotBlank'],
901  'field3' => ['l10n_mode' => 'mergeIfNotBlank']
902  ]
903  ]
904  ],
905  [
906  'origUid' => 0,
907  'field2' => 'basic',
908  'field3' => '',
909  ],
910  [
911  'origUid' => 1,
912  'field2' => 'fdas',
913  'field3' => 'trans',
914  ]
915  ],
916  'other table: mergeIfNotBlank' => [
917  'foo',
918  [
919  'origUid' => 1,
920  'field2' => '',
921  'field3' => 'trans',
922  ],
923  [
924  'foo' => [
925  'ctrl' => [
926  'transOrigPointerTable' => 'bar',
927  'transOrigPointerField' => 'origUid'
928  ]
929  ],
930  'bar' => [
931  'columns' => [
932  'field2' => ['l10n_mode' => 'mergeIfNotBlank'],
933  'field3' => ['l10n_mode' => 'mergeIfNotBlank']
934  ]
935  ]
936  ],
937  [
938  'origUid' => 0,
939  'field2' => 'basic',
940  'field3' => '',
941  ],
942  [
943  'origUid' => 1,
944  'field2' => 'basic',
945  'field3' => 'trans',
946  ]
947  ],
948  'same table: exclude' => [
949  'foo',
950  [
951  'origUid' => 1,
952  'field2' => 'fdas',
953  'field3' => 'trans',
954  ],
955  [
956  'foo' => [
957  'ctrl' => [
958  'transOrigPointerTable' => '',
959  'transOrigPointerField' => 'origUid'
960  ],
961  'columns' => [
962  'field2' => ['l10n_mode' => 'exclude'],
963  'field3' => ['l10n_mode' => 'exclude']
964  ]
965  ]
966  ],
967  [
968  'origUid' => 0,
969  'field2' => 'basic',
970  'field3' => '',
971  ],
972  [
973  'origUid' => 1,
974  'field2' => 'basic',
975  'field3' => '',
976  ]
977  ],
978  'other table: exclude' => [
979  'foo',
980  [
981  'origUid' => 1,
982  'field2' => 'fdas',
983  'field3' => 'trans',
984  ],
985  [
986  'foo' => [
987  'ctrl' => [
988  'transOrigPointerTable' => 'bar',
989  'transOrigPointerField' => 'origUid'
990  ]
991  ],
992  'bar' => [
993  'columns' => [
994  'field2' => ['l10n_mode' => 'exclude'],
995  'field3' => ['l10n_mode' => 'exclude']
996  ]
997  ]
998  ],
999  [
1000  'origUid' => 0,
1001  'field2' => 'basic',
1002  'field3' => '',
1003  ],
1004  [
1005  'origUid' => 1,
1006  'field2' => 'basic',
1007  'field3' => '',
1008  ]
1009  ],
1010  ];
1011  }
1012 
1026  public function replaceL10nModeFieldsReplacesFields($table, array $row, array $tca, array $originalRow, $expected)
1027  {
1028  $GLOBALS['TCA'] = $tca;
1029  $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection::class);
1030  $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->will($this->returnValue($originalRow));
1031 
1033  $subject = $this->getAccessibleMock(BackendUtility::class, ['dummy']);
1034  $this->assertSame($expected, $subject->_call('replaceL10nModeFields', $table, $row));
1035  }
1036 
1041  {
1042  $defaultExtras = 'nowrap:wizards[foo|bar]:anotherDefaultExtras:some[other|setting|with|parameters]';
1043  $expected = [
1044  'nowrap' => 1,
1045  'wizards' => [
1046  'parameters' => [
1047  0 => 'foo',
1048  1 => 'bar',
1049  ],
1050  ],
1051  'anotherDefaultExtras' => 1,
1052  'some' => [
1053  'parameters' => [
1054  0 => 'other',
1055  1 => 'setting',
1056  2 => 'with',
1057  3 => 'parameters',
1058  ],
1059  ],
1060  ];
1061  $this->assertEquals($expected, BackendUtility::getSpecConfParts($defaultExtras));
1062  }
1063 
1067  public function dateTimeAgeReturnsCorrectValues()
1068  {
1070  $languageServiceProphecy = $this->prophesize(LanguageService::class);
1071  $languageServiceProphecy->sL(Argument::cetera())->willReturn(' min| hrs| days| yrs| min| hour| day| year');
1072  $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
1073  $GLOBALS['EXEC_TIME'] = mktime(0, 0, 0, 3, 23, 2016);
1074 
1075  $this->assertSame('24-03-16 00:00 (-1 day)', BackendUtility::dateTimeAge($GLOBALS['EXEC_TIME'] + 86400));
1076  $this->assertSame('24-03-16 (-1 day)', BackendUtility::dateTimeAge($GLOBALS['EXEC_TIME'] + 86400, 1, 'date'));
1077  }
1078 
1080  // Tests concerning getTCAtypes
1082 
1087  {
1088  return [
1089  'no input' => [
1090  '', // table
1091  [], // rec
1092  '', // useFieldNameAsKey
1093  null // expected
1094  ],
1095  'non-existant table' => [
1096  'fooBar', // table
1097  [], // rec
1098  '', // useFieldNameAsKey
1099  null // expected
1100  ],
1101  'Doktype=1: one simple field' => [
1102  'pages',
1103  [
1104  'uid' => '1',
1105  'doktype' => '1'
1106  ],
1107  false,
1108  [
1109  0 => [
1110  'field' => 'title',
1111  'title' => null,
1112  'palette' => null,
1113  'spec' => [],
1114  'origString' => 'title'
1115  ]
1116  ]
1117  ],
1118  'non-existant type given: Return for type 1' => [
1119  'pages', // table
1120  [
1121  'uid' => '1',
1122  'doktype' => '999'
1123  ], // rec
1124  '', // useFieldNameAsKey
1125  [
1126  0 => [
1127  'field' => 'title',
1128  'title' => null,
1129  'palette' => null,
1130  'spec' => [],
1131  'origString' => 'title'
1132  ]
1133  ] // expected
1134  ],
1135  'Doktype=1: one simple field, useFieldNameAsKey=true' => [
1136  'pages',
1137  [
1138  'uid' => '1',
1139  'doktype' => '1'
1140  ],
1141  true,
1142  [
1143  'title' => [
1144  'field' => 'title',
1145  'title' => null,
1146  'palette' => null,
1147  'spec' => [],
1148  'origString' => 'title'
1149  ]
1150  ]
1151  ],
1152  'Empty showitem Field' => [
1153  'test',
1154  [
1155  'uid' => '1',
1156  'fooBar' => '99'
1157  ],
1158  true,
1159  [
1160  '' => [
1161  'field' => '',
1162  'title' => null,
1163  'palette' => null,
1164  'spec' => [],
1165  'origString' => ''
1166  ]
1167  ]
1168  ],
1169  'RTE field within a palette' => [
1170  'pages',
1171  [
1172  'uid' => '1',
1173  'doktype' => '10',
1174  ],
1175  false,
1176  [
1177  0 => [
1178  'field' => '--div--',
1179  'title' => 'General',
1180  'palette' => null,
1181  'spec' => [],
1182  'origString' => '--div--;General'
1183  ],
1184  1 => [
1185  'field' => '--palette--',
1186  'title' => 'Palette',
1187  'palette' => '123',
1188  'spec' => [],
1189  'origString' => '--palette--;Palette;123'
1190  ],
1191  2 => [
1192  'field' => 'title',
1193  'title' => null,
1194  'palette' => null,
1195  'spec' => [],
1196  'origString' => 'title'
1197  ],
1198  3 => [
1199  'field' => 'text',
1200  'title' => null,
1201  'palette' => null,
1202  'spec' => [
1203  'richtext' => 1,
1204  'rte_transform' => [
1205  'parameters' => [
1206  0 => 'mode=ts_css'
1207  ]
1208  ]
1209  ],
1210  'origString' => 'text'
1211  ],
1212  4 => [
1213  'field' => 'select',
1214  'title' => 'Select field',
1215  'palette' => null,
1216  'spec' => [],
1217  'origString' => 'select;Select field'
1218  ]
1219  ]
1220  ],
1221  'RTE field with more settings within a palette' => [
1222  'pages',
1223  [
1224  'uid' => 1,
1225  'doktype' => 2
1226  ],
1227  false,
1228  [
1229  0 => [
1230  'field' => '--div--',
1231  'title' => 'General',
1232  'palette' => null,
1233  'spec' => [],
1234  'origString' => '--div--;General'
1235  ],
1236  1 => [
1237  'field' => '--palette--',
1238  'title' => 'RTE palette',
1239  'palette' => '456',
1240  'spec' => [],
1241  'origString' => '--palette--;RTE palette;456'
1242  ],
1243  2 => [
1244  'field' => 'text2',
1245  'title' => null,
1246  'palette' => null,
1247  'spec' => [
1248  'richtext' => 1,
1249  'rte_transform' => [
1250  'parameters' => [
1251  0 => 'mode=fooBar,type=RTE'
1252  ]
1253  ]
1254  ],
1255  'origString' => 'text2'
1256  ]
1257  ]
1258  ]
1259  ];
1260  }
1261 
1271  public function getTCAtypesReturnsCorrectValues($table, $rec, $useFieldNameAsKey, $expected)
1272  {
1273  $GLOBALS['TCA'] = [
1274  'pages' => [
1275  'ctrl' => [
1276  'type' => 'doktype'
1277  ],
1278  'columns' => [
1279  'title' => [
1280  'label' => 'Title test',
1281  'config' => [
1282  'type' => 'input'
1283  ]
1284  ],
1285  'text' => [
1286  'label' => 'RTE Text',
1287  'config' => [
1288  'type' => 'text',
1289  'cols' => 40,
1290  'rows' => 5
1291  ],
1292  'defaultExtras' => 'richtext:rte_transform[mode=ts_css]'
1293  ],
1294  'text2' => [
1295  'label' => 'RTE Text 2',
1296  'config' => [
1297  'type' => 'text',
1298  'cols' => 40,
1299  'rows' => 5
1300  ],
1301  'defaultExtras' => 'richtext:rte_transform[mode=fooBar,type=RTE]'
1302  ],
1303  'select' => [
1304  'label' => 'Select test',
1305  'config' => [
1306  'items' => [
1307  ['Please select', 0],
1308  ['Option 1', 1],
1309  ['Option 2', 2]
1310  ]
1311  ],
1312  'maxitems' => 1,
1313  'renderType' => 'selectSingle'
1314  ]
1315  ],
1316  'types' => [
1317  '1' => [
1318  'showitem' => 'title'
1319  ],
1320  '2' => [
1321  'showitem' => '--div--;General,--palette--;RTE palette;456'
1322  ],
1323  '10' => [
1324  'showitem' => '--div--;General,--palette--;Palette;123,title'
1325  ],
1326  '14' => [
1327  'showitem' => '--div--;General,title'
1328  ]
1329  ],
1330  'palettes' => [
1331  '123' => [
1332  'showitem' => 'text,select;Select field'
1333  ],
1334  '456' => [
1335  'showitem' => 'text2'
1336  ]
1337  ]
1338  ],
1339  'test' => [
1340  'ctrl' => [
1341  'type' => 'fooBar'
1342  ],
1343  'types' => [
1344  '99' => [ 'showitem' => '']
1345  ]
1346  ]
1347  ];
1348 
1349  $return = BackendUtility::getTCAtypes($table, $rec, $useFieldNameAsKey);
1350  $this->assertSame($expected, $return);
1351  }
1352 }
static getFuncCheck($mainParams, $elementName, $currentValue, $script='', $addParams='', $tagParams='')
getLabelsFromItemsListReturnsCorrectValue($table, $col, $keyList, $tca, array $pageTsConfig, $expectedLabel)
getTCAtypesReturnsCorrectValues($table, $rec, $useFieldNameAsKey, $expected)
static getCommonSelectFields($table, $prefix='', $fields=[])
static getTCAtypes($table, $rec, $useFieldNameAsKey=false)
static calcAge($seconds, $labels=' min|hrs|days|yrs|min|hour|day|year')
getCommonSelectFieldsReturnsCorrectFields($table, $prefix='', array $presetFields, array $tca, $expectedFields='')
getLabelFromItemlistReturnsCorrectFields($table, $col='', $key='', array $tca, $expectedLabel='')
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
static viewOnClick($pageUid, $backPath='', $rootLine=null, $anchorSection='', $alternativeUrl='', $additionalGetVars='', $switchFocus=true)
static getLabelFromItemListMerged($pageId, $table, $column, $key)
static getSpecConfParts($defaultExtrasString, $_='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static dateTimeAge($tstamp, $prefix=1, $date='')
static getLabelFromItemlist($table, $col, $key)
static getLabelsFromItemsList($table, $column, $keyList, array $columnTsConfig=[])
getLabelFromItemListMergedReturnsCorrectFields($pageId, $table, $column='', $key='', array $tca, $expectedLabel='')