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 TYPO3\CMS\Backend\Utility\BackendUtility
;
18 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ProcessedValueForGroupWithOneAllowedTableFixture
;
19 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ProcessedValueForGroupWithMultipleAllowedTablesFixture
;
20 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ProcessedValueForSelectWithMMRelationFixture
;
21 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\LabelFromItemListMergedReturnsCorrectFieldsFixture
;
22 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ExcludeFieldsReturnsCorrectFieldListFixture
;
23 use TYPO3\CMS\Backend\Tests\Unit\Utility\Fixtures\ExcludeFieldsReturnsCorrectListWithFlexFormFieldsFixture
;
24 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication
;
25 use TYPO3\CMS\Core\Charset\CharsetConverter
;
26 use TYPO3\CMS\Core\Database\DatabaseConnection
;
27 use TYPO3\CMS\Core\Tests\UnitTestCase
;
28 use TYPO3\CMS\Core\Utility\GeneralUtility
;
29 use TYPO3\CMS\Lang\LanguageService
;
34 class BackendUtilityTest
extends UnitTestCase
{
36 ///////////////////////////////////////
37 // Tests concerning calcAge
38 ///////////////////////////////////////
40 * Data provider for calcAge function
44 public function calcAgeDataProvider() {
46 'Single year' => array(
47 'seconds' => 60 * 60 * 24 * 365,
48 'expectedLabel' => '1 year'
50 'Plural years' => array(
51 'seconds' => 60 * 60 * 24 * 365 * 2,
52 'expectedLabel' => '2 yrs'
54 'Single negative year' => array(
55 'seconds' => 60 * 60 * 24 * 365 * -1,
56 'expectedLabel' => '-1 year'
58 'Plural negative years' => array(
59 'seconds' => 60 * 60 * 24 * 365 * 2 * -1,
60 'expectedLabel' => '-2 yrs'
62 'Single day' => array(
63 'seconds' => 60 * 60 * 24,
64 'expectedLabel' => '1 day'
66 'Plural days' => array(
67 'seconds' => 60 * 60 * 24 * 2,
68 'expectedLabel' => '2 days'
70 'Single negative day' => array(
71 'seconds' => 60 * 60 * 24 * -1,
72 'expectedLabel' => '-1 day'
74 'Plural negative days' => array(
75 'seconds' => 60 * 60 * 24 * 2 * -1,
76 'expectedLabel' => '-2 days'
78 'Single hour' => array(
80 'expectedLabel' => '1 hour'
82 'Plural hours' => array(
83 'seconds' => 60 * 60 * 2,
84 'expectedLabel' => '2 hrs'
86 'Single negative hour' => array(
87 'seconds' => 60 * 60 * -1,
88 'expectedLabel' => '-1 hour'
90 'Plural negative hours' => array(
91 'seconds' => 60 * 60 * 2 * -1,
92 'expectedLabel' => '-2 hrs'
94 'Single minute' => array(
96 'expectedLabel' => '1 min'
98 'Plural minutes' => array(
100 'expectedLabel' => '2 min'
102 'Single negative minute' => array(
103 'seconds' => 60 * -1,
104 'expectedLabel' => '-1 min'
106 'Plural negative minutes' => array(
107 'seconds' => 60 * 2 * -1,
108 'expectedLabel' => '-2 min'
110 'Zero seconds' => array(
112 'expectedLabel' => '0 min'
119 * @dataProvider calcAgeDataProvider
120 * @param int $seconds
121 * @param string $expectedLabel
123 public function calcAgeReturnsExpectedValues($seconds, $expectedLabel) {
124 $this->assertSame($expectedLabel, BackendUtility
::calcAge($seconds));
127 ///////////////////////////////////////
128 // Tests concerning getProcessedValue
129 ///////////////////////////////////////
132 * @see http://forge.typo3.org/issues/20994
134 public function getProcessedValueForZeroStringIsZero() {
135 $GLOBALS['TCA'] = array(
136 'tt_content' => array(
146 $this->assertEquals('0', BackendUtility
::getProcessedValue('tt_content', 'header', '0'));
152 public function getProcessedValueForGroup() {
153 $GLOBALS['TCA'] = array(
154 'tt_content' => array(
156 'multimedia' => array(
164 $this->assertSame('1, 2', BackendUtility
::getProcessedValue('tt_content', 'multimedia', '1,2'));
170 public function getProcessedValueForGroupWithOneAllowedTable() {
171 $GLOBALS['TCA'] = array(
172 'tt_content' => array(
177 'allowed' => 'pages',
178 'internal_type' => 'db',
189 $this->assertSame('Page 1, Page 2', ProcessedValueForGroupWithOneAllowedTableFixture
::getProcessedValue('tt_content', 'pages', '1,2'));
195 public function getProcessedValueForGroupWithMultipleAllowedTables() {
196 $GLOBALS['TCA'] = array(
197 'index_config' => array(
199 'indexcfgs' => array(
202 'internal_type' => 'db',
203 'allowed' => 'index_config,pages',
211 $this->assertSame('Page 1, Configuration 2', ProcessedValueForGroupWithMultipleAllowedTablesFixture
::getProcessedValue('index_config', 'indexcfgs', 'pages_1,index_config_2'));
217 public function getProcessedValueForSelectWithMMRelation() {
218 $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection
::class, array(), array(), '', FALSE);
219 $GLOBALS['TYPO3_DB']->expects($this->any())->method('fullQuoteStr')
220 ->will($this->returnCallback(
221 function($quoteStr) {
222 return "'" . $quoteStr . "'";
225 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTquery')->will($this->returnValue(0));
226 $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_free_result');
227 $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_fetch_assoc')
228 ->will($this->returnCallback(
233 // SELECT * FROM sys_category_record_mm
236 'uid_local' => 1, // uid of a sys_category record
237 'uid_foreign' => 1, // uid of a pages record
241 'uid_local' => 2, // uid of a sys_category record
242 'uid_foreign' => 1, // uid of a pages record
246 // SELECT * FROM sys_catgory
250 'title' => 'Category 1',
255 'title' => 'Category 2',
264 $GLOBALS['TCA'] = array(
267 'categories' => array(
270 'foreign_table' => 'sys_category',
271 'MM' => 'sys_category_record_mm',
272 'MM_match_fields' => array(
273 'fieldname' => 'categories',
274 'tablesnames' => 'pages',
276 'MM_opposite_field' => 'items',
281 'sys_category' => array(
286 'internal_type' => 'db',
288 'MM' => 'sys_category_record_mm',
289 'MM_oppositeUsage' => array(),
296 $this->assertSame('Category 1; Category 2', ProcessedValueForSelectWithMMRelationFixture
::getProcessedValue('pages', 'categories', '2', 0, FALSE, FALSE, 1));
300 * Tests concerning getCommonSelectFields
304 * Data provider for getCommonSelectFieldsReturnsCorrectFields
306 * @return array The test data with $table, $prefix, $presetFields, $tca, $expectedFields
308 public function getCommonSelectFieldsReturnsCorrectFieldsDataProvider() {
311 'table' => 'test_table',
313 'presetFields' => array(),
315 'expectedFields' => 'uid'
317 'label set' => array(
318 'table' => 'test_table',
320 'presetFields' => array(),
326 'expectedFields' => 'uid,label'
328 'label_alt set' => array(
329 'table' => 'test_table',
331 'presetFields' => array(),
334 'label_alt' => 'label,label2'
337 'expectedFields' => 'uid,label,label2'
339 'versioningWS set' => array(
340 'table' => 'test_table',
342 'presetFields' => array(),
345 'versioningWS' => '2'
348 'expectedFields' => 'uid,t3ver_id,t3ver_state,t3ver_wsid,t3ver_count'
350 'selicon_field set' => array(
351 'table' => 'test_table',
353 'presetFields' => array(),
356 'selicon_field' => 'field'
359 'expectedFields' => 'uid,field'
361 'typeicon_column set' => array(
362 'table' => 'test_table',
364 'presetFields' => array(),
367 'typeicon_column' => 'field'
370 'expectedFields' => 'uid,field'
372 'enablecolumns set' => array(
373 'table' => 'test_table',
375 'presetFields' => array(),
378 'enablecolumns' => array(
379 'disabled' => 'hidden',
380 'starttime' => 'start',
382 'fe_group' => 'groups'
386 'expectedFields' => 'uid,hidden,start,stop,groups'
388 'label set to uid' => array(
389 'table' => 'test_table',
391 'presetFields' => array(),
397 'expectedFields' => 'uid'
404 * @dataProvider getCommonSelectFieldsReturnsCorrectFieldsDataProvider
405 * @param string $table
406 * @param string $prefix
407 * @param array $presetFields
409 * @param string $expectedFields
411 public function getCommonSelectFieldsReturnsCorrectFields($table, $prefix = '', array $presetFields, array $tca, $expectedFields = '') {
412 $GLOBALS['TCA'][$table] = $tca;
413 $selectFields = BackendUtility
::getCommonSelectFields($table, $prefix, $presetFields);
414 $this->assertEquals($selectFields, $expectedFields);
418 * Tests concerning getLabelFromItemlist
422 * Data provider for getLabelFromItemlistReturnsCorrectFields
424 * @return array The test data with $table, $col, $key, $expectedLabel
426 public function getLabelFromItemlistReturnsCorrectFieldsDataProvider() {
429 'table' => 'tt_content',
430 'col' => 'menu_type',
434 'menu_type' => array(
437 array('Item 1', '0'),
438 array('Item 2', '1'),
445 'expectedLabel' => 'Item 2'
447 'item set twice' => array(
448 'table' => 'tt_content',
449 'col' => 'menu_type',
453 'menu_type' => array(
456 array('Item 1', '0'),
457 array('Item 2a', '1'),
458 array('Item 2b', '1'),
465 'expectedLabel' => 'Item 2a'
467 'item not found' => array(
468 'table' => 'tt_content',
469 'col' => 'menu_type',
473 'menu_type' => array(
476 array('Item 1', '0'),
477 array('Item 2', '1'),
484 'expectedLabel' => NULL
491 * @dataProvider getLabelFromItemlistReturnsCorrectFieldsDataProvider
492 * @param string $table
496 * @param string $expectedLabel
498 public function getLabelFromItemlistReturnsCorrectFields($table, $col = '', $key = '', array $tca, $expectedLabel = '') {
499 $GLOBALS['TCA'][$table] = $tca;
500 $label = BackendUtility
::getLabelFromItemlist($table, $col, $key);
501 $this->assertEquals($label, $expectedLabel);
505 * Tests concerning getLabelFromItemListMerged
509 * Data provider for getLabelFromItemListMerged
511 * @return array The test data with $pageId, $table, $column, $key, $expectedLabel
513 public function getLabelFromItemListMergedReturnsCorrectFieldsDataProvider() {
515 'no field found' => array(
517 'table' => 'tt_content',
518 'col' => 'menu_type',
522 'menu_type' => array(
525 array('Item 1', '0'),
526 array('Item 2', '1'),
533 'expectedLabel' => ''
535 'no tsconfig set' => array(
537 'table' => 'tt_content',
538 'col' => 'menu_type',
542 'menu_type' => array(
545 array('Item 1', '0'),
546 array('Item 2', '1'),
553 'expectedLabel' => 'Item 2'
560 * @dataProvider getLabelFromItemListMergedReturnsCorrectFieldsDataProvider
562 * @param string $table
563 * @param string $column
566 * @param string $expectedLabel
568 public function getLabelFromItemListMergedReturnsCorrectFields($pageId, $table, $column = '', $key = '', array $tca, $expectedLabel = '') {
569 $GLOBALS['TCA'][$table] = $tca;
571 $this->assertEquals($expectedLabel, LabelFromItemListMergedReturnsCorrectFieldsFixture
::getLabelFromItemListMerged($pageId, $table, $column, $key));
575 * Tests concerning getFuncCheck
581 public function getFuncCheckReturnsInputTagWithValueAttribute() {
582 $this->assertStringMatchesFormat('<input %Svalue="1"%S/>', BackendUtility
::getFuncCheck('params', 'test', TRUE));
586 * Tests concerning getLabelsFromItemsList
592 public function getLabelsFromItemsListDataProvider() {
594 'return value if found' => array(
597 'foo, bar', // keyList
600 'someColumn' => array(
603 '0' => array('aFooLabel', 'foo'),
604 '1' => array('aBarLabel', 'bar')
610 array(), // page TSconfig
611 'aFooLabel, aBarLabel' // expected
613 'page TSconfig overrules TCA' => array(
616 'foo,bar, add', // keyList
619 'someColumn' => array(
622 '0' => array('aFooLabel', 'foo'),
623 '1' => array('aBarLabel', 'bar')
629 array( // page TSconfig
630 'addItems.' => array('add' => 'aNewLabel'),
631 'altLabels.' => array('bar' => 'aBarDiffLabel'),
633 'aFooLabel, aBarDiffLabel, aNewLabel' // expected
640 * @dataProvider getLabelsFromItemsListDataProvider
641 * @param string $table
643 * @param string $keyList
645 * @param array $pageTsConfig
646 * @param string $expectedLabel
648 public function getLabelsFromItemsListReturnsCorrectValue($table, $col, $keyList, $tca, array $pageTsConfig, $expectedLabel) {
649 // Stub LanguageService and let sL() return the same value that came in again
650 $GLOBALS['LANG'] = $this->getMock(LanguageService
::class, array(), array(), '', FALSE);
651 $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
653 $GLOBALS['TCA'][$table] = $tca;
654 $label = BackendUtility
::getLabelsFromItemsList($table, $col, $keyList,$pageTsConfig);
655 $this->assertEquals($expectedLabel, $label);
661 public function getProcessedValueReturnsLabelsForExistingValuesSolely() {
666 'someColumn' => array(
670 '0' => array('aFooLabel', 'foo'),
671 '1' => array('aBarLabel', 'bar')
677 // Stub LanguageService and let sL() return the same value that came in again
678 $GLOBALS['LANG'] = $this->getMock(LanguageService
::class, array(), array(), '', FALSE);
679 $GLOBALS['LANG']->charSet
= 'utf-8';
680 $GLOBALS['LANG']->csConvObj
= $this->getMock(CharsetConverter
::class);
681 $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
683 $GLOBALS['LANG']->csConvObj
->expects($this->any())->method('crop')->will($this->returnArgument(1));
685 $GLOBALS['TCA'][$table] = $tca;
686 $label = BackendUtility
::getProcessedValue($table, $col, 'foo,invalidKey,bar');
687 $this->assertEquals('aFooLabel, aBarLabel', $label);
693 public function getProcessedValueReturnsPlainValueIfItemIsNotFound() {
698 'someColumn' => array(
702 '0' => array('aFooLabel', 'foo')
708 // Stub LanguageService and let sL() return the same value that came in again
709 $GLOBALS['LANG'] = $this->getMock(LanguageService
::class, array(), array(), '', FALSE);
710 $GLOBALS['LANG']->charSet
= 'utf-8';
711 $GLOBALS['LANG']->csConvObj
= $this->getMock(CharsetConverter
::class);
712 $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
714 $GLOBALS['LANG']->csConvObj
->expects($this->any())->method('crop')->will($this->returnArgument(1));
716 $GLOBALS['TCA'][$table] = $tca;
717 $label = BackendUtility
::getProcessedValue($table, $col, 'invalidKey');
718 $this->assertEquals('invalidKey', $label);
722 * Tests concerning getExcludeFields
728 public function getExcludeFieldsDataProvider() {
730 'getExcludeFields does not return fields not configured as exclude field' => array(
754 'getExcludeFields returns fields from root level tables if root level restriction should be ignored' => array(
761 'ignoreRootLevelRestriction' => TRUE,
779 'getExcludeFields does not return fields from root level tables' => array(
796 'getExcludeFields does not return fields from admin only level tables' => array(
821 * @dataProvider getExcludeFieldsDataProvider
823 public function getExcludeFieldsReturnsCorrectFieldList($tca, $expected) {
824 $GLOBALS['TCA'] = $tca;
826 // Stub LanguageService and let sL() return the same value that came in again
827 $GLOBALS['LANG'] = $this->getMock(LanguageService
::class, array(), array(), '', FALSE);
828 $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
830 $this->assertSame($expected, ExcludeFieldsReturnsCorrectFieldListFixture
::getExcludeFields());
836 public function getExcludeFieldsReturnsCorrectListWithFlexFormFields() {
837 $GLOBALS['TCA'] = array(
852 'label' => 'abarfoo',
862 'tx_foobar' => array(
894 $expectedResult = array(
904 'abarfoo dummy: The Title:',
905 'tx_foo:abarfoo;dummy;sGeneral;xmlTitle'
925 // Stub LanguageService and let sL() return the same value that came in again
926 $GLOBALS['LANG'] = $this->getMock(LanguageService
::class, array(), array(), '', FALSE);
927 $GLOBALS['LANG']->expects($this->any())->method('sL')->will($this->returnArgument(0));
929 $this->assertSame($expectedResult, ExcludeFieldsReturnsCorrectListWithFlexFormFieldsFixture
::getExcludeFields());
933 * Tests concerning viewOnClick
939 public function viewOnClickReturnsOnClickCodeWithAlternativeUrl() {
940 // Make sure the hook inside viewOnClick is not fired. This may be removed if unit tests
941 // bootstrap does not initialize TYPO3_CONF_VARS anymore.
942 unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']);
944 $alternativeUrl = 'https://typo3.org/about/typo3-the-cms/the-history-of-typo3/#section';
945 $onclickCode = 'var previewWin = window.open(' . GeneralUtility
::quoteJSvalue($alternativeUrl) . ',\'newTYPO3frontendWindow\');';
946 $this->assertStringMatchesFormat(
948 BackendUtility
::viewOnClick(NULL, NULL, NULL, NULL, $alternativeUrl, NULL, FALSE)
953 * Tests concerning replaceMarkersInWhereClause
959 public function replaceMarkersInWhereClauseDataProvider() {
961 'replaceMarkersInWhereClause replaces record field marker with quoted string' => array(
962 ' AND dummytable.title=\'###REC_FIELD_dummyfield###\'',
964 '_THIS_ROW' => array(
965 'dummyfield' => 'Hello World'
968 ' AND dummytable.title=\'Hello World\''
970 'replaceMarkersInWhereClause replaces record field marker with fullquoted string' => array(
971 ' AND dummytable.title=###REC_FIELD_dummyfield###',
973 '_THIS_ROW' => array(
974 'dummyfield' => 'Hello World'
977 ' AND dummytable.title=\'Hello World\''
979 'replaceMarkersInWhereClause replaces multiple record field markers' => array(
980 ' AND dummytable.title=\'###REC_FIELD_dummyfield###\' AND dummytable.pid=###REC_FIELD_pid###',
982 '_THIS_ROW' => array(
983 'dummyfield' => 'Hello World',
987 ' AND dummytable.title=\'Hello World\' AND dummytable.pid=\'42\''
989 'replaceMarkersInWhereClause replaces current pid with integer' => array(
990 ' AND dummytable.uid=###CURRENT_PID###',
994 ' AND dummytable.uid=42'
996 'replaceMarkersInWhereClause replaces current pid with string' => array(
997 ' AND dummytable.uid=###CURRENT_PID###',
999 '_CURRENT_PID' => '42string'
1001 ' AND dummytable.uid=42'
1003 'replaceMarkersInWhereClause replaces current record uid with integer' => array(
1004 ' AND dummytable.uid=###THIS_UID###',
1008 ' AND dummytable.uid=42'
1010 'replaceMarkersInWhereClause replaces current record uid with string' => array(
1011 ' AND dummytable.uid=###THIS_UID###',
1013 '_THIS_UID' => '42string'
1015 ' AND dummytable.uid=42'
1017 'replaceMarkersInWhereClause replaces storage pid with integer' => array(
1018 ' AND dummytable.uid=###STORAGE_PID###',
1020 '_STORAGE_PID' => 42
1022 ' AND dummytable.uid=42'
1024 'replaceMarkersInWhereClause replaces storage pid with string' => array(
1025 ' AND dummytable.uid=###STORAGE_PID###',
1027 '_STORAGE_PID' => '42string'
1029 ' AND dummytable.uid=42'
1031 'replaceMarkersInWhereClause replaces siteroot uid with integer' => array(
1032 ' AND dummytable.uid=###SITEROOT###',
1036 ' AND dummytable.uid=42'
1038 'replaceMarkersInWhereClause replaces siteroot uid with string' => array(
1039 ' AND dummytable.uid=###SITEROOT###',
1041 '_SITEROOT' => '42string'
1043 ' AND dummytable.uid=42'
1045 'replaceMarkersInWhereClause replaces page tsconfig id with integer' => array(
1046 ' AND dummytable.uid=###PAGE_TSCONFIG_ID###',
1048 'dummyfield' => array(
1049 'PAGE_TSCONFIG_ID' => 42
1052 ' AND dummytable.uid=42'
1054 'replaceMarkersInWhereClause replaces page tsconfig id with string' => array(
1055 ' AND dummytable.uid=###PAGE_TSCONFIG_ID###',
1057 'dummyfield' => array(
1058 'PAGE_TSCONFIG_ID' => '42string'
1061 ' AND dummytable.uid=42'
1063 'replaceMarkersInWhereClause replaces page tsconfig string' => array(
1064 ' AND dummytable.title=\'###PAGE_TSCONFIG_STR###\'',
1066 'dummyfield' => array(
1067 'PAGE_TSCONFIG_STR' => '42'
1070 ' AND dummytable.title=\'42\''
1072 'replaceMarkersInWhereClause replaces all markers' => array(
1073 ' AND dummytable.title=\'###REC_FIELD_dummyfield###\'' .
1074 ' AND dummytable.uid=###REC_FIELD_uid###' .
1075 ' AND dummytable.pid=###CURRENT_PID###' .
1076 ' AND dummytable.l18n_parent=###THIS_UID###' .
1077 ' AND dummytable.storage_pid=###STORAGE_PID###' .
1078 ' AND dummytable.siteroot=###SITEROOT###' .
1079 ' AND dummytable.config_uid=###PAGE_TSCONFIG_ID###' .
1080 ' AND dummytable.idlist IN (###PAGE_TSCONFIG_IDLIST###)' .
1081 ' AND dummytable.string=\'###PAGE_TSCONFIG_STR###\'',
1083 '_THIS_ROW' => array(
1084 'dummyfield' => 'Hello World',
1087 '_CURRENT_PID' => '1',
1089 '_STORAGE_PID' => 4,
1091 'dummyfield' => array(
1092 'PAGE_TSCONFIG_ID' => 6,
1093 'PAGE_TSCONFIG_IDLIST' => '1,2,3',
1094 'PAGE_TSCONFIG_STR' => 'string'
1097 ' AND dummytable.title=\'Hello World\' AND dummytable.uid=\'42\' AND dummytable.pid=1' .
1098 ' AND dummytable.l18n_parent=2 AND dummytable.storage_pid=4' .
1099 ' AND dummytable.siteroot=5 AND dummytable.config_uid=6 AND dummytable.idlist IN (1,2,3)' .
1100 ' AND dummytable.string=\'string\'',
1107 * @dataProvider replaceMarkersInWhereClauseDataProvider
1108 * @param string $whereClause
1109 * @param array $tsConfig
1110 * @param string $expected
1111 * @throws \PHPUnit_Framework_Exception
1113 public function replaceMarkersInWhereClauseReturnsValidWhereClause($whereClause, array $tsConfig, $expected) {
1114 // Mock TYPO3_DB and let it return same values that came in
1115 $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection
::class, array(), array(), '', FALSE);
1116 $GLOBALS['TYPO3_DB']->expects($this->any())->method('quoteStr')->will($this->returnArgument(0));
1117 $GLOBALS['TYPO3_DB']->expects($this->any())->method('fullQuoteStr')
1118 ->will($this->returnCallback(
1119 function($quoteStr) {
1120 return "'" . $quoteStr . "'";
1123 $GLOBALS['TYPO3_DB']->expects($this->any())->method('cleanIntList')->will($this->returnArgument(0));
1124 $this->assertSame($expected, BackendUtility
::replaceMarkersInWhereClause($whereClause, 'dummytable', 'dummyfield', $tsConfig));
1130 public function replaceMarkersInWhereClauseCleansIdList() {
1131 $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection
::class, array(), array(), '', FALSE);
1132 $GLOBALS['TYPO3_DB']->expects($this->once())->method('cleanIntList')->with('1,a,2,b,3,c');
1133 $where = ' AND dummytable.uid IN (###PAGE_TSCONFIG_IDLIST###)';
1135 'dummyfield' => array(
1136 'PAGE_TSCONFIG_IDLIST' => '1,a,2,b,3,c'
1139 BackendUtility
::replaceMarkersInWhereClause($where, 'dummytable', 'dummyfield', $tsConfig);
1145 public function getModTSconfigIgnoresValuesFromUserTsConfigIfNoSet() {
1146 $completeConfiguration = array(
1148 'properties' => array(
1149 'permissions.' => array(
1151 'default.' => array('readAction' => '1'),
1152 '1.' => array('writeAction' => '1'),
1153 '0.' => array('readAction' => '0'),
1159 $GLOBALS['BE_USER'] = $this->getMock(BackendUserAuthentication
::class, array(), array(), '', FALSE);
1160 $GLOBALS['BE_USER']->expects($this->at(0))->method('getTSConfig')->will($this->returnValue($completeConfiguration));
1161 $GLOBALS['BE_USER']->expects($this->at(1))->method('getTSConfig')->will($this->returnValue(array('value' => NULL, 'properties' => NULL)));
1163 $className = $this->getUniqueId('BackendUtility');
1164 /** @var \PHPUnit_Framework_MockObject_MockObject|BackendUtility $subject */
1165 $subject = __NAMESPACE__
. '\\' . $className;
1167 'namespace ' . __NAMESPACE__
. ';' .
1168 'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
1169 ' static public function getPagesTSconfig($id, $rootLine = NULL, $returnPartArray = false) {' .
1170 ' return array();' .
1175 $this->assertSame($completeConfiguration, $subject::getModTSconfig(42, 'notrelevant'));
1179 * Data provider for replaceL10nModeFieldsReplacesFields
1182 public function replaceL10nModeFieldsReplacesFieldsDataProvider() {
1184 'same table: mergeIfNotBlank' => array(
1189 'field3' => 'trans',
1194 'transOrigPointerTable' => '',
1195 'transOrigPointerField' => 'origUid'
1198 'field2' => array('l10n_mode' => 'mergeIfNotBlank'),
1199 'field3' => array('l10n_mode' => 'mergeIfNotBlank')
1205 'field2' => 'basic',
1211 'field3' => 'trans',
1214 'other table: mergeIfNotBlank' => array(
1219 'field3' => 'trans',
1224 'transOrigPointerTable' => 'bar',
1225 'transOrigPointerField' => 'origUid'
1230 'field2' => array('l10n_mode' => 'mergeIfNotBlank'),
1231 'field3' => array('l10n_mode' => 'mergeIfNotBlank')
1237 'field2' => 'basic',
1242 'field2' => 'basic',
1243 'field3' => 'trans',
1246 'same table: exclude' => array(
1251 'field3' => 'trans',
1256 'transOrigPointerTable' => '',
1257 'transOrigPointerField' => 'origUid'
1260 'field2' => array('l10n_mode' => 'exclude'),
1261 'field3' => array('l10n_mode' => 'exclude')
1267 'field2' => 'basic',
1272 'field2' => 'basic',
1276 'other table: exclude' => array(
1281 'field3' => 'trans',
1286 'transOrigPointerTable' => 'bar',
1287 'transOrigPointerField' => 'origUid'
1292 'field2' => array('l10n_mode' => 'exclude'),
1293 'field3' => array('l10n_mode' => 'exclude')
1299 'field2' => 'basic',
1304 'field2' => 'basic',
1313 * @dataProvider replaceL10nModeFieldsReplacesFieldsDataProvider
1314 * @param string $table
1317 * @param array $originalRow
1318 * @param array $expected
1319 * @throws \InvalidArgumentException
1320 * @throws \PHPUnit_Framework_Exception
1322 public function replaceL10nModeFieldsReplacesFields($table, array $row, array $tca, array $originalRow, $expected) {
1323 $GLOBALS['TCA'] = $tca;
1324 $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection
::class);
1325 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->will($this->returnValue($originalRow));
1327 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|BackendUtility $subject */
1328 $subject = $this->getAccessibleMock(BackendUtility
::class, array('dummy'));
1329 $this->assertSame($expected, $subject->_call('replaceL10nModeFields', $table, $row));
1335 public function getSpecConfPartsSplitsDefaultExtras() {
1336 $defaultExtras = 'nowrap:wizards[foo|bar]:anotherDefaultExtras:some[other|setting|with|parameters]';
1340 'parameters' => array(
1345 'anotherDefaultExtras' => 1,
1347 'parameters' => array(
1355 $this->assertEquals($expected, BackendUtility
::getSpecConfParts($defaultExtras));