TYPO3 CMS  TYPO3_8-7
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 
34 
38 class BackendUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
39 {
41  // Tests concerning calcAge
43 
48  public function calcAgeDataProvider()
49  {
50  return [
51  'Single year' => [
52  'seconds' => 60 * 60 * 24 * 365,
53  'expectedLabel' => '1 year'
54  ],
55  'Plural years' => [
56  'seconds' => 60 * 60 * 24 * 365 * 2,
57  'expectedLabel' => '2 yrs'
58  ],
59  'Single negative year' => [
60  'seconds' => 60 * 60 * 24 * 365 * -1,
61  'expectedLabel' => '-1 year'
62  ],
63  'Plural negative years' => [
64  'seconds' => 60 * 60 * 24 * 365 * 2 * -1,
65  'expectedLabel' => '-2 yrs'
66  ],
67  'Single day' => [
68  'seconds' => 60 * 60 * 24,
69  'expectedLabel' => '1 day'
70  ],
71  'Plural days' => [
72  'seconds' => 60 * 60 * 24 * 2,
73  'expectedLabel' => '2 days'
74  ],
75  'Single negative day' => [
76  'seconds' => 60 * 60 * 24 * -1,
77  'expectedLabel' => '-1 day'
78  ],
79  'Plural negative days' => [
80  'seconds' => 60 * 60 * 24 * 2 * -1,
81  'expectedLabel' => '-2 days'
82  ],
83  'Single hour' => [
84  'seconds' => 60 * 60,
85  'expectedLabel' => '1 hour'
86  ],
87  'Plural hours' => [
88  'seconds' => 60 * 60 * 2,
89  'expectedLabel' => '2 hrs'
90  ],
91  'Single negative hour' => [
92  'seconds' => 60 * 60 * -1,
93  'expectedLabel' => '-1 hour'
94  ],
95  'Plural negative hours' => [
96  'seconds' => 60 * 60 * 2 * -1,
97  'expectedLabel' => '-2 hrs'
98  ],
99  'Single minute' => [
100  'seconds' => 60,
101  'expectedLabel' => '1 min'
102  ],
103  'Plural minutes' => [
104  'seconds' => 60 * 2,
105  'expectedLabel' => '2 min'
106  ],
107  'Single negative minute' => [
108  'seconds' => 60 * -1,
109  'expectedLabel' => '-1 min'
110  ],
111  'Plural negative minutes' => [
112  'seconds' => 60 * 2 * -1,
113  'expectedLabel' => '-2 min'
114  ],
115  'Zero seconds' => [
116  'seconds' => 0,
117  'expectedLabel' => '0 min'
118  ]
119  ];
120  }
121 
129  public function calcAgeReturnsExpectedValues($seconds, $expectedLabel)
130  {
131  $this->assertSame($expectedLabel, BackendUtility::calcAge($seconds));
132  }
133 
135  // Tests concerning getProcessedValue
137 
142  {
143  $GLOBALS['TCA'] = [
144  'tt_content' => [
145  'columns' => [
146  'header' => [
147  'config' => [
148  'type' => 'input',
149  ],
150  ],
151  ],
152  ],
153  ];
154  $this->assertEquals('0', BackendUtility::getProcessedValue('tt_content', 'header', '0'));
155  }
156 
160  public function getProcessedValueForGroup()
161  {
162  $GLOBALS['TCA'] = [
163  'tt_content' => [
164  'columns' => [
165  'multimedia' => [
166  'config' => [
167  'type' => 'group',
168  ],
169  ],
170  ],
171  ],
172  ];
173  $this->assertSame('1, 2', BackendUtility::getProcessedValue('tt_content', 'multimedia', '1,2'));
174  }
175 
180  {
181  $GLOBALS['TCA'] = [
182  'tt_content' => [
183  'columns' => [
184  'pages' => [
185  'config' => [
186  'type' => 'group',
187  'allowed' => 'pages',
188  'internal_type' => 'db',
189  'maxitems' => 22,
190  'minitems' => 0,
191  'size' => 3,
192  ],
193  ],
194  ],
195  ],
196  ];
197 
198  $this->assertSame('Page 1, Page 2', ProcessedValueForGroupWithOneAllowedTableFixture::getProcessedValue('tt_content', 'pages', '1,2'));
199  }
200 
205  {
206  $GLOBALS['TCA'] = [
207  'index_config' => [
208  'columns' => [
209  'indexcfgs' => [
210  'config' => [
211  'type' => 'group',
212  'internal_type' => 'db',
213  'allowed' => 'index_config,pages',
214  'size' => 5,
215  ],
216  ],
217  ],
218  ],
219  ];
220 
221  $this->assertSame('Page 1, Configuration 2', ProcessedValueForGroupWithMultipleAllowedTablesFixture::getProcessedValue('index_config', 'indexcfgs', 'pages_1,index_config_2'));
222  }
223 
231  protected function mockDatabaseConnection($tableName = 'sys_category')
232  {
233  $connectionProphet = $this->prophesize(Connection::class);
234  $connectionProphet->quote(Argument::cetera())->will(function ($arguments) {
235  return "'" . $arguments[0] . "'";
236  });
237  $connectionProphet->quoteIdentifier(Argument::cetera())->will(function ($arguments) {
238  return '`' . $arguments[0] . '`';
239  });
240 
241  $restrictionProphet = $this->prophesize(DefaultRestrictionContainer::class);
242  $restrictionProphet->removeAll()->willReturn($restrictionProphet->reveal());
243  $restrictionProphet->add(Argument::cetera())->willReturn($restrictionProphet->reveal());
244 
245  $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
246  $queryBuilderProphet->expr()->willReturn(
247  GeneralUtility::makeInstance(ExpressionBuilder::class, $connectionProphet->reveal())
248  );
249  $queryBuilderProphet->getRestrictions()->willReturn($restrictionProphet->reveal());
250  $queryBuilderProphet->quoteIdentifier(Argument::cetera())->will(function ($arguments) {
251  return '`' . $arguments[0] . '`';
252  });
253 
254  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
255  $connectionPoolProphet->getConnectionForTable($tableName)
256  ->willReturn($connectionProphet->reveal());
257  $connectionPoolProphet->getQueryBuilderForTable($tableName)
258  ->shouldBeCalled()
259  ->willReturn($queryBuilderProphet->reveal());
260 
261  return [$queryBuilderProphet, $connectionPoolProphet, $connectionProphet, $restrictionProphet];
262  }
263 
267  public function getProcessedValueForSelectWithMMRelation()
268  {
270  $relationHandlerProphet = $this->prophesize(RelationHandler::class);
271  $relationHandlerProphet->start(Argument::cetera())->shouldBeCalled();
272 
273  $relationHandlerInstance = $relationHandlerProphet->reveal();
274  $relationHandlerInstance->tableArray['sys_category'] = [1, 2];
275 
276  list($queryBuilderProphet, $connectionPoolProphet) = $this->mockDatabaseConnection('sys_category');
277  $statementProphet = $this->prophesize(\Doctrine\DBAL\Driver\Statement::class);
278  $statementProphet->fetch()->shouldBeCalled()->willReturn(
279  [
280  'uid' => 1,
281  'title' => 'Category 1',
282  ],
283  [
284  'uid' => 2,
285  'title' => 'Category 2',
286  ],
287  false
288  );
289 
291  $queryBuilderProphet->select('uid', 'sys_category.title')->willReturn($queryBuilderProphet->reveal());
292  $queryBuilderProphet->from('sys_category')->willReturn($queryBuilderProphet->reveal());
293  $queryBuilderProphet->where('`uid` IN (:dcValue1)')->willReturn($queryBuilderProphet->reveal());
294  $queryBuilderProphet->createNamedParameter([1, 2], Connection::PARAM_INT_ARRAY)->willReturn(':dcValue1');
295  $queryBuilderProphet->execute()->willReturn($statementProphet->reveal());
296 
297  GeneralUtility::addInstance(RelationHandler::class, $relationHandlerInstance);
298  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
299 
300  $GLOBALS['TCA'] = [
301  'pages' => [
302  'columns' => [
303  'categories' => [
304  'config' => [
305  'type' => 'select',
306  'foreign_table' => 'sys_category',
307  'MM' => 'sys_category_record_mm',
308  'MM_match_fields' => [
309  'fieldname' => 'categories',
310  'tablesnames' => 'pages',
311  ],
312  'MM_opposite_field' => 'items',
313  ],
314  ],
315  ],
316  ],
317  'sys_category' => [
318  'ctrl' => ['label' => 'title'],
319  'columns' => [
320  'items' => [
321  'config' => [
322  'type' => 'group',
323  'internal_type' => 'db',
324  'allowed' => '*',
325  'MM' => 'sys_category_record_mm',
326  'MM_oppositeUsage' => [],
327  ]
328  ]
329  ],
330  ],
331  ];
332 
333  $this->assertSame(
334  'Category 1; Category 2',
335  ProcessedValueForSelectWithMMRelationFixture::getProcessedValue(
336  'pages',
337  'categories',
338  '2',
339  0,
340  false,
341  false,
342  1
343  )
344  );
345  }
346 
350  public function getProcessedValueDisplaysAgeForDateInputFieldsIfSettingAbsent()
351  {
353  $languageServiceProphecy = $this->prophesize(LanguageService::class);
354  $languageServiceProphecy->sL(Argument::cetera())->willReturn(' min| hrs| days| yrs| min| hour| day| year');
355  $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
356 
357  $GLOBALS['EXEC_TIME'] = mktime(0, 0, 0, 8, 30, 2015);
358 
359  $GLOBALS['TCA'] = [
360  'tt_content' => [
361  'columns' => [
362  'date' => [
363  'config' => [
364  'type' => 'input',
365  'eval' => 'date',
366  ],
367  ],
368  ],
369  ],
370  ];
371  $this->assertSame('28-08-15 (-2 days)', BackendUtility::getProcessedValue('tt_content', 'date', mktime(0, 0, 0, 8, 28, 2015)));
372  }
373 
377  public function inputTypeDateDisplayOptions()
378  {
379  return [
380  'typeSafe Setting' => [
381  true,
382  '28-08-15',
383  ],
384  'non typesafe setting' => [
385  1,
386  '28-08-15',
387  ],
388  'setting disabled typesafe' => [
389  false,
390  '28-08-15 (-2 days)',
391  ],
392  'setting disabled not typesafe' => [
393  0,
394  '28-08-15 (-2 days)',
395  ],
396  ];
397  }
398 
407  public function getProcessedValueHandlesAgeDisplayCorrectly($input, $expected)
408  {
410  $languageServiceProphecy = $this->prophesize(LanguageService::class);
411  $languageServiceProphecy->sL(Argument::cetera())->willReturn(' min| hrs| days| yrs| min| hour| day| year');
412  $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
413 
414  $GLOBALS['EXEC_TIME'] = mktime(0, 0, 0, 8, 30, 2015);
415 
416  $GLOBALS['TCA'] = [
417  'tt_content' => [
418  'columns' => [
419  'date' => [
420  'config' => [
421  'type' => 'input',
422  'eval' => 'date',
423  'disableAgeDisplay' => $input,
424  ],
425  ],
426  ],
427  ],
428  ];
429  $this->assertSame($expected, BackendUtility::getProcessedValue('tt_content', 'date', mktime(0, 0, 0, 8, 28, 2015)));
430  }
431 
442  {
443  return [
444  'only uid' => [
445  'table' => 'test_table',
446  'prefix' => '',
447  'presetFields' => [],
448  'tca' => [],
449  'expectedFields' => 'uid'
450  ],
451  'label set' => [
452  'table' => 'test_table',
453  'prefix' => '',
454  'presetFields' => [],
455  'tca' => [
456  'ctrl' => [
457  'label' => 'label'
458  ]
459  ],
460  'expectedFields' => 'uid,label'
461  ],
462  'label_alt set' => [
463  'table' => 'test_table',
464  'prefix' => '',
465  'presetFields' => [],
466  'tca' => [
467  'ctrl' => [
468  'label_alt' => 'label,label2'
469  ]
470  ],
471  'expectedFields' => 'uid,label,label2'
472  ],
473  'versioningWS set' => [
474  'table' => 'test_table',
475  'prefix' => '',
476  'presetFields' => [],
477  'tca' => [
478  'ctrl' => [
479  'versioningWS' => true
480  ]
481  ],
482  'expectedFields' => 'uid,t3ver_id,t3ver_state,t3ver_wsid,t3ver_count'
483  ],
484  'selicon_field set' => [
485  'table' => 'test_table',
486  'prefix' => '',
487  'presetFields' => [],
488  'tca' => [
489  'ctrl' => [
490  'selicon_field' => 'field'
491  ]
492  ],
493  'expectedFields' => 'uid,field'
494  ],
495  'typeicon_column set' => [
496  'table' => 'test_table',
497  'prefix' => '',
498  'presetFields' => [],
499  'tca' => [
500  'ctrl' => [
501  'typeicon_column' => 'field'
502  ]
503  ],
504  'expectedFields' => 'uid,field'
505  ],
506  'enablecolumns set' => [
507  'table' => 'test_table',
508  'prefix' => '',
509  'presetFields' => [],
510  'tca' => [
511  'ctrl' => [
512  'enablecolumns' => [
513  'disabled' => 'hidden',
514  'starttime' => 'start',
515  'endtime' => 'stop',
516  'fe_group' => 'groups'
517  ]
518  ]
519  ],
520  'expectedFields' => 'uid,hidden,start,stop,groups'
521  ],
522  'label set to uid' => [
523  'table' => 'test_table',
524  'prefix' => '',
525  'presetFields' => [],
526  'tca' => [
527  'ctrl' => [
528  'label' => 'uid'
529  ]
530  ],
531  'expectedFields' => 'uid'
532  ]
533  ];
534  }
535 
546  public function getCommonSelectFieldsReturnsCorrectFields($table, $prefix = '', array $presetFields, array $tca, $expectedFields = '')
547  {
548  $GLOBALS['TCA'][$table] = $tca;
549  $selectFields = BackendUtility::getCommonSelectFields($table, $prefix, $presetFields);
550  $this->assertEquals($selectFields, $expectedFields);
551  }
552 
563  {
564  return [
565  'item set' => [
566  'table' => 'tt_content',
567  'col' => 'menu_type',
568  'key' => '1',
569  'tca' => [
570  'columns' => [
571  'menu_type' => [
572  'config' => [
573  'items' => [
574  ['Item 1', '0'],
575  ['Item 2', '1'],
576  ['Item 3', '3']
577  ]
578  ]
579  ]
580  ]
581  ],
582  'expectedLabel' => 'Item 2'
583  ],
584  'item set twice' => [
585  'table' => 'tt_content',
586  'col' => 'menu_type',
587  'key' => '1',
588  'tca' => [
589  'columns' => [
590  'menu_type' => [
591  'config' => [
592  'items' => [
593  ['Item 1', '0'],
594  ['Item 2a', '1'],
595  ['Item 2b', '1'],
596  ['Item 3', '3']
597  ]
598  ]
599  ]
600  ]
601  ],
602  'expectedLabel' => 'Item 2a'
603  ],
604  'item not found' => [
605  'table' => 'tt_content',
606  'col' => 'menu_type',
607  'key' => '5',
608  'tca' => [
609  'columns' => [
610  'menu_type' => [
611  'config' => [
612  'items' => [
613  ['Item 1', '0'],
614  ['Item 2', '1'],
615  ['Item 3', '2']
616  ]
617  ]
618  ]
619  ]
620  ],
621  'expectedLabel' => null
622  ]
623  ];
624  }
625 
636  public function getLabelFromItemlistReturnsCorrectFields($table, $col = '', $key = '', array $tca, $expectedLabel = '')
637  {
638  $GLOBALS['TCA'][$table] = $tca;
639  $label = BackendUtility::getLabelFromItemlist($table, $col, $key);
640  $this->assertEquals($label, $expectedLabel);
641  }
642 
653  {
654  return [
655  'no field found' => [
656  'pageId' => '123',
657  'table' => 'tt_content',
658  'col' => 'menu_type',
659  'key' => '10',
660  'tca' => [
661  'columns' => [
662  'menu_type' => [
663  'config' => [
664  'items' => [
665  ['Item 1', '0'],
666  ['Item 2', '1'],
667  ['Item 3', '3']
668  ]
669  ]
670  ]
671  ]
672  ],
673  'expectedLabel' => ''
674  ],
675  'no tsconfig set' => [
676  'pageId' => '123',
677  'table' => 'tt_content',
678  'col' => 'menu_type',
679  'key' => '1',
680  'tca' => [
681  'columns' => [
682  'menu_type' => [
683  'config' => [
684  'items' => [
685  ['Item 1', '0'],
686  ['Item 2', '1'],
687  ['Item 3', '3']
688  ]
689  ]
690  ]
691  ]
692  ],
693  'expectedLabel' => 'Item 2'
694  ]
695  ];
696  }
697 
709  public function getLabelFromItemListMergedReturnsCorrectFields($pageId, $table, $column = '', $key = '', array $tca, $expectedLabel = '')
710  {
711  $GLOBALS['TCA'][$table] = $tca;
712 
713  $this->assertEquals($expectedLabel, LabelFromItemListMergedReturnsCorrectFieldsFixture::getLabelFromItemListMerged($pageId, $table, $column, $key));
714  }
715 
724  {
725  $this->assertStringMatchesFormat('<input %Svalue="1"%S/>', BackendUtility::getFuncCheck('params', 'test', true));
726  }
727 
728  /*
729  * Tests concerning getLabelsFromItemsList
730  */
731 
736  {
737  return [
738  'return value if found' => [
739  'foobar', // table
740  'someColumn', // col
741  'foo, bar', // keyList
742  [ // TCA
743  'columns' => [
744  'someColumn' => [
745  'config' => [
746  'items' => [
747  '0' => ['aFooLabel', 'foo'],
748  '1' => ['aBarLabel', 'bar']
749  ]
750  ]
751  ]
752  ]
753  ],
754  [], // page TSconfig
755  'aFooLabel, aBarLabel' // expected
756  ],
757  'page TSconfig overrules TCA' => [
758  'foobar', // table
759  'someColumn', // col
760  'foo,bar, add', // keyList
761  [ // TCA
762  'columns' => [
763  'someColumn' => [
764  'config' => [
765  'items' => [
766  '0' => ['aFooLabel', 'foo'],
767  '1' => ['aBarLabel', 'bar']
768  ]
769  ]
770  ]
771  ]
772  ],
773  [ // page TSconfig
774  'addItems.' => ['add' => 'aNewLabel'],
775  'altLabels.' => ['bar' => 'aBarDiffLabel'],
776  ],
777  'aFooLabel, aBarDiffLabel, aNewLabel' // expected
778  ]
779  ];
780  }
781 
793  public function getLabelsFromItemsListReturnsCorrectValue($table, $col, $keyList, $tca, array $pageTsConfig, $expectedLabel)
794  {
795  // Stub LanguageService and let sL() return the same value that came in again
796  $GLOBALS['LANG'] = $this->createMock(LanguageService::class);
797  $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
798 
799  $GLOBALS['TCA'][$table] = $tca;
800  $label = BackendUtility::getLabelsFromItemsList($table, $col, $keyList, $pageTsConfig);
801  $this->assertEquals($expectedLabel, $label);
802  }
803 
808  {
809  $table = 'foobar';
810  $col = 'someColumn';
811  $tca = [
812  'columns' => [
813  'someColumn' => [
814  'config' => [
815  'type' => 'select',
816  'items' => [
817  '0' => ['aFooLabel', 'foo'],
818  '1' => ['aBarLabel', 'bar']
819  ]
820  ]
821  ]
822  ]
823  ];
824  // Stub LanguageService and let sL() return the same value that came in again
825  $GLOBALS['LANG'] = $this->createMock(LanguageService::class);
826  $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
827 
828  $GLOBALS['TCA'][$table] = $tca;
829  $label = BackendUtility::getProcessedValue($table, $col, 'foo,invalidKey,bar');
830  $this->assertEquals('aFooLabel, aBarLabel', $label);
831  }
832 
837  {
838  $table = 'foobar';
839  $col = 'someColumn';
840  $tca = [
841  'columns' => [
842  'someColumn' => [
843  'config' => [
844  'type' => 'select',
845  'items' => [
846  '0' => ['aFooLabel', 'foo']
847  ]
848  ]
849  ]
850  ]
851  ];
852  // Stub LanguageService and let sL() return the same value that came in again
853  $GLOBALS['LANG'] = $this->createMock(LanguageService::class);
854  $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
855 
856  $GLOBALS['TCA'][$table] = $tca;
857  $label = BackendUtility::getProcessedValue($table, $col, 'invalidKey');
858  $this->assertEquals('invalidKey', $label);
859  }
860 
869  {
870  // Make sure the hook inside viewOnClick is not fired. This may be removed if unit tests
871  // bootstrap does not initialize TYPO3_CONF_VARS anymore.
872  unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']);
873 
874  $alternativeUrl = 'https://typo3.org/about/typo3-the-cms/the-history-of-typo3/#section';
875  $onclickCode = 'var previewWin = window.open(' . GeneralUtility::quoteJSvalue($alternativeUrl) . ',\'newTYPO3frontendWindow\');';
876  $this->assertStringMatchesFormat(
877  $onclickCode,
878  BackendUtility::viewOnClick(null, null, null, null, $alternativeUrl, null, false)
879  );
880  }
881 
886  {
887  $completeConfiguration = [
888  'value' => 'bar',
889  'properties' => [
890  'permissions.' => [
891  'file.' => [
892  'default.' => ['readAction' => '1'],
893  '1.' => ['writeAction' => '1'],
894  '0.' => ['readAction' => '0'],
895  ],
896  ]
897  ]
898  ];
899 
900  $GLOBALS['BE_USER'] = $this->createMock(BackendUserAuthentication::class);
901  $GLOBALS['BE_USER']->expects($this->at(0))->method('getTSConfig')->will($this->returnValue($completeConfiguration));
902  $GLOBALS['BE_USER']->expects($this->at(1))->method('getTSConfig')->will($this->returnValue(['value' => null, 'properties' => null]));
903 
904  $this->assertSame($completeConfiguration, BackendUtilityFixture::getModTSconfig(42, 'notrelevant'));
905  }
906 
911  {
912  $defaultExtras = 'nowrap:wizards[foo|bar]:anotherDefaultExtras:some[other|setting|with|parameters]';
913  $expected = [
914  'nowrap' => 1,
915  'wizards' => [
916  'parameters' => [
917  0 => 'foo',
918  1 => 'bar',
919  ],
920  ],
921  'anotherDefaultExtras' => 1,
922  'some' => [
923  'parameters' => [
924  0 => 'other',
925  1 => 'setting',
926  2 => 'with',
927  3 => 'parameters',
928  ],
929  ],
930  ];
931  $this->assertEquals($expected, BackendUtility::getSpecConfParts($defaultExtras));
932  }
933 
937  public function dateTimeAgeReturnsCorrectValues()
938  {
940  $languageServiceProphecy = $this->prophesize(LanguageService::class);
941  $languageServiceProphecy->sL(Argument::cetera())->willReturn(' min| hrs| days| yrs| min| hour| day| year');
942  $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
943  $GLOBALS['EXEC_TIME'] = mktime(0, 0, 0, 3, 23, 2016);
944 
945  $this->assertSame('24-03-16 00:00 (-1 day)', BackendUtility::dateTimeAge($GLOBALS['EXEC_TIME'] + 86400));
946  $this->assertSame('24-03-16 (-1 day)', BackendUtility::dateTimeAge($GLOBALS['EXEC_TIME'] + 86400, 1, 'date'));
947  }
948 
950  // Tests concerning getTCAtypes
952 
957  {
958  return [
959  'no input' => [
960  '', // table
961  [], // rec
962  '', // useFieldNameAsKey
963  null // expected
964  ],
965  'non-existant table' => [
966  'fooBar', // table
967  [], // rec
968  '', // useFieldNameAsKey
969  null // expected
970  ],
971  'Doktype=1: one simple field' => [
972  'pages',
973  [
974  'uid' => '1',
975  'doktype' => '1'
976  ],
977  false,
978  [
979  0 => [
980  'field' => 'title',
981  'title' => null,
982  'palette' => null,
983  'spec' => [],
984  'origString' => 'title'
985  ]
986  ]
987  ],
988  'non-existant type given: Return for type 1' => [
989  'pages', // table
990  [
991  'uid' => '1',
992  'doktype' => '999'
993  ], // rec
994  '', // useFieldNameAsKey
995  [
996  0 => [
997  'field' => 'title',
998  'title' => null,
999  'palette' => null,
1000  'spec' => [],
1001  'origString' => 'title'
1002  ]
1003  ] // expected
1004  ],
1005  'Doktype=1: one simple field, useFieldNameAsKey=true' => [
1006  'pages',
1007  [
1008  'uid' => '1',
1009  'doktype' => '1'
1010  ],
1011  true,
1012  [
1013  'title' => [
1014  'field' => 'title',
1015  'title' => null,
1016  'palette' => null,
1017  'spec' => [],
1018  'origString' => 'title'
1019  ]
1020  ]
1021  ],
1022  'Empty showitem Field' => [
1023  'test',
1024  [
1025  'uid' => '1',
1026  'fooBar' => '99'
1027  ],
1028  true,
1029  [
1030  '' => [
1031  'field' => '',
1032  'title' => null,
1033  'palette' => null,
1034  'spec' => [],
1035  'origString' => ''
1036  ]
1037  ]
1038  ],
1039  'RTE field within a palette' => [
1040  'pages',
1041  [
1042  'uid' => '1',
1043  'doktype' => '10',
1044  ],
1045  false,
1046  [
1047  0 => [
1048  'field' => '--div--',
1049  'title' => 'General',
1050  'palette' => null,
1051  'spec' => [],
1052  'origString' => '--div--;General'
1053  ],
1054  1 => [
1055  'field' => '--palette--',
1056  'title' => 'Palette',
1057  'palette' => '123',
1058  'spec' => [],
1059  'origString' => '--palette--;Palette;123'
1060  ],
1061  2 => [
1062  'field' => 'title',
1063  'title' => null,
1064  'palette' => null,
1065  'spec' => [],
1066  'origString' => 'title'
1067  ],
1068  3 => [
1069  'field' => 'text',
1070  'title' => null,
1071  'palette' => null,
1072  'spec' => [],
1073  'origString' => 'text'
1074  ],
1075  4 => [
1076  'field' => 'select',
1077  'title' => 'Select field',
1078  'palette' => null,
1079  'spec' => [],
1080  'origString' => 'select;Select field'
1081  ]
1082  ]
1083  ],
1084  'RTE field with more settings within a palette' => [
1085  'pages',
1086  [
1087  'uid' => 1,
1088  'doktype' => 2
1089  ],
1090  false,
1091  [
1092  0 => [
1093  'field' => '--div--',
1094  'title' => 'General',
1095  'palette' => null,
1096  'spec' => [],
1097  'origString' => '--div--;General'
1098  ],
1099  1 => [
1100  'field' => '--palette--',
1101  'title' => 'RTE palette',
1102  'palette' => '456',
1103  'spec' => [],
1104  'origString' => '--palette--;RTE palette;456'
1105  ],
1106  2 => [
1107  'field' => 'text2',
1108  'title' => null,
1109  'palette' => null,
1110  'spec' => [],
1111  'origString' => 'text2'
1112  ]
1113  ]
1114  ]
1115  ];
1116  }
1117 
1127  public function getTCAtypesReturnsCorrectValues($table, $rec, $useFieldNameAsKey, $expected)
1128  {
1129  $GLOBALS['TCA'] = [
1130  'pages' => [
1131  'ctrl' => [
1132  'type' => 'doktype'
1133  ],
1134  'columns' => [
1135  'title' => [
1136  'label' => 'Title test',
1137  'config' => [
1138  'type' => 'input'
1139  ]
1140  ],
1141  'text' => [
1142  'label' => 'RTE Text',
1143  'config' => [
1144  'type' => 'text',
1145  'cols' => 40,
1146  'rows' => 5
1147  ],
1148  'defaultExtras' => 'richtext:rte_transform[mode=ts_css]'
1149  ],
1150  'text2' => [
1151  'label' => 'RTE Text 2',
1152  'config' => [
1153  'type' => 'text',
1154  'cols' => 40,
1155  'rows' => 5
1156  ],
1157  'defaultExtras' => 'richtext:rte_transform[mode=fooBar,type=RTE]'
1158  ],
1159  'select' => [
1160  'label' => 'Select test',
1161  'config' => [
1162  'items' => [
1163  ['Please select', 0],
1164  ['Option 1', 1],
1165  ['Option 2', 2]
1166  ]
1167  ],
1168  'maxitems' => 1,
1169  'renderType' => 'selectSingle'
1170  ]
1171  ],
1172  'types' => [
1173  '1' => [
1174  'showitem' => 'title'
1175  ],
1176  '2' => [
1177  'showitem' => '--div--;General,--palette--;RTE palette;456'
1178  ],
1179  '10' => [
1180  'showitem' => '--div--;General,--palette--;Palette;123,title'
1181  ],
1182  '14' => [
1183  'showitem' => '--div--;General,title'
1184  ]
1185  ],
1186  'palettes' => [
1187  '123' => [
1188  'showitem' => 'text,select;Select field'
1189  ],
1190  '456' => [
1191  'showitem' => 'text2'
1192  ]
1193  ]
1194  ],
1195  'test' => [
1196  'ctrl' => [
1197  'type' => 'fooBar'
1198  ],
1199  'types' => [
1200  '99' => [ 'showitem' => '']
1201  ]
1202  ]
1203  ];
1204 
1205  $return = BackendUtility::getTCAtypes($table, $rec, $useFieldNameAsKey);
1206  $this->assertSame($expected, $return);
1207  }
1208 
1213  {
1214  $propertyNames = [
1215  'uid',
1216  'pid',
1217  '_ORIG_PID'
1218  ];
1219  $computedPropertyNames = BackendUtility::purgeComputedPropertyNames($propertyNames);
1220  self::assertSame(['uid', 'pid'], $computedPropertyNames);
1221  }
1222 
1227  {
1228  $record = [
1229  'uid' => 1,
1230  'pid' => 2,
1231  '_ORIG_PID' => 1
1232  ];
1233  $expected = [
1234  'uid' => 1,
1235  'pid' => 2
1236  ];
1237  $computedProperties = BackendUtility::purgeComputedPropertiesFromRecord($record);
1238  self::assertSame($expected, $computedProperties);
1239  }
1240 }
getLabelsFromItemsListReturnsCorrectValue($table, $col, $keyList, $tca, array $pageTsConfig, $expectedLabel)
getTCAtypesReturnsCorrectValues($table, $rec, $useFieldNameAsKey, $expected)
static addInstance($className, $instance)
static getSpecConfParts($defaultExtrasString)
static viewOnClick( $pageUid, $backPath='', $rootLine=null, $anchorSection='', $alternativeUrl='', $additionalGetVars='', $switchFocus=true)
static calcAge($seconds, $labels='min|hrs|days|yrs|min|hour|day|year')
static getCommonSelectFields($table, $prefix='', $fields=[])
static purgeComputedPropertiesFromRecord(array $record)
static getTCAtypes($table, $rec, $useFieldNameAsKey=false)
static purgeComputedPropertyNames(array $propertyNames)
static makeInstance($className,... $constructorArguments)
getCommonSelectFieldsReturnsCorrectFields($table, $prefix='', array $presetFields, array $tca, $expectedFields='')
getLabelFromItemlistReturnsCorrectFields($table, $col='', $key='', array $tca, $expectedLabel='')
static getFuncCheck( $mainParams, $elementName, $currentValue, $script='', $addParams='', $tagParams='')
static getLabelFromItemListMerged($pageId, $table, $column, $key)
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='')