2 namespace TYPO3\CMS\Backend\Tests\Unit\Utility
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use Prophecy\Argument
;
18 use Prophecy\Prophecy\ObjectProphecy
;
19 use TYPO3\CMS\Backend\Utility\BackendUtility
;
20 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ProcessedValueForGroupWithOneAllowedTableFixture
;
21 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ProcessedValueForGroupWithMultipleAllowedTablesFixture
;
22 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ProcessedValueForSelectWithMMRelationFixture
;
23 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\LabelFromItemListMergedReturnsCorrectFieldsFixture
;
24 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ExcludeFieldsReturnsCorrectFieldListFixture
;
25 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ExcludeFieldsReturnsCorrectListWithFlexFormFieldsFixture
;
26 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication
;
27 use TYPO3\CMS\Core\Charset\CharsetConverter
;
28 use TYPO3\CMS\Core\Database\DatabaseConnection
;
29 use TYPO3\CMS\Core\Tests\UnitTestCase
;
30 use TYPO3\CMS\Core\Utility\GeneralUtility
;
31 use TYPO3\CMS\Lang\LanguageService
;
36 class BackendUtilityTest
extends UnitTestCase
{
38 ///////////////////////////////////////
39 // Tests concerning calcAge
40 ///////////////////////////////////////
42 * Data provider for calcAge function
46 public function calcAgeDataProvider() {
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'
121 * @dataProvider calcAgeDataProvider
123 * @param int $seconds
124 * @param string $expectedLabel
126 public function calcAgeReturnsExpectedValues($seconds, $expectedLabel) {
127 $this->assertSame($expectedLabel, BackendUtility
::calcAge($seconds));
130 ///////////////////////////////////////
131 // Tests concerning getProcessedValue
132 ///////////////////////////////////////
135 * @see http://forge.typo3.org/issues/20994
137 public function getProcessedValueForZeroStringIsZero() {
138 $GLOBALS['TCA'] = array(
139 'tt_content' => array(
149 $this->assertEquals('0', BackendUtility
::getProcessedValue('tt_content', 'header', '0'));
155 public function getProcessedValueForGroup() {
156 $GLOBALS['TCA'] = array(
157 'tt_content' => array(
159 'multimedia' => array(
167 $this->assertSame('1, 2', BackendUtility
::getProcessedValue('tt_content', 'multimedia', '1,2'));
173 public function getProcessedValueForGroupWithOneAllowedTable() {
174 $GLOBALS['TCA'] = array(
175 'tt_content' => array(
180 'allowed' => 'pages',
181 'internal_type' => 'db',
192 $this->assertSame('Page 1, Page 2', ProcessedValueForGroupWithOneAllowedTableFixture
::getProcessedValue('tt_content', 'pages', '1,2'));
198 public function getProcessedValueForGroupWithMultipleAllowedTables() {
199 $GLOBALS['TCA'] = array(
200 'index_config' => array(
202 'indexcfgs' => array(
205 'internal_type' => 'db',
206 'allowed' => 'index_config,pages',
214 $this->assertSame('Page 1, Configuration 2', ProcessedValueForGroupWithMultipleAllowedTablesFixture
::getProcessedValue('index_config', 'indexcfgs', 'pages_1,index_config_2'));
220 public function getProcessedValueForSelectWithMMRelation() {
221 $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection
::class, array(), array(), '', FALSE);
222 $GLOBALS['TYPO3_DB']->expects($this->any())->method('fullQuoteStr')
223 ->will($this->returnCallback(
224 function ($quoteStr) {
225 return "'" . $quoteStr . "'";
229 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTquery')->will($this->returnValue(0));
230 $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_free_result');
231 $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_fetch_assoc')
232 ->will($this->returnCallback(
237 // SELECT * FROM sys_category_record_mm
240 'uid_local' => 1, // uid of a sys_category record
241 'uid_foreign' => 1, // uid of a pages record
245 'uid_local' => 2, // uid of a sys_category record
246 'uid_foreign' => 1, // uid of a pages record
250 // SELECT * FROM sys_catgory
254 'title' => 'Category 1',
259 'title' => 'Category 2',
269 $GLOBALS['TCA'] = array(
272 'categories' => array(
275 'foreign_table' => 'sys_category',
276 'MM' => 'sys_category_record_mm',
277 'MM_match_fields' => array(
278 'fieldname' => 'categories',
279 'tablesnames' => 'pages',
281 'MM_opposite_field' => 'items',
286 'sys_category' => array(
291 'internal_type' => 'db',
293 'MM' => 'sys_category_record_mm',
294 'MM_oppositeUsage' => array(),
301 $this->assertSame('Category 1; Category 2', ProcessedValueForSelectWithMMRelationFixture
::getProcessedValue('pages', 'categories', '2', 0, FALSE, FALSE, 1));
307 public function getProcessedValueDisplaysAgeForDateInputFieldsIfSettingAbsent() {
308 /** @var ObjectProphecy $languageServiceProphecy */
309 $languageServiceProphecy = $this->prophesize(LanguageService
::class);
310 $languageServiceProphecy->sL(Argument
::cetera())->willReturn(' min| hrs| days| yrs| min| hour| day| year');
311 $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
313 $GLOBALS['EXEC_TIME'] = mktime(0, 0, 0, 8, 30, 2015);
327 $this->assertSame('28-08-15 (-2 days)', BackendUtility
::getProcessedValue('tt_content', 'date', mktime(0, 0, 0, 8, 28, 2015)));
333 public function inputTypeDateDisplayOptions() {
335 'typeSafe Setting' => [
339 'non typesafe setting' => [
343 'setting disabled typesafe' => [
345 '28-08-15 (-2 days)',
347 'setting disabled not typesafe' => [
349 '28-08-15 (-2 days)',
357 * @dataProvider inputTypeDateDisplayOptions
359 * @param string $input
360 * @param string $expected
362 public function getProcessedValueHandlesAgeDisplayCorrectly($input, $expected) {
363 /** @var ObjectProphecy $languageServiceProphecy */
364 $languageServiceProphecy = $this->prophesize(LanguageService
::class);
365 $languageServiceProphecy->sL(Argument
::cetera())->willReturn(' min| hrs| days| yrs| min| hour| day| year');
366 $GLOBALS['LANG'] = $languageServiceProphecy->reveal();
368 $GLOBALS['EXEC_TIME'] = mktime(0, 0, 0, 8, 30, 2015);
377 'disableAgeDisplay' => $input,
383 $this->assertSame($expected, BackendUtility
::getProcessedValue('tt_content', 'date', mktime(0, 0, 0, 8, 28, 2015)));
387 * Tests concerning getCommonSelectFields
391 * Data provider for getCommonSelectFieldsReturnsCorrectFields
393 * @return array The test data with $table, $prefix, $presetFields, $tca, $expectedFields
395 public function getCommonSelectFieldsReturnsCorrectFieldsDataProvider() {
398 'table' => 'test_table',
400 'presetFields' => array(),
402 'expectedFields' => 'uid'
404 'label set' => array(
405 'table' => 'test_table',
407 'presetFields' => array(),
413 'expectedFields' => 'uid,label'
415 'label_alt set' => array(
416 'table' => 'test_table',
418 'presetFields' => array(),
421 'label_alt' => 'label,label2'
424 'expectedFields' => 'uid,label,label2'
426 'versioningWS set' => array(
427 'table' => 'test_table',
429 'presetFields' => array(),
432 'versioningWS' => '2'
435 'expectedFields' => 'uid,t3ver_id,t3ver_state,t3ver_wsid,t3ver_count'
437 'selicon_field set' => array(
438 'table' => 'test_table',
440 'presetFields' => array(),
443 'selicon_field' => 'field'
446 'expectedFields' => 'uid,field'
448 'typeicon_column set' => array(
449 'table' => 'test_table',
451 'presetFields' => array(),
454 'typeicon_column' => 'field'
457 'expectedFields' => 'uid,field'
459 'enablecolumns set' => array(
460 'table' => 'test_table',
462 'presetFields' => array(),
465 'enablecolumns' => array(
466 'disabled' => 'hidden',
467 'starttime' => 'start',
469 'fe_group' => 'groups'
473 'expectedFields' => 'uid,hidden,start,stop,groups'
475 'label set to uid' => array(
476 'table' => 'test_table',
478 'presetFields' => array(),
484 'expectedFields' => 'uid'
491 * @dataProvider getCommonSelectFieldsReturnsCorrectFieldsDataProvider
493 * @param string $table
494 * @param string $prefix
495 * @param array $presetFields
497 * @param string $expectedFields
499 public function getCommonSelectFieldsReturnsCorrectFields($table, $prefix = '', array $presetFields, array $tca, $expectedFields = '') {
500 $GLOBALS['TCA'][$table] = $tca;
501 $selectFields = BackendUtility
::getCommonSelectFields($table, $prefix, $presetFields);
502 $this->assertEquals($selectFields, $expectedFields);
506 * Tests concerning getLabelFromItemlist
510 * Data provider for getLabelFromItemlistReturnsCorrectFields
512 * @return array The test data with $table, $col, $key, $expectedLabel
514 public function getLabelFromItemlistReturnsCorrectFieldsDataProvider() {
517 'table' => 'tt_content',
518 'col' => 'menu_type',
522 'menu_type' => array(
525 array('Item 1', '0'),
526 array('Item 2', '1'),
533 'expectedLabel' => 'Item 2'
535 'item set twice' => array(
536 'table' => 'tt_content',
537 'col' => 'menu_type',
541 'menu_type' => array(
544 array('Item 1', '0'),
545 array('Item 2a', '1'),
546 array('Item 2b', '1'),
553 'expectedLabel' => 'Item 2a'
555 'item not found' => array(
556 'table' => 'tt_content',
557 'col' => 'menu_type',
561 'menu_type' => array(
564 array('Item 1', '0'),
565 array('Item 2', '1'),
572 'expectedLabel' => NULL
579 * @dataProvider getLabelFromItemlistReturnsCorrectFieldsDataProvider
581 * @param string $table
585 * @param string $expectedLabel
587 public function getLabelFromItemlistReturnsCorrectFields($table, $col = '', $key = '', array $tca, $expectedLabel = '') {
588 $GLOBALS['TCA'][$table] = $tca;
589 $label = BackendUtility
::getLabelFromItemlist($table, $col, $key);
590 $this->assertEquals($label, $expectedLabel);
594 * Tests concerning getLabelFromItemListMerged
598 * Data provider for getLabelFromItemListMerged
600 * @return array The test data with $pageId, $table, $column, $key, $expectedLabel
602 public function getLabelFromItemListMergedReturnsCorrectFieldsDataProvider() {
604 'no field found' => array(
606 'table' => 'tt_content',
607 'col' => 'menu_type',
611 'menu_type' => array(
614 array('Item 1', '0'),
615 array('Item 2', '1'),
622 'expectedLabel' => ''
624 'no tsconfig set' => array(
626 'table' => 'tt_content',
627 'col' => 'menu_type',
631 'menu_type' => array(
634 array('Item 1', '0'),
635 array('Item 2', '1'),
642 'expectedLabel' => 'Item 2'
649 * @dataProvider getLabelFromItemListMergedReturnsCorrectFieldsDataProvider
652 * @param string $table
653 * @param string $column
656 * @param string $expectedLabel
658 public function getLabelFromItemListMergedReturnsCorrectFields($pageId, $table, $column = '', $key = '', array $tca, $expectedLabel = '') {
659 $GLOBALS['TCA'][$table] = $tca;
661 $this->assertEquals($expectedLabel, LabelFromItemListMergedReturnsCorrectFieldsFixture
::getLabelFromItemListMerged($pageId, $table, $column, $key));
665 * Tests concerning getFuncCheck
671 public function getFuncCheckReturnsInputTagWithValueAttribute() {
672 $this->assertStringMatchesFormat('<input %Svalue="1"%S/>', BackendUtility
::getFuncCheck('params', 'test', TRUE));
676 * Tests concerning getLabelsFromItemsList
682 public function getLabelsFromItemsListDataProvider() {
684 'return value if found' => array(
687 'foo, bar', // keyList
690 'someColumn' => array(
693 '0' => array('aFooLabel', 'foo'),
694 '1' => array('aBarLabel', 'bar')
700 array(), // page TSconfig
701 'aFooLabel, aBarLabel' // expected
703 'page TSconfig overrules TCA' => array(
706 'foo,bar, add', // keyList
709 'someColumn' => array(
712 '0' => array('aFooLabel', 'foo'),
713 '1' => array('aBarLabel', 'bar')
719 array( // page TSconfig
720 'addItems.' => array('add' => 'aNewLabel'),
721 'altLabels.' => array('bar' => 'aBarDiffLabel'),
723 'aFooLabel, aBarDiffLabel, aNewLabel' // expected
730 * @dataProvider getLabelsFromItemsListDataProvider
732 * @param string $table
734 * @param string $keyList
736 * @param array $pageTsConfig
737 * @param string $expectedLabel
739 public function getLabelsFromItemsListReturnsCorrectValue($table, $col, $keyList, $tca, array $pageTsConfig, $expectedLabel) {
740 // Stub LanguageService and let sL() return the same value that came in again
741 $GLOBALS['LANG'] = $this->getMock(LanguageService
::class, array(), array(), '', FALSE);
742 $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
744 $GLOBALS['TCA'][$table] = $tca;
745 $label = BackendUtility
::getLabelsFromItemsList($table, $col, $keyList, $pageTsConfig);
746 $this->assertEquals($expectedLabel, $label);
752 public function getProcessedValueReturnsLabelsForExistingValuesSolely() {
757 'someColumn' => array(
761 '0' => array('aFooLabel', 'foo'),
762 '1' => array('aBarLabel', 'bar')
768 // Stub LanguageService and let sL() return the same value that came in again
769 $GLOBALS['LANG'] = $this->getMock(LanguageService
::class, array(), array(), '', FALSE);
770 $GLOBALS['LANG']->charSet
= 'utf-8';
771 $GLOBALS['LANG']->csConvObj
= $this->getMock(CharsetConverter
::class);
772 $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
774 $GLOBALS['LANG']->csConvObj
->expects($this->any())->method('crop')->will($this->returnArgument(1));
776 $GLOBALS['TCA'][$table] = $tca;
777 $label = BackendUtility
::getProcessedValue($table, $col, 'foo,invalidKey,bar');
778 $this->assertEquals('aFooLabel, aBarLabel', $label);
784 public function getProcessedValueReturnsPlainValueIfItemIsNotFound() {
789 'someColumn' => array(
793 '0' => array('aFooLabel', 'foo')
799 // Stub LanguageService and let sL() return the same value that came in again
800 $GLOBALS['LANG'] = $this->getMock(LanguageService
::class, array(), array(), '', FALSE);
801 $GLOBALS['LANG']->charSet
= 'utf-8';
802 $GLOBALS['LANG']->csConvObj
= $this->getMock(CharsetConverter
::class);
803 $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
805 $GLOBALS['LANG']->csConvObj
->expects($this->any())->method('crop')->will($this->returnArgument(1));
807 $GLOBALS['TCA'][$table] = $tca;
808 $label = BackendUtility
::getProcessedValue($table, $col, 'invalidKey');
809 $this->assertEquals('invalidKey', $label);
813 * Tests concerning getExcludeFields
819 public function getExcludeFieldsDataProvider() {
821 'getExcludeFields does not return fields not configured as exclude field' => array(
845 'getExcludeFields returns fields from root level tables if root level restriction should be ignored' => array(
852 'ignoreRootLevelRestriction' => TRUE,
870 'getExcludeFields does not return fields from root level tables' => array(
887 'getExcludeFields does not return fields from admin only level tables' => array(
912 * @dataProvider getExcludeFieldsDataProvider
914 public function getExcludeFieldsReturnsCorrectFieldList($tca, $expected) {
915 $GLOBALS['TCA'] = $tca;
917 // Stub LanguageService and let sL() return the same value that came in again
918 $GLOBALS['LANG'] = $this->getMock(LanguageService
::class, array(), array(), '', FALSE);
919 $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
921 $this->assertSame($expected, ExcludeFieldsReturnsCorrectFieldListFixture
::getExcludeFields());
927 public function getExcludeFieldsReturnsCorrectListWithFlexFormFields() {
928 $GLOBALS['TCA'] = array(
943 'label' => 'abarfoo',
953 'tx_foobar' => array(
985 $expectedResult = array(
995 'abarfoo dummy: The Title:',
996 'tx_foo:abarfoo;dummy;sGeneral;xmlTitle'
1016 // Stub LanguageService and let sL() return the same value that came in again
1017 $GLOBALS['LANG'] = $this->getMock(LanguageService
::class, array(), array(), '', FALSE);
1018 $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
1020 $this->assertSame($expectedResult, ExcludeFieldsReturnsCorrectListWithFlexFormFieldsFixture
::getExcludeFields());
1024 * Tests concerning viewOnClick
1030 public function viewOnClickReturnsOnClickCodeWithAlternativeUrl() {
1031 // Make sure the hook inside viewOnClick is not fired. This may be removed if unit tests
1032 // bootstrap does not initialize TYPO3_CONF_VARS anymore.
1033 unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']);
1035 $alternativeUrl = 'https://typo3.org/about/typo3-the-cms/the-history-of-typo3/#section';
1036 $onclickCode = 'var previewWin = window.open(' . GeneralUtility
::quoteJSvalue($alternativeUrl) . ',\'newTYPO3frontendWindow\');';
1037 $this->assertStringMatchesFormat(
1039 BackendUtility
::viewOnClick(NULL, NULL, NULL, NULL, $alternativeUrl, NULL, FALSE)
1044 * Tests concerning replaceMarkersInWhereClause
1050 public function replaceMarkersInWhereClauseDataProvider() {
1052 'replaceMarkersInWhereClause replaces record field marker with quoted string' => array(
1053 ' AND dummytable.title=\'###REC_FIELD_dummyfield###\'',
1055 '_THIS_ROW' => array(
1056 'dummyfield' => 'Hello World'
1059 ' AND dummytable.title=\'Hello World\''
1061 'replaceMarkersInWhereClause replaces record field marker with fullquoted string' => array(
1062 ' AND dummytable.title=###REC_FIELD_dummyfield###',
1064 '_THIS_ROW' => array(
1065 'dummyfield' => 'Hello World'
1068 ' AND dummytable.title=\'Hello World\''
1070 'replaceMarkersInWhereClause replaces multiple record field markers' => array(
1071 ' AND dummytable.title=\'###REC_FIELD_dummyfield###\' AND dummytable.pid=###REC_FIELD_pid###',
1073 '_THIS_ROW' => array(
1074 'dummyfield' => 'Hello World',
1078 ' AND dummytable.title=\'Hello World\' AND dummytable.pid=\'42\''
1080 'replaceMarkersInWhereClause replaces current pid with integer' => array(
1081 ' AND dummytable.uid=###CURRENT_PID###',
1083 '_CURRENT_PID' => 42
1085 ' AND dummytable.uid=42'
1087 'replaceMarkersInWhereClause replaces current pid with string' => array(
1088 ' AND dummytable.uid=###CURRENT_PID###',
1090 '_CURRENT_PID' => '42string'
1092 ' AND dummytable.uid=42'
1094 'replaceMarkersInWhereClause replaces current record uid with integer' => array(
1095 ' AND dummytable.uid=###THIS_UID###',
1099 ' AND dummytable.uid=42'
1101 'replaceMarkersInWhereClause replaces current record uid with string' => array(
1102 ' AND dummytable.uid=###THIS_UID###',
1104 '_THIS_UID' => '42string'
1106 ' AND dummytable.uid=42'
1108 'replaceMarkersInWhereClause replaces storage pid with integer' => array(
1109 ' AND dummytable.uid=###STORAGE_PID###',
1111 '_STORAGE_PID' => 42
1113 ' AND dummytable.uid=42'
1115 'replaceMarkersInWhereClause replaces storage pid with string' => array(
1116 ' AND dummytable.uid=###STORAGE_PID###',
1118 '_STORAGE_PID' => '42string'
1120 ' AND dummytable.uid=42'
1122 'replaceMarkersInWhereClause replaces siteroot uid with integer' => array(
1123 ' AND dummytable.uid=###SITEROOT###',
1127 ' AND dummytable.uid=42'
1129 'replaceMarkersInWhereClause replaces siteroot uid with string' => array(
1130 ' AND dummytable.uid=###SITEROOT###',
1132 '_SITEROOT' => '42string'
1134 ' AND dummytable.uid=42'
1136 'replaceMarkersInWhereClause replaces page tsconfig id with integer' => array(
1137 ' AND dummytable.uid=###PAGE_TSCONFIG_ID###',
1139 'dummyfield' => array(
1140 'PAGE_TSCONFIG_ID' => 42
1143 ' AND dummytable.uid=42'
1145 'replaceMarkersInWhereClause replaces page tsconfig id with string' => array(
1146 ' AND dummytable.uid=###PAGE_TSCONFIG_ID###',
1148 'dummyfield' => array(
1149 'PAGE_TSCONFIG_ID' => '42string'
1152 ' AND dummytable.uid=42'
1154 'replaceMarkersInWhereClause replaces page tsconfig string' => array(
1155 ' AND dummytable.title=\'###PAGE_TSCONFIG_STR###\'',
1157 'dummyfield' => array(
1158 'PAGE_TSCONFIG_STR' => '42'
1161 ' AND dummytable.title=\'42\''
1163 'replaceMarkersInWhereClause replaces all markers' => array(
1164 ' AND dummytable.title=\'###REC_FIELD_dummyfield###\'' .
1165 ' AND dummytable.uid=###REC_FIELD_uid###' .
1166 ' AND dummytable.pid=###CURRENT_PID###' .
1167 ' AND dummytable.l18n_parent=###THIS_UID###' .
1168 ' AND dummytable.storage_pid=###STORAGE_PID###' .
1169 ' AND dummytable.siteroot=###SITEROOT###' .
1170 ' AND dummytable.config_uid=###PAGE_TSCONFIG_ID###' .
1171 ' AND dummytable.idlist IN (###PAGE_TSCONFIG_IDLIST###)' .
1172 ' AND dummytable.string=\'###PAGE_TSCONFIG_STR###\'',
1174 '_THIS_ROW' => array(
1175 'dummyfield' => 'Hello World',
1178 '_CURRENT_PID' => '1',
1180 '_STORAGE_PID' => 4,
1182 'dummyfield' => array(
1183 'PAGE_TSCONFIG_ID' => 6,
1184 'PAGE_TSCONFIG_IDLIST' => '1,2,3',
1185 'PAGE_TSCONFIG_STR' => 'string'
1188 ' AND dummytable.title=\'Hello World\' AND dummytable.uid=\'42\' AND dummytable.pid=1' .
1189 ' AND dummytable.l18n_parent=2 AND dummytable.storage_pid=4' .
1190 ' AND dummytable.siteroot=5 AND dummytable.config_uid=6 AND dummytable.idlist IN (1,2,3)' .
1191 ' AND dummytable.string=\'string\'',
1198 * @dataProvider replaceMarkersInWhereClauseDataProvider
1200 * @param string $whereClause
1201 * @param array $tsConfig
1202 * @param string $expected
1204 * @throws \PHPUnit_Framework_Exception
1206 public function replaceMarkersInWhereClauseReturnsValidWhereClause($whereClause, array $tsConfig, $expected) {
1207 // Mock TYPO3_DB and let it return same values that came in
1208 $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection
::class, array(), array(), '', FALSE);
1209 $GLOBALS['TYPO3_DB']->expects($this->any())->method('quoteStr')->will($this->returnArgument(0));
1210 $GLOBALS['TYPO3_DB']->expects($this->any())->method('fullQuoteStr')
1211 ->will($this->returnCallback(
1212 function ($quoteStr) {
1213 return "'" . $quoteStr . "'";
1217 $GLOBALS['TYPO3_DB']->expects($this->any())->method('cleanIntList')->will($this->returnArgument(0));
1218 $this->assertSame($expected, BackendUtility
::replaceMarkersInWhereClause($whereClause, 'dummytable', 'dummyfield', $tsConfig));
1224 public function replaceMarkersInWhereClauseCleansIdList() {
1225 $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection
::class, array(), array(), '', FALSE);
1226 $GLOBALS['TYPO3_DB']->expects($this->once())->method('cleanIntList')->with('1,a,2,b,3,c');
1227 $where = ' AND dummytable.uid IN (###PAGE_TSCONFIG_IDLIST###)';
1229 'dummyfield' => array(
1230 'PAGE_TSCONFIG_IDLIST' => '1,a,2,b,3,c'
1233 BackendUtility
::replaceMarkersInWhereClause($where, 'dummytable', 'dummyfield', $tsConfig);
1239 public function getModTSconfigIgnoresValuesFromUserTsConfigIfNoSet() {
1240 $completeConfiguration = array(
1242 'properties' => array(
1243 'permissions.' => array(
1245 'default.' => array('readAction' => '1'),
1246 '1.' => array('writeAction' => '1'),
1247 '0.' => array('readAction' => '0'),
1253 $GLOBALS['BE_USER'] = $this->getMock(BackendUserAuthentication
::class, array(), array(), '', FALSE);
1254 $GLOBALS['BE_USER']->expects($this->at(0))->method('getTSConfig')->will($this->returnValue($completeConfiguration));
1255 $GLOBALS['BE_USER']->expects($this->at(1))->method('getTSConfig')->will($this->returnValue(array('value' => NULL, 'properties' => NULL)));
1257 $className = $this->getUniqueId('BackendUtility');
1258 /** @var \PHPUnit_Framework_MockObject_MockObject|BackendUtility $subject */
1259 $subject = __NAMESPACE__
. '\\' . $className;
1261 'namespace ' . __NAMESPACE__
. ';' .
1262 'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
1263 ' static public function getPagesTSconfig($id, $rootLine = NULL, $returnPartArray = false) {' .
1264 ' return array();' .
1269 $this->assertSame($completeConfiguration, $subject::getModTSconfig(42, 'notrelevant'));
1273 * Data provider for replaceL10nModeFieldsReplacesFields
1277 public function replaceL10nModeFieldsReplacesFieldsDataProvider() {
1279 'same table: mergeIfNotBlank' => array(
1284 'field3' => 'trans',
1289 'transOrigPointerTable' => '',
1290 'transOrigPointerField' => 'origUid'
1293 'field2' => array('l10n_mode' => 'mergeIfNotBlank'),
1294 'field3' => array('l10n_mode' => 'mergeIfNotBlank')
1300 'field2' => 'basic',
1306 'field3' => 'trans',
1309 'other table: mergeIfNotBlank' => array(
1314 'field3' => 'trans',
1319 'transOrigPointerTable' => 'bar',
1320 'transOrigPointerField' => 'origUid'
1325 'field2' => array('l10n_mode' => 'mergeIfNotBlank'),
1326 'field3' => array('l10n_mode' => 'mergeIfNotBlank')
1332 'field2' => 'basic',
1337 'field2' => 'basic',
1338 'field3' => 'trans',
1341 'same table: exclude' => array(
1346 'field3' => 'trans',
1351 'transOrigPointerTable' => '',
1352 'transOrigPointerField' => 'origUid'
1355 'field2' => array('l10n_mode' => 'exclude'),
1356 'field3' => array('l10n_mode' => 'exclude')
1362 'field2' => 'basic',
1367 'field2' => 'basic',
1371 'other table: exclude' => array(
1376 'field3' => 'trans',
1381 'transOrigPointerTable' => 'bar',
1382 'transOrigPointerField' => 'origUid'
1387 'field2' => array('l10n_mode' => 'exclude'),
1388 'field3' => array('l10n_mode' => 'exclude')
1394 'field2' => 'basic',
1399 'field2' => 'basic',
1408 * @dataProvider replaceL10nModeFieldsReplacesFieldsDataProvider
1410 * @param string $table
1413 * @param array $originalRow
1414 * @param array $expected
1416 * @throws \InvalidArgumentException
1417 * @throws \PHPUnit_Framework_Exception
1419 public function replaceL10nModeFieldsReplacesFields($table, array $row, array $tca, array $originalRow, $expected) {
1420 $GLOBALS['TCA'] = $tca;
1421 $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection
::class);
1422 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->will($this->returnValue($originalRow));
1424 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|BackendUtility $subject */
1425 $subject = $this->getAccessibleMock(BackendUtility
::class, array('dummy'));
1426 $this->assertSame($expected, $subject->_call('replaceL10nModeFields', $table, $row));
1432 public function getSpecConfPartsSplitsDefaultExtras() {
1433 $defaultExtras = 'nowrap:wizards[foo|bar]:anotherDefaultExtras:some[other|setting|with|parameters]';
1437 'parameters' => array(
1442 'anotherDefaultExtras' => 1,
1444 'parameters' => array(
1452 $this->assertEquals($expected, BackendUtility
::getSpecConfParts($defaultExtras));