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
;
22 * @author Oliver Klee <typo3-coding@oliverklee.de>
24 class BackendUtilityTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
26 ///////////////////////////////////////
27 // Tests concerning calcAge
28 ///////////////////////////////////////
30 * Data provider for calcAge function
34 public function calcAgeDataProvider() {
36 'Single year' => array(
37 'seconds' => 60 * 60 * 24 * 365,
38 'expectedLabel' => '1 year'
40 'Plural years' => array(
41 'seconds' => 60 * 60 * 24 * 365 * 2,
42 'expectedLabel' => '2 yrs'
44 'Single negative year' => array(
45 'seconds' => 60 * 60 * 24 * 365 * -1,
46 'expectedLabel' => '-1 year'
48 'Plural negative years' => array(
49 'seconds' => 60 * 60 * 24 * 365 * 2 * -1,
50 'expectedLabel' => '-2 yrs'
52 'Single day' => array(
53 'seconds' => 60 * 60 * 24,
54 'expectedLabel' => '1 day'
56 'Plural days' => array(
57 'seconds' => 60 * 60 * 24 * 2,
58 'expectedLabel' => '2 days'
60 'Single negative day' => array(
61 'seconds' => 60 * 60 * 24 * -1,
62 'expectedLabel' => '-1 day'
64 'Plural negative days' => array(
65 'seconds' => 60 * 60 * 24 * 2 * -1,
66 'expectedLabel' => '-2 days'
68 'Single hour' => array(
70 'expectedLabel' => '1 hour'
72 'Plural hours' => array(
73 'seconds' => 60 * 60 * 2,
74 'expectedLabel' => '2 hrs'
76 'Single negative hour' => array(
77 'seconds' => 60 * 60 * -1,
78 'expectedLabel' => '-1 hour'
80 'Plural negative hours' => array(
81 'seconds' => 60 * 60 * 2 * -1,
82 'expectedLabel' => '-2 hrs'
84 'Single minute' => array(
86 'expectedLabel' => '1 min'
88 'Plural minutes' => array(
90 'expectedLabel' => '2 min'
92 'Single negative minute' => array(
94 'expectedLabel' => '-1 min'
96 'Plural negative minutes' => array(
97 'seconds' => 60 * 2 * -1,
98 'expectedLabel' => '-2 min'
100 'Zero seconds' => array(
102 'expectedLabel' => '0 min'
109 * @dataProvider calcAgeDataProvider
111 public function calcAgeReturnsExpectedValues($seconds, $expectedLabel) {
112 $this->assertSame($expectedLabel, BackendUtility
::calcAge($seconds));
115 ///////////////////////////////////////
116 // Tests concerning getProcessedValue
117 ///////////////////////////////////////
120 * @see http://forge.typo3.org/issues/20994
122 public function getProcessedValueForZeroStringIsZero() {
123 $GLOBALS['TCA'] = array(
124 'tt_content' => array(
134 $this->assertEquals('0', BackendUtility
::getProcessedValue('tt_content', 'header', '0'));
140 public function getProcessedValueForGroup() {
141 $GLOBALS['TCA'] = array(
142 'tt_content' => array(
144 'multimedia' => array(
152 $this->assertSame('1, 2', BackendUtility
::getProcessedValue('tt_content', 'multimedia', '1,2'));
158 public function getProcessedValueForGroupWithOneAllowedTable() {
159 // Disable getRecordWSOL and getRecordTitle dependency by returning stable results
160 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
161 $className = uniqid('BackendUtility');
162 $subject = __NAMESPACE__
. '\\' . $className;
164 'namespace ' . __NAMESPACE__
. ';' .
165 'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
166 ' static public function getRecordWSOL() {' .
167 ' static $called = 0;' .
169 ' if ($called === 1) {' .
170 ' return array(\'title\' => \'Page 1\');' .
172 ' if ($called === 2) {' .
173 ' return array(\'title\' => \'Page 2\');' .
176 ' static public function getRecordTitle() {' .
177 ' static $called = 0;' .
179 ' if ($called === 1) {' .
180 ' return \'Page 1\';' .
182 ' if ($called === 2) {' .
183 ' return \'Page 2\';' .
189 $GLOBALS['TCA'] = array(
190 'tt_content' => array(
195 'allowed' => 'pages',
196 'internal_type' => 'db',
207 $this->assertSame('Page 1, Page 2', $subject::getProcessedValue('tt_content', 'pages', '1,2'));
213 public function getProcessedValueForGroupWithMultipleAllowedTables() {
214 // Disable getRecordWSOL and getRecordTitle dependency by returning stable results
215 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
216 $className = uniqid('BackendUtility');
217 $subject = __NAMESPACE__
. '\\' . $className;
219 'namespace ' . __NAMESPACE__
. ';' .
220 'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
221 ' static public function getRecordWSOL() {' .
222 ' static $called = 0;' .
224 ' if ($called === 1) {' .
225 ' return array(\'title\' => \'Page 1\');' .
227 ' if ($called === 2) {' .
228 ' return array(\'header\' => \'Content 2\');' .
231 ' static public function getRecordTitle() {' .
232 ' static $called = 0;' .
234 ' if ($called === 1) {' .
235 ' return \'Page 1\';' .
237 ' if ($called === 2) {' .
238 ' return \'Content 2\';' .
244 $GLOBALS['TCA'] = array(
245 'sys_category' => array(
250 'internal_type' => 'db',
251 'MM' => 'sys_category_record_mm',
260 $this->assertSame('Page 1, Content 2', $subject::getProcessedValue('sys_category', 'items', 'pages_1,tt_content_2'));
264 * Tests concerning getCommonSelectFields
268 * Data provider for getCommonSelectFieldsReturnsCorrectFields
270 * @return array The test data with $table, $prefix, $presetFields, $tca, $expectedFields
272 public function getCommonSelectFieldsReturnsCorrectFieldsDataProvider() {
275 'table' => 'test_table',
277 'presetFields' => array(),
279 'expectedFields' => 'uid'
281 'label set' => array(
282 'table' => 'test_table',
284 'presetFields' => array(),
290 'expectedFields' => 'uid,label'
292 'label_alt set' => array(
293 'table' => 'test_table',
295 'presetFields' => array(),
298 'label_alt' => 'label,label2'
301 'expectedFields' => 'uid,label,label2'
303 'versioningWS set' => array(
304 'table' => 'test_table',
306 'presetFields' => array(),
309 'versioningWS' => '2'
312 'expectedFields' => 'uid,t3ver_id,t3ver_state,t3ver_wsid,t3ver_count'
314 'selicon_field set' => array(
315 'table' => 'test_table',
317 'presetFields' => array(),
320 'selicon_field' => 'field'
323 'expectedFields' => 'uid,field'
325 'typeicon_column set' => array(
326 'table' => 'test_table',
328 'presetFields' => array(),
331 'typeicon_column' => 'field'
334 'expectedFields' => 'uid,field'
336 'enablecolumns set' => array(
337 'table' => 'test_table',
339 'presetFields' => array(),
342 'enablecolumns' => array(
343 'disabled' => 'hidden',
344 'starttime' => 'start',
346 'fe_group' => 'groups'
350 'expectedFields' => 'uid,hidden,start,stop,groups'
352 'label set to uid' => array(
353 'table' => 'test_table',
355 'presetFields' => array(),
361 'expectedFields' => 'uid'
368 * @dataProvider getCommonSelectFieldsReturnsCorrectFieldsDataProvider
370 public function getCommonSelectFieldsReturnsCorrectFields($table, $prefix = '', array $presetFields, array $tca, $expectedFields = '') {
371 $GLOBALS['TCA'][$table] = $tca;
372 $selectFields = BackendUtility
::getCommonSelectFields($table, $prefix, $presetFields);
373 $this->assertEquals($selectFields, $expectedFields);
377 * Tests concerning getLabelFromItemlist
381 * Data provider for getLabelFromItemlistReturnsCorrectFields
383 * @return array The test data with $table, $col, $key, $expectedLabel
385 public function getLabelFromItemlistReturnsCorrectFieldsDataProvider() {
388 'table' => 'tt_content',
389 'col' => 'menu_type',
393 'menu_type' => array(
396 array('Item 1', '0'),
397 array('Item 2', '1'),
404 'expectedLabel' => 'Item 2'
406 'item set twice' => array(
407 'table' => 'tt_content',
408 'col' => 'menu_type',
412 'menu_type' => array(
415 array('Item 1', '0'),
416 array('Item 2a', '1'),
417 array('Item 2b', '1'),
424 'expectedLabel' => 'Item 2a'
426 'item not found' => array(
427 'table' => 'tt_content',
428 'col' => 'menu_type',
432 'menu_type' => array(
435 array('Item 1', '0'),
436 array('Item 2', '1'),
443 'expectedLabel' => NULL
450 * @dataProvider getLabelFromItemlistReturnsCorrectFieldsDataProvider
452 public function getLabelFromItemlistReturnsCorrectFields($table, $col = '', $key = '', array $tca, $expectedLabel = '') {
453 $GLOBALS['TCA'][$table] = $tca;
454 $label = BackendUtility
::getLabelFromItemlist($table, $col, $key);
455 $this->assertEquals($label, $expectedLabel);
459 * Tests concerning getLabelFromItemListMerged
463 * Data provider for getLabelFromItemListMerged
465 * @return array The test data with $pageId, $table, $column, $key, $expectedLabel
467 public function getLabelFromItemListMergedReturnsCorrectFieldsDataProvider() {
469 'no field found' => array(
471 'table' => 'tt_content',
472 'col' => 'menu_type',
476 'menu_type' => array(
479 array('Item 1', '0'),
480 array('Item 2', '1'),
487 'expectedLabel' => ''
489 'no tsconfig set' => array(
491 'table' => 'tt_content',
492 'col' => 'menu_type',
496 'menu_type' => array(
499 array('Item 1', '0'),
500 array('Item 2', '1'),
507 'expectedLabel' => 'Item 2'
514 * @dataProvider getLabelFromItemListMergedReturnsCorrectFieldsDataProvider
516 public function getLabelFromItemListMergedReturnsCorrectFields($pageId, $table, $column = '', $key = '', array $tca, $expectedLabel = '') {
517 // Disable getPagesTSconfig by returning stable result
518 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
519 $className = uniqid('BackendUtility');
520 $subject = __NAMESPACE__
. '\\' . $className;
522 'namespace ' . __NAMESPACE__
. ';' .
523 'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
524 ' static public function getPagesTSconfig() {' .
530 $GLOBALS['TCA'][$table] = $tca;
532 $this->assertEquals($expectedLabel, $subject::getLabelFromItemListMerged($pageId, $table, $column, $key));
536 * Tests concerning getFuncCheck
542 public function getFuncCheckReturnsInputTagWithValueAttribute() {
543 $this->assertStringMatchesFormat('<input %Svalue="1"%S/>', BackendUtility
::getFuncCheck('params', 'test', TRUE));
547 * Tests concerning getLabelsFromItemsList
553 public function getLabelsFromItemsListReturnsValueIfItemIsFound() {
558 'someColumn' => array(
561 '0' => array('aFooLabel', 'foo'),
562 '1' => array('aBarLabel', 'bar')
568 // Stub LanguageService and let sL() return the same value that came in again
569 $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
570 $GLOBALS['LANG']->expects($this->any())->method('sL')
571 ->will($this->returnCallback(
577 $GLOBALS['TCA'][$table] = $tca;
578 $label = BackendUtility
::getLabelsFromItemsList($table, $col, 'foo,bar');
579 $this->assertEquals('aFooLabel, aBarLabel', $label);
585 public function getProcessedValueReturnsLabelsForExistingValuesSolely() {
590 'someColumn' => array(
594 '0' => array('aFooLabel', 'foo'),
595 '1' => array('aBarLabel', 'bar')
601 // Stub LanguageService and let sL() return the same value that came in again
602 $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
603 $GLOBALS['LANG']->charSet
= 'utf-8';
604 $GLOBALS['LANG']->csConvObj
= $this->getMock('TYPO3\\CMS\\Core\\Charset\\CharsetConverter');
605 $GLOBALS['LANG']->expects($this->any())->method('sL')
606 ->will($this->returnCallback(
611 $GLOBALS['LANG']->csConvObj
->expects($this->any())->method('crop')
612 ->will($this->returnCallback(
613 function($charset, $string, $len, $crop = '') {
618 $GLOBALS['TCA'][$table] = $tca;
619 $label = BackendUtility
::getProcessedValue($table, $col, 'foo,invalidKey,bar');
620 $this->assertEquals('aFooLabel, aBarLabel', $label);
626 public function getProcessedValueReturnsPlainValueIfItemIsNotFound() {
631 'someColumn' => array(
635 '0' => array('aFooLabel', 'foo')
641 // Stub LanguageService and let sL() return the same value that came in again
642 $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
643 $GLOBALS['LANG']->charSet
= 'utf-8';
644 $GLOBALS['LANG']->csConvObj
= $this->getMock('TYPO3\\CMS\\Core\\Charset\\CharsetConverter');
645 $GLOBALS['LANG']->expects($this->any())->method('sL')
646 ->will($this->returnCallback(
651 $GLOBALS['LANG']->csConvObj
->expects($this->any())->method('crop')
652 ->will($this->returnCallback(
653 function($charset, $string, $len, $crop = '') {
658 $GLOBALS['TCA'][$table] = $tca;
659 $label = BackendUtility
::getProcessedValue($table, $col, 'invalidKey');
660 $this->assertEquals('invalidKey', $label);
664 * Tests concerning getExcludeFields
670 public function getExcludeFieldsDataProvider() {
672 'getExcludeFields does not return fields not configured as exclude field' => array(
696 'getExcludeFields returns fields from root level tables if root level restriction should be ignored' => array(
703 'ignoreRootLevelRestriction' => TRUE,
721 'getExcludeFields does not return fields from root level tables' => array(
738 'getExcludeFields does not return fields from admin only level tables' => array(
763 * @dataProvider getExcludeFieldsDataProvider
765 public function getExcludeFieldsReturnsCorrectFieldList($tca, $expected) {
766 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
767 $className = uniqid('BackendUtility');
768 $subject = __NAMESPACE__
. '\\' . $className;
770 'namespace ' . __NAMESPACE__
. ';' .
771 'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
772 ' static public function getRegisteredFlexForms() {' .
778 $GLOBALS['TCA'] = $tca;
780 // Stub LanguageService and let sL() return the same value that came in again
781 $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
782 $GLOBALS['LANG']->expects($this->any())->method('sL')
783 ->will($this->returnCallback(
789 $this->assertSame($expected, $subject::getExcludeFields());
795 public function getExcludeFieldsReturnsCorrectListWithFlexFormFields() {
796 $GLOBALS['TCA'] = array(
811 'label' => 'abarfoo',
821 'tx_foobar' => array(
853 $expectedResult = array(
863 'abarfoo dummy: The Title:',
864 'tx_foo:abarfoo;dummy;sGeneral;xmlTitle'
884 // Stub LanguageService and let sL() return the same value that came in again
885 $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
886 $GLOBALS['LANG']->expects($this->any())->method('sL')
887 ->will($this->returnCallback(
893 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
894 $className = uniqid('BackendUtility');
895 $subject = __NAMESPACE__
. '\\' . $className;
897 'namespace ' . __NAMESPACE__
. ';' .
898 'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
899 ' static public function getRegisteredFlexForms($table) {' .
900 ' static $called = 0;' .
902 ' if ($called === 1) {' .
905 ' if ($called === 2) {' .
906 ' if ($table !== \'tx_foo\') {' .
907 ' throw new Exception(\'Expected tx_foo as argument on call 2\', 1399638572);' .
909 ' $parsedFlexForm = array(' .
910 ' \'abarfoo\' => array(' .
911 ' \'dummy\' => array(' .
912 ' \'title\' => \'dummy\',' .
913 ' \'ds\' => array(' .
914 ' \'sheets\' => array(' .
915 ' \'sGeneral\' => array(' .
916 ' \'ROOT\' => array(' .
917 ' \'type\' => \'array\',' .
918 ' \'el\' => array(' .
919 ' \'xmlTitle\' => array(' .
920 ' \'TCEforms\' => array(' .
921 ' \'exclude\' => 1,' .
922 ' \'label\' => \'The Title:\',' .
923 ' \'config\' => array(' .
924 ' \'type\' => \'input\',' .
937 ' return $parsedFlexForm;' .
939 ' if ($called === 3) {' .
946 $this->assertSame($expectedResult, $subject::getExcludeFields());
950 * Tests concerning viewOnClick
956 public function viewOnClickReturnsOnClickCodeWithAlternativeUrl() {
957 // Make sure the hook inside viewOnClick is not fired. This may be removed if unit tests
958 // bootstrap does not initialize TYPO3_CONF_VARS anymore.
959 unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']);
961 $alternativeUrl = 'https://typo3.org/about/typo3-the-cms/the-history-of-typo3/#section';
962 $onclickCode = 'var previewWin = window.open(\'' . $alternativeUrl . '\',\'newTYPO3frontendWindow\');';
963 $this->assertStringMatchesFormat(
965 BackendUtility
::viewOnClick(NULL, NULL, NULL, NULL, $alternativeUrl, NULL, FALSE)
970 * Tests concerning replaceMarkersInWhereClause
976 public function replaceMarkersInWhereClauseDataProvider() {
978 'replaceMarkersInWhereClause replaces record field marker with quoted string' => array(
979 ' AND dummytable.title=\'###REC_FIELD_dummyfield###\'',
981 '_THIS_ROW' => array(
982 'dummyfield' => 'Hello World'
985 ' AND dummytable.title=\'Hello World\''
987 'replaceMarkersInWhereClause replaces record field marker with fullquoted string' => array(
988 ' AND dummytable.title=###REC_FIELD_dummyfield###',
990 '_THIS_ROW' => array(
991 'dummyfield' => 'Hello World'
994 ' AND dummytable.title=\'Hello World\''
996 'replaceMarkersInWhereClause replaces multiple record field markers' => array(
997 ' AND dummytable.title=\'###REC_FIELD_dummyfield###\' AND dummytable.pid=###REC_FIELD_pid###',
999 '_THIS_ROW' => array(
1000 'dummyfield' => 'Hello World',
1004 ' AND dummytable.title=\'Hello World\' AND dummytable.pid=\'42\''
1006 'replaceMarkersInWhereClause replaces current pid with integer' => array(
1007 ' AND dummytable.uid=###CURRENT_PID###',
1009 '_CURRENT_PID' => 42
1011 ' AND dummytable.uid=42'
1013 'replaceMarkersInWhereClause replaces current pid with string' => array(
1014 ' AND dummytable.uid=###CURRENT_PID###',
1016 '_CURRENT_PID' => '42string'
1018 ' AND dummytable.uid=42'
1020 'replaceMarkersInWhereClause replaces current record uid with integer' => array(
1021 ' AND dummytable.uid=###THIS_UID###',
1025 ' AND dummytable.uid=42'
1027 'replaceMarkersInWhereClause replaces current record uid with string' => array(
1028 ' AND dummytable.uid=###THIS_UID###',
1030 '_THIS_UID' => '42string'
1032 ' AND dummytable.uid=42'
1034 'replaceMarkersInWhereClause replaces current record cid with integer' => array(
1035 ' AND dummytable.uid=###THIS_CID###',
1039 ' AND dummytable.uid=42'
1041 'replaceMarkersInWhereClause replaces current record cid with string' => array(
1042 ' AND dummytable.uid=###THIS_CID###',
1044 '_THIS_CID' => '42string'
1046 ' AND dummytable.uid=42'
1048 'replaceMarkersInWhereClause replaces storage pid with integer' => array(
1049 ' AND dummytable.uid=###STORAGE_PID###',
1051 '_STORAGE_PID' => 42
1053 ' AND dummytable.uid=42'
1055 'replaceMarkersInWhereClause replaces storage pid with string' => array(
1056 ' AND dummytable.uid=###STORAGE_PID###',
1058 '_STORAGE_PID' => '42string'
1060 ' AND dummytable.uid=42'
1062 'replaceMarkersInWhereClause replaces siteroot uid with integer' => array(
1063 ' AND dummytable.uid=###SITEROOT###',
1067 ' AND dummytable.uid=42'
1069 'replaceMarkersInWhereClause replaces siteroot uid with string' => array(
1070 ' AND dummytable.uid=###SITEROOT###',
1072 '_SITEROOT' => '42string'
1074 ' AND dummytable.uid=42'
1076 'replaceMarkersInWhereClause replaces page tsconfig id with integer' => array(
1077 ' AND dummytable.uid=###PAGE_TSCONFIG_ID###',
1079 'dummyfield' => array(
1080 'PAGE_TSCONFIG_ID' => 42
1083 ' AND dummytable.uid=42'
1085 'replaceMarkersInWhereClause replaces page tsconfig id with string' => array(
1086 ' AND dummytable.uid=###PAGE_TSCONFIG_ID###',
1088 'dummyfield' => array(
1089 'PAGE_TSCONFIG_ID' => '42string'
1092 ' AND dummytable.uid=42'
1094 'replaceMarkersInWhereClause replaces page tsconfig string' => array(
1095 ' AND dummytable.title=\'###PAGE_TSCONFIG_STR###\'',
1097 'dummyfield' => array(
1098 'PAGE_TSCONFIG_STR' => '42'
1101 ' AND dummytable.title=\'42\''
1103 'replaceMarkersInWhereClause replaces all markers' => array(
1104 ' AND dummytable.title=\'###REC_FIELD_dummyfield###\'' .
1105 ' AND dummytable.uid=###REC_FIELD_uid###' .
1106 ' AND dummytable.pid=###CURRENT_PID###' .
1107 ' AND dummytable.l18n_parent=###THIS_UID###' .
1108 ' AND dummytable.cid=###THIS_CID###' .
1109 ' AND dummytable.storage_pid=###STORAGE_PID###' .
1110 ' AND dummytable.siteroot=###SITEROOT###' .
1111 ' AND dummytable.config_uid=###PAGE_TSCONFIG_ID###' .
1112 ' AND dummytable.idlist IN (###PAGE_TSCONFIG_IDLIST###)' .
1113 ' AND dummytable.string=\'###PAGE_TSCONFIG_STR###\'',
1115 '_THIS_ROW' => array(
1116 'dummyfield' => 'Hello World',
1119 '_CURRENT_PID' => '1',
1122 '_STORAGE_PID' => 4,
1124 'dummyfield' => array(
1125 'PAGE_TSCONFIG_ID' => 6,
1126 'PAGE_TSCONFIG_IDLIST' => '1,2,3',
1127 'PAGE_TSCONFIG_STR' => 'string'
1130 ' AND dummytable.title=\'Hello World\' AND dummytable.uid=\'42\' AND dummytable.pid=1' .
1131 ' AND dummytable.l18n_parent=2 AND dummytable.cid=3 AND dummytable.storage_pid=4' .
1132 ' AND dummytable.siteroot=5 AND dummytable.config_uid=6 AND dummytable.idlist IN (1,2,3)' .
1133 ' AND dummytable.string=\'string\'',
1140 * @dataProvider replaceMarkersInWhereClauseDataProvider
1142 public function replaceMarkersInWhereClauseReturnsValidWhereClause($whereClause, $tsConfig, $expected) {
1143 // Mock TYPO3_DB and let it return same values that came in
1144 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
1145 $GLOBALS['TYPO3_DB']->expects($this->any())->method('quoteStr')
1146 ->will($this->returnCallback(
1147 function($quoteStr, $table) {
1151 $GLOBALS['TYPO3_DB']->expects($this->any())->method('fullQuoteStr')
1152 ->will($this->returnCallback(
1153 function($quoteStr, $table) {
1154 return "'" . $quoteStr . "'";
1157 $GLOBALS['TYPO3_DB']->expects($this->any())->method('cleanIntList')
1158 ->will($this->returnCallback(
1159 function($intList) {
1163 $this->assertSame($expected, BackendUtility
::replaceMarkersInWhereClause($whereClause, 'dummytable', 'dummyfield', $tsConfig));
1169 public function replaceMarkersInWhereClauseCleansIdList() {
1170 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
1171 $GLOBALS['TYPO3_DB']->expects($this->once())->method('cleanIntList')->with('1,a,2,b,3,c');
1172 $where = ' AND dummytable.uid IN (###PAGE_TSCONFIG_IDLIST###)';
1174 'dummyfield' => array(
1175 'PAGE_TSCONFIG_IDLIST' => '1,a,2,b,3,c'
1178 BackendUtility
::replaceMarkersInWhereClause($where, 'dummytable', 'dummyfield', $tsConfig);
1184 public function getModTSconfigIgnoresValuesFromUserTsConfigIfNoSet() {
1185 $completeConfiguration = array(
1187 'properties' => array(
1188 'permissions.' => array(
1190 'default.' => array('readAction' => '1'),
1191 '1.' => array('writeAction' => '1'),
1192 '0.' => array('readAction' => '0'),
1198 $GLOBALS['BE_USER'] = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication', array(), array(), '', FALSE);
1199 $GLOBALS['BE_USER']->expects($this->at(0))->method('getTSConfig')->will($this->returnValue($completeConfiguration));
1200 $GLOBALS['BE_USER']->expects($this->at(1))->method('getTSConfig')->will($this->returnValue(array('value' => NULL, 'properties' => NULL)));
1202 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
1203 $className = uniqid('BackendUtility');
1204 $subject = __NAMESPACE__
. '\\' . $className;
1206 'namespace ' . __NAMESPACE__
. ';' .
1207 'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
1208 ' static public function getPagesTSconfig() {' .
1209 ' return array();' .
1214 $this->assertSame($completeConfiguration, $subject::getModTSconfig(42, 'notrelevant'));
1218 * Data provider for replaceL10nModeFieldsReplacesFields
1221 public function replaceL10nModeFieldsReplacesFieldsDataProvider() {
1223 'same table: mergeIfNotBlank' => array(
1228 'field3' => 'trans',
1233 'transOrigPointerTable' => '',
1234 'transOrigPointerField' => 'origUid'
1237 'field2' => array('l10n_mode' => 'mergeIfNotBlank'),
1238 'field3' => array('l10n_mode' => 'mergeIfNotBlank')
1244 'field2' => 'basic',
1249 'field2' => 'basic',
1250 'field3' => 'trans',
1253 'other table: mergeIfNotBlank' => array(
1258 'field3' => 'trans',
1263 'transOrigPointerTable' => 'bar',
1264 'transOrigPointerField' => 'origUid'
1269 'field2' => array('l10n_mode' => 'mergeIfNotBlank'),
1270 'field3' => array('l10n_mode' => 'mergeIfNotBlank')
1276 'field2' => 'basic',
1281 'field2' => 'basic',
1282 'field3' => 'trans',
1285 'same table: exclude' => array(
1290 'field3' => 'trans',
1295 'transOrigPointerTable' => '',
1296 'transOrigPointerField' => 'origUid'
1299 'field2' => array('l10n_mode' => 'exclude'),
1300 'field3' => array('l10n_mode' => 'exclude')
1306 'field2' => 'basic',
1311 'field2' => 'basic',
1315 'other table: exclude' => array(
1320 'field3' => 'trans',
1325 'transOrigPointerTable' => 'bar',
1326 'transOrigPointerField' => 'origUid'
1331 'field2' => array('l10n_mode' => 'exclude'),
1332 'field3' => array('l10n_mode' => 'exclude')
1338 'field2' => 'basic',
1343 'field2' => 'basic',
1352 * @dataProvider replaceL10nModeFieldsReplacesFieldsDataProvider
1354 public function replaceL10nModeFieldsReplacesFields($table, $row, $tca, $originalRow, $expected) {
1355 $GLOBALS['TCA'] = $tca;
1356 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
1357 $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->will($this->returnValue($originalRow));
1359 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
1360 $subject = $this->getAccessibleMock('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('dummy'));
1361 $this->assertSame($expected, $subject->_call('replaceL10nModeFields', $table, $row));