2 namespace TYPO3\CMS\Backend\Tests\Unit\Utility;
17 use Prophecy\Argument;
18 use Prophecy\Prophecy\ObjectProphecy;
28 use TYPO3\CMS\Core\Tests\UnitTestCase;
48 'Single year' => array(
49 'seconds' => 60 * 60 * 24 * 365,
50 'expectedLabel' =>
'1 year'
52 'Plural years' => array(
53 'seconds' => 60 * 60 * 24 * 365 * 2,
54 'expectedLabel' =>
'2 yrs'
56 'Single negative year' => array(
57 'seconds' => 60 * 60 * 24 * 365 * -1,
58 'expectedLabel' =>
'-1 year'
60 'Plural negative years' => array(
61 'seconds' => 60 * 60 * 24 * 365 * 2 * -1,
62 'expectedLabel' =>
'-2 yrs'
64 'Single day' => array(
65 'seconds' => 60 * 60 * 24,
66 'expectedLabel' =>
'1 day'
68 'Plural days' => array(
69 'seconds' => 60 * 60 * 24 * 2,
70 'expectedLabel' =>
'2 days'
72 'Single negative day' => array(
73 'seconds' => 60 * 60 * 24 * -1,
74 'expectedLabel' =>
'-1 day'
76 'Plural negative days' => array(
77 'seconds' => 60 * 60 * 24 * 2 * -1,
78 'expectedLabel' =>
'-2 days'
80 'Single hour' => array(
82 'expectedLabel' =>
'1 hour'
84 'Plural hours' => array(
85 'seconds' => 60 * 60 * 2,
86 'expectedLabel' =>
'2 hrs'
88 'Single negative hour' => array(
89 'seconds' => 60 * 60 * -1,
90 'expectedLabel' =>
'-1 hour'
92 'Plural negative hours' => array(
93 'seconds' => 60 * 60 * 2 * -1,
94 'expectedLabel' =>
'-2 hrs'
96 'Single minute' => array(
98 'expectedLabel' =>
'1 min'
100 'Plural minutes' => array(
102 'expectedLabel' =>
'2 min'
104 'Single negative minute' => array(
105 'seconds' => 60 * -1,
106 'expectedLabel' =>
'-1 min'
108 'Plural negative minutes' => array(
109 'seconds' => 60 * 2 * -1,
110 'expectedLabel' =>
'-2 min'
112 'Zero seconds' => array(
114 'expectedLabel' =>
'0 min'
141 'tt_content' => array(
151 $this->assertEquals(
'0', BackendUtility::getProcessedValue(
'tt_content',
'header',
'0'));
160 'tt_content' => array(
162 'multimedia' => array(
170 $this->assertSame(
'1, 2', BackendUtility::getProcessedValue(
'tt_content',
'multimedia',
'1,2'));
179 'tt_content' => array(
184 'allowed' =>
'pages',
185 'internal_type' =>
'db',
196 $this->assertSame(
'Page 1, Page 2', ProcessedValueForGroupWithOneAllowedTableFixture::getProcessedValue(
'tt_content',
'pages',
'1,2'));
205 'index_config' => array(
207 'indexcfgs' => array(
210 'internal_type' =>
'db',
211 'allowed' =>
'index_config,pages',
219 $this->assertSame(
'Page 1, Configuration 2', ProcessedValueForGroupWithMultipleAllowedTablesFixture::getProcessedValue(
'index_config',
'indexcfgs',
'pages_1,index_config_2'));
227 $GLOBALS[
'TYPO3_DB'] = $this->getMock(DatabaseConnection::class, array(), array(),
'',
false);
228 $GLOBALS[
'TYPO3_DB']->expects($this->any())->method(
'fullQuoteStr')
229 ->will($this->returnCallback(
230 function ($quoteStr) {
231 return "'" . $quoteStr .
"'";
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(
260 'title' =>
'Category 1',
265 'title' =>
'Category 2',
278 'categories' => array(
281 'foreign_table' =>
'sys_category',
282 'MM' =>
'sys_category_record_mm',
283 'MM_match_fields' => array(
284 'fieldname' =>
'categories',
285 'tablesnames' =>
'pages',
287 'MM_opposite_field' =>
'items',
292 'sys_category' => array(
297 'internal_type' =>
'db',
299 'MM' =>
'sys_category_record_mm',
300 'MM_oppositeUsage' => array(),
307 $this->assertSame(
'Category 1; Category 2', ProcessedValueForSelectWithMMRelationFixture::getProcessedValue(
'pages',
'categories',
'2', 0,
false,
false, 1));
313 public function getProcessedValueDisplaysAgeForDateInputFieldsIfSettingAbsent()
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();
320 $GLOBALS[
'EXEC_TIME'] = mktime(0, 0, 0, 8, 30, 2015);
334 $this->assertSame(
'28-08-15 (-2 days)', BackendUtility::getProcessedValue(
'tt_content',
'date', mktime(0, 0, 0, 8, 28, 2015)));
343 'typeSafe Setting' => [
347 'non typesafe setting' => [
351 'setting disabled typesafe' => [
353 '28-08-15 (-2 days)',
355 'setting disabled not typesafe' => [
357 '28-08-15 (-2 days)',
370 public function getProcessedValueHandlesAgeDisplayCorrectly($input, $expected)
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();
377 $GLOBALS[
'EXEC_TIME'] = mktime(0, 0, 0, 8, 30, 2015);
386 'disableAgeDisplay' => $input,
392 $this->assertSame($expected, BackendUtility::getProcessedValue(
'tt_content',
'date', mktime(0, 0, 0, 8, 28, 2015)));
408 'table' =>
'test_table',
410 'presetFields' => array(),
412 'expectedFields' =>
'uid'
414 'label set' => array(
415 'table' =>
'test_table',
417 'presetFields' => array(),
423 'expectedFields' =>
'uid,label'
425 'label_alt set' => array(
426 'table' =>
'test_table',
428 'presetFields' => array(),
431 'label_alt' =>
'label,label2'
434 'expectedFields' =>
'uid,label,label2'
436 'versioningWS set' => array(
437 'table' =>
'test_table',
439 'presetFields' => array(),
442 'versioningWS' =>
true
445 'expectedFields' =>
'uid,t3ver_id,t3ver_state,t3ver_wsid,t3ver_count'
447 'selicon_field set' => array(
448 'table' =>
'test_table',
450 'presetFields' => array(),
453 'selicon_field' =>
'field'
456 'expectedFields' =>
'uid,field'
458 'typeicon_column set' => array(
459 'table' =>
'test_table',
461 'presetFields' => array(),
464 'typeicon_column' =>
'field'
467 'expectedFields' =>
'uid,field'
469 'enablecolumns set' => array(
470 'table' =>
'test_table',
472 'presetFields' => array(),
475 'enablecolumns' => array(
476 'disabled' =>
'hidden',
477 'starttime' =>
'start',
479 'fe_group' =>
'groups'
483 'expectedFields' =>
'uid,hidden,start,stop,groups'
485 'label set to uid' => array(
486 'table' =>
'test_table',
488 'presetFields' => array(),
494 'expectedFields' =>
'uid'
513 $this->assertEquals($selectFields, $expectedFields);
529 'table' =>
'tt_content',
530 'col' =>
'menu_type',
534 'menu_type' => array(
537 array(
'Item 1',
'0'),
538 array(
'Item 2',
'1'),
545 'expectedLabel' =>
'Item 2'
547 'item set twice' => array(
548 'table' =>
'tt_content',
549 'col' =>
'menu_type',
553 'menu_type' => array(
556 array(
'Item 1',
'0'),
557 array(
'Item 2a',
'1'),
558 array(
'Item 2b',
'1'),
565 'expectedLabel' =>
'Item 2a'
567 'item not found' => array(
568 'table' =>
'tt_content',
569 'col' =>
'menu_type',
573 'menu_type' => array(
576 array(
'Item 1',
'0'),
577 array(
'Item 2',
'1'),
584 'expectedLabel' => null
603 $this->assertEquals($label, $expectedLabel);
618 'no field found' => array(
620 'table' =>
'tt_content',
621 'col' =>
'menu_type',
625 'menu_type' => array(
628 array(
'Item 1',
'0'),
629 array(
'Item 2',
'1'),
636 'expectedLabel' =>
''
638 'no tsconfig set' => array(
640 'table' =>
'tt_content',
641 'col' =>
'menu_type',
645 'menu_type' => array(
648 array(
'Item 1',
'0'),
649 array(
'Item 2',
'1'),
656 'expectedLabel' =>
'Item 2'
701 'return value if found' => array(
707 'someColumn' => array(
710 '0' => array(
'aFooLabel',
'foo'),
711 '1' => array(
'aBarLabel',
'bar')
718 'aFooLabel, aBarLabel'
720 'page TSconfig overrules TCA' => array(
726 'someColumn' => array(
729 '0' => array(
'aFooLabel',
'foo'),
730 '1' => array(
'aBarLabel',
'bar')
737 'addItems.' => array(
'add' =>
'aNewLabel'),
738 'altLabels.' => array(
'bar' =>
'aBarDiffLabel'),
740 'aFooLabel, aBarDiffLabel, aNewLabel'
759 $GLOBALS[
'LANG'] = $this->getMock(LanguageService::class, array(), array(),
'',
false);
760 $GLOBALS[
'LANG']->expects($this->any())->method(
'sL')->will($this->returnArgument(0));
764 $this->assertEquals($expectedLabel, $label);
776 'someColumn' => array(
780 '0' => array(
'aFooLabel',
'foo'),
781 '1' => array(
'aBarLabel',
'bar')
788 $GLOBALS[
'LANG'] = $this->getMock(LanguageService::class, array(), array(),
'',
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));
793 $GLOBALS[
'LANG']->csConvObj->expects($this->any())->method(
'crop')->will($this->returnArgument(1));
796 $label = BackendUtility::getProcessedValue($table, $col,
'foo,invalidKey,bar');
797 $this->assertEquals(
'aFooLabel, aBarLabel', $label);
809 'someColumn' => array(
813 '0' => array(
'aFooLabel',
'foo')
820 $GLOBALS[
'LANG'] = $this->getMock(LanguageService::class, array(), array(),
'',
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));
825 $GLOBALS[
'LANG']->csConvObj->expects($this->any())->method(
'crop')->will($this->returnArgument(1));
828 $label = BackendUtility::getProcessedValue($table, $col,
'invalidKey');
829 $this->assertEquals(
'invalidKey', $label);
843 unset(
$GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
't3lib/class.t3lib_befunc.php'][
'viewOnClickClass']);
845 $alternativeUrl =
'https://typo3.org/about/typo3-the-cms/the-history-of-typo3/#section';
847 $this->assertStringMatchesFormat(
858 $completeConfiguration = array(
860 'properties' => array(
861 'permissions.' => array(
863 'default.' => array(
'readAction' =>
'1'),
864 '1.' => array(
'writeAction' =>
'1'),
865 '0.' => array(
'readAction' =>
'0'),
871 $GLOBALS[
'BE_USER'] = $this->getMock(BackendUserAuthentication::class, array(), array(),
'',
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(array(
'value' => null,
'properties' => null)));
886 'same table: mergeIfNotBlank' => array(
896 'transOrigPointerTable' =>
'',
897 'transOrigPointerField' =>
'origUid'
900 'field2' => array(
'l10n_mode' =>
'mergeIfNotBlank'),
901 'field3' => array(
'l10n_mode' =>
'mergeIfNotBlank')
916 'other table: mergeIfNotBlank' => array(
926 'transOrigPointerTable' =>
'bar',
927 'transOrigPointerField' =>
'origUid'
932 'field2' => array(
'l10n_mode' =>
'mergeIfNotBlank'),
933 'field3' => array(
'l10n_mode' =>
'mergeIfNotBlank')
948 'same table: exclude' => array(
958 'transOrigPointerTable' =>
'',
959 'transOrigPointerField' =>
'origUid'
962 'field2' => array(
'l10n_mode' =>
'exclude'),
963 'field3' => array(
'l10n_mode' =>
'exclude')
978 'other table: exclude' => array(
988 'transOrigPointerTable' =>
'bar',
989 'transOrigPointerField' =>
'origUid'
994 'field2' => array(
'l10n_mode' =>
'exclude'),
995 'field3' => array(
'l10n_mode' =>
'exclude')
1001 'field2' =>
'basic',
1006 'field2' =>
'basic',
1026 public function replaceL10nModeFieldsReplacesFields($table, array $row, array
$tca, array $originalRow, $expected)
1029 $GLOBALS[
'TYPO3_DB'] = $this->getMock(DatabaseConnection::class);
1030 $GLOBALS[
'TYPO3_DB']->expects($this->any())->method(
'exec_SELECTgetSingleRow')->will($this->returnValue($originalRow));
1033 $subject = $this->getAccessibleMock(BackendUtility::class, array(
'dummy'));
1034 $this->assertSame($expected, $subject->_call(
'replaceL10nModeFields', $table, $row));
1042 $defaultExtras =
'nowrap:wizards[foo|bar]:anotherDefaultExtras:some[other|setting|with|parameters]';
1046 'parameters' => array(
1051 'anotherDefaultExtras' => 1,
1053 'parameters' => array(