2 namespace TYPO3\CMS\Backend\Tests\Unit\Utility
;
4 /***************************************************************
7 * (c) 2009-2013 Oliver Klee (typo3-coding@oliverklee.de)
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
27 use TYPO3\CMS\Backend\Utility\BackendUtility
;
32 * @author Oliver Klee <typo3-coding@oliverklee.de>
34 class BackendUtilityTest
extends \TYPO3\CMS\Core\Tests\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
121 public function calcAgeReturnsExpectedValues($seconds, $expectedLabel) {
122 $this->assertSame($expectedLabel, BackendUtility
::calcAge($seconds));
125 ///////////////////////////////////////
126 // Tests concerning getProcessedValue
127 ///////////////////////////////////////
130 * @see http://forge.typo3.org/issues/20994
132 public function getProcessedValueForZeroStringIsZero() {
133 $subject = new BackendUtility();
134 $GLOBALS['TCA'] = array(
135 'tt_content' => array(
145 $this->assertEquals('0', $subject->getProcessedValue('tt_content', 'header', '0'));
151 public function getProcessedValueForGroup() {
152 $GLOBALS['TCA'] = array(
153 'tt_content' => array(
155 'multimedia' => array(
163 $this->assertSame('1, 2', BackendUtility
::getProcessedValue('tt_content', 'multimedia', '1,2'));
169 public function getProcessedValueForGroupWithOneAllowedTable() {
170 $GLOBALS['TCA'] = array(
171 'tt_content' => array(
176 'allowed' => 'pages',
177 'internal_type' => 'db',
187 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
188 $subject = $this->getMock('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getRecordWSOL', 'getRecordTitle'));
189 $subject->staticExpects($this->at(0))->method('getRecordWSOL')->will($this->returnValue(array('title' => 'Page 1')));
190 $subject->staticExpects($this->at(1))->method('getRecordTitle')->will($this->returnValue('Page 1'));
191 $subject->staticExpects($this->at(2))->method('getRecordWSOL')->will($this->returnValue(array('title' => 'Page 2')));
192 $subject->staticExpects($this->at(3))->method('getRecordTitle')->will($this->returnValue('Page 2'));
193 $this->assertSame('Page 1, Page 2', $subject->getProcessedValue('tt_content', 'pages', '1,2'));
199 public function getProcessedValueForGroupWithMultipleAllowedTables() {
200 $GLOBALS['TCA'] = array(
201 'sys_category' => array(
206 'internal_type' => 'db',
207 'MM' => 'sys_category_record_mm',
215 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
216 $subject = $this->getMock('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getRecordWSOL', 'getRecordTitle'));
217 $subject->staticExpects($this->at(0))->method('getRecordWSOL')->will($this->returnValue(array('title' => 'Page 1')));
218 $subject->staticExpects($this->at(1))->method('getRecordTitle')->will($this->returnValue('Page 1'));
219 $subject->staticExpects($this->at(2))->method('getRecordWSOL')->will($this->returnValue(array('header' => 'Content 2')));
220 $subject->staticExpects($this->at(3))->method('getRecordTitle')->will($this->returnValue('Content 2'));
221 $this->assertSame('Page 1, Content 2', $subject->getProcessedValue('sys_category', 'items', 'pages_1,tt_content_2'));
225 * Tests concerning getCommonSelectFields
229 * Data provider for getCommonSelectFieldsReturnsCorrectFields
231 * @return array The test data with $table, $prefix, $presetFields, $tca, $expectedFields
233 public function getCommonSelectFieldsReturnsCorrectFieldsDataProvider() {
236 'table' => 'test_table',
238 'presetFields' => array(),
240 'expectedFields' => 'uid'
242 'label set' => array(
243 'table' => 'test_table',
245 'presetFields' => array(),
251 'expectedFields' => 'uid,label'
253 'label_alt set' => array(
254 'table' => 'test_table',
256 'presetFields' => array(),
259 'label_alt' => 'label,label2'
262 'expectedFields' => 'uid,label,label2'
264 'versioningWS set' => array(
265 'table' => 'test_table',
267 'presetFields' => array(),
270 'versioningWS' => '2'
273 'expectedFields' => 'uid,t3ver_id,t3ver_state,t3ver_wsid,t3ver_count'
275 'selicon_field set' => array(
276 'table' => 'test_table',
278 'presetFields' => array(),
281 'selicon_field' => 'field'
284 'expectedFields' => 'uid,field'
286 'typeicon_column set' => array(
287 'table' => 'test_table',
289 'presetFields' => array(),
292 'typeicon_column' => 'field'
295 'expectedFields' => 'uid,field'
297 'enablecolumns set' => array(
298 'table' => 'test_table',
300 'presetFields' => array(),
303 'enablecolumns' => array(
304 'disabled' => 'hidden',
305 'starttime' => 'start',
307 'fe_group' => 'groups'
311 'expectedFields' => 'uid,hidden,start,stop,groups'
313 'label set to uid' => array(
314 'table' => 'test_table',
316 'presetFields' => array(),
322 'expectedFields' => 'uid'
329 * @dataProvider getCommonSelectFieldsReturnsCorrectFieldsDataProvider
331 public function getCommonSelectFieldsReturnsCorrectFields($table, $prefix = '', array $presetFields, array $tca, $expectedFields = '') {
332 $GLOBALS['TCA'][$table] = $tca;
333 $selectFields = BackendUtility
::getCommonSelectFields($table, $prefix, $presetFields);
334 $this->assertEquals($selectFields, $expectedFields);
338 * Tests concerning getLabelFromItemlist
342 * Data provider for getLabelFromItemlistReturnsCorrectFields
344 * @return array The test data with $table, $col, $key, $expectedLabel
346 public function getLabelFromItemlistReturnsCorrectFieldsDataProvider() {
349 'table' => 'tt_content',
350 'col' => 'menu_type',
354 'menu_type' => array(
357 array('Item 1', '0'),
358 array('Item 2', '1'),
365 'expectedLabel' => 'Item 2'
367 'item set twice' => array(
368 'table' => 'tt_content',
369 'col' => 'menu_type',
373 'menu_type' => array(
376 array('Item 1', '0'),
377 array('Item 2a', '1'),
378 array('Item 2b', '1'),
385 'expectedLabel' => 'Item 2a'
387 'item not found' => array(
388 'table' => 'tt_content',
389 'col' => 'menu_type',
393 'menu_type' => array(
396 array('Item 1', '0'),
397 array('Item 2', '1'),
404 'expectedLabel' => NULL
411 * @dataProvider getLabelFromItemlistReturnsCorrectFieldsDataProvider
413 public function getLabelFromItemlistReturnsCorrectFields($table, $col = '', $key = '', array $tca, $expectedLabel = '') {
414 $GLOBALS['TCA'][$table] = $tca;
415 $label = BackendUtility
::getLabelFromItemlist($table, $col, $key);
416 $this->assertEquals($label, $expectedLabel);
420 * Tests concerning getLabelFromItemListMerged
424 * Data provider for getLabelFromItemListMerged
426 * @return array The test data with $pageId, $table, $column, $key, $expectedLabel
428 public function getLabelFromItemListMergedReturnsCorrectFieldsDataProvider() {
430 'no field found' => array(
432 'table' => 'tt_content',
433 'col' => 'menu_type',
437 'menu_type' => array(
440 array('Item 1', '0'),
441 array('Item 2', '1'),
448 'expectedLabel' => ''
450 'no tsconfig set' => array(
452 'table' => 'tt_content',
453 'col' => 'menu_type',
457 'menu_type' => array(
460 array('Item 1', '0'),
461 array('Item 2', '1'),
468 'expectedLabel' => 'Item 2'
475 * @dataProvider getLabelFromItemListMergedReturnsCorrectFieldsDataProvider
477 public function getLabelFromItemListMergedReturnsCorrectFields($pageId, $table, $column = '', $key = '', array $tca, $expectedLabel = '') {
478 $GLOBALS['TCA'][$table] = $tca;
479 /** @var \TYPO3\CMS\Backend\Utility\BackendUtility|\PHPUnit_Framework_MockObject_MockObject $subject */
480 $subject = $this->getMockClass('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getPagesTSconfig'), array(), '', FALSE);
481 $subject::staticExpects($this->once())->method('getPagesTSconfig')->will($this->returnValue(array()));
482 $this->assertEquals($expectedLabel, $subject::getLabelFromItemListMerged($pageId, $table, $column, $key));
486 * Tests concerning getFuncCheck
492 public function getFuncCheckReturnsInputTagWithValueAttribute() {
493 $this->assertStringMatchesFormat('<input %Svalue="1"%S/>', BackendUtility
::getFuncCheck('params', 'test', TRUE));
497 * Tests concerning getLabelsFromItemsList
503 public function getLabelsFromItemsListReturnsValueIfItemIsFound() {
508 'someColumn' => array(
511 '0' => array('aFooLabel', 'foo'),
512 '1' => array('aBarLabel', 'bar')
518 // Stub LanguageService and let sL() return the same value that came in again
519 $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
520 $GLOBALS['LANG']->expects($this->any())->method('sL')
521 ->will($this->returnCallback(
527 $GLOBALS['TCA'][$table] = $tca;
528 $label = BackendUtility
::getLabelsFromItemsList($table, $col, 'foo,bar');
529 $this->assertEquals('aFooLabel, aBarLabel', $label);
535 public function getProcessedValueReturnsLabelsForExistingValuesSolely() {
540 'someColumn' => array(
544 '0' => array('aFooLabel', 'foo'),
545 '1' => array('aBarLabel', 'bar')
551 // Stub LanguageService and let sL() return the same value that came in again
552 $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
553 $GLOBALS['LANG']->charSet
= 'utf-8';
554 $GLOBALS['LANG']->csConvObj
= $this->getMock('TYPO3\\CMS\\Core\\Charset\\CharsetConverter');
555 $GLOBALS['LANG']->expects($this->any())->method('sL')
556 ->will($this->returnCallback(
561 $GLOBALS['LANG']->csConvObj
->expects($this->any())->method('crop')
562 ->will($this->returnCallback(
563 function($charset, $string, $len, $crop = '') {
568 $GLOBALS['TCA'][$table] = $tca;
569 $label = BackendUtility
::getProcessedValue($table, $col, 'foo,invalidKey,bar');
570 $this->assertEquals('aFooLabel, aBarLabel', $label);
576 public function getProcessedValueReturnsPlainValueIfItemIsNotFound() {
581 'someColumn' => array(
585 '0' => array('aFooLabel', 'foo')
591 // Stub LanguageService and let sL() return the same value that came in again
592 $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
593 $GLOBALS['LANG']->charSet
= 'utf-8';
594 $GLOBALS['LANG']->csConvObj
= $this->getMock('TYPO3\\CMS\\Core\\Charset\\CharsetConverter');
595 $GLOBALS['LANG']->expects($this->any())->method('sL')
596 ->will($this->returnCallback(
601 $GLOBALS['LANG']->csConvObj
->expects($this->any())->method('crop')
602 ->will($this->returnCallback(
603 function($charset, $string, $len, $crop = '') {
608 $GLOBALS['TCA'][$table] = $tca;
609 $label = BackendUtility
::getProcessedValue($table, $col, 'invalidKey');
610 $this->assertEquals('invalidKey', $label);
614 * Tests concerning getExcludeFields
620 public function getExcludeFieldsDataProvider() {
622 'getExcludeFields does not return fields not configured as exclude field' => array(
646 'getExcludeFields returns fields from root level tables if root level restriction should be ignored' => array(
653 'ignoreRootLevelRestriction' => TRUE,
671 'getExcludeFields does not return fields from root level tables' => array(
688 'getExcludeFields does not return fields from admin only level tables' => array(
713 * @dataProvider getExcludeFieldsDataProvider
715 public function getExcludeFieldsReturnsCorrectFieldList($tca, $expected) {
716 $GLOBALS['TCA'] = $tca;
718 // Stub LanguageService and let sL() return the same value that came in again
719 $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
720 $GLOBALS['LANG']->expects($this->any())->method('sL')
721 ->will($this->returnCallback(
726 /** @var \TYPO3\CMS\Backend\Utility\BackendUtility|\PHPUnit_Framework_MockObject_MockObject $subject */
727 $subject = $this->getMockClass('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getRegisteredFlexForms'), array(), '', FALSE);
728 $subject::staticExpects($this->any())->method('getRegisteredFlexForms')->will($this->returnValue(array()));
729 $this->assertSame($expected, $subject::getExcludeFields());
735 public function getExcludeFieldsReturnsCorrectListWithFlexFormFields() {
736 $parsedFlexForm = array(
749 'label' => 'The Title:',
765 $GLOBALS['TCA'] = array(
780 'label' => 'abarfoo',
790 'tx_foobar' => array(
822 $expectedResult = array(
832 'abarfoo dummy: The Title:',
833 'tx_foo:abarfoo;dummy;sGeneral;xmlTitle'
853 // Stub LanguageService and let sL() return the same value that came in again
854 $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
855 $GLOBALS['LANG']->expects($this->any())->method('sL')
856 ->will($this->returnCallback(
862 /** @var \TYPO3\CMS\Backend\Utility\BackendUtility|\PHPUnit_Framework_MockObject_MockObject $subject */
863 $subject = $this->getMockClass('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getRegisteredFlexForms'), array(), '', FALSE);
864 $subject::staticExpects($this->at(0))
865 ->method('getRegisteredFlexForms')
866 ->will($this->returnValue(array()));
868 $subject::staticExpects($this->at(1))
869 ->method('getRegisteredFlexForms')
871 ->will($this->returnValue($parsedFlexForm));
873 $subject::staticExpects($this->at(2))
874 ->method('getRegisteredFlexForms')
875 ->will($this->returnValue(array()));
877 $this->assertSame($expectedResult, $subject::getExcludeFields());
881 * Tests concerning viewOnClick
887 public function viewOnClickReturnsOnClickCodeWithAlternativeUrl() {
888 // Make sure the hook inside viewOnClick is not fired. This may be removed if unit tests
889 // bootstrap does not initialize TYPO3_CONF_VARS anymore.
890 unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']);
892 $alternativeUrl = 'https://typo3.org/about/typo3-the-cms/the-history-of-typo3/#section';
893 $onclickCode = 'var previewWin = window.open(\'' . $alternativeUrl . '\',\'newTYPO3frontendWindow\');';
894 $this->assertStringMatchesFormat(
896 BackendUtility
::viewOnClick(NULL, NULL, NULL, NULL, $alternativeUrl, NULL, FALSE)
901 * Tests concerning replaceMarkersInWhereClause
907 public function replaceMarkersInWhereClauseDataProvider() {
909 'replaceMarkersInWhereClause replaces record field marker with quoted string' => array(
910 ' AND dummytable.title=\'###REC_FIELD_dummyfield###\'',
912 '_THIS_ROW' => array(
913 'dummyfield' => 'Hello World'
916 ' AND dummytable.title=\'Hello World\''
918 'replaceMarkersInWhereClause replaces record field marker with fullquoted string' => array(
919 ' AND dummytable.title=###REC_FIELD_dummyfield###',
921 '_THIS_ROW' => array(
922 'dummyfield' => 'Hello World'
925 ' AND dummytable.title=\'Hello World\''
927 'replaceMarkersInWhereClause replaces multiple record field markers' => array(
928 ' AND dummytable.title=\'###REC_FIELD_dummyfield###\' AND dummytable.pid=###REC_FIELD_pid###',
930 '_THIS_ROW' => array(
931 'dummyfield' => 'Hello World',
935 ' AND dummytable.title=\'Hello World\' AND dummytable.pid=\'42\''
937 'replaceMarkersInWhereClause replaces current pid with integer' => array(
938 ' AND dummytable.uid=###CURRENT_PID###',
942 ' AND dummytable.uid=42'
944 'replaceMarkersInWhereClause replaces current pid with string' => array(
945 ' AND dummytable.uid=###CURRENT_PID###',
947 '_CURRENT_PID' => '42string'
949 ' AND dummytable.uid=42'
951 'replaceMarkersInWhereClause replaces current record uid with integer' => array(
952 ' AND dummytable.uid=###THIS_UID###',
956 ' AND dummytable.uid=42'
958 'replaceMarkersInWhereClause replaces current record uid with string' => array(
959 ' AND dummytable.uid=###THIS_UID###',
961 '_THIS_UID' => '42string'
963 ' AND dummytable.uid=42'
965 'replaceMarkersInWhereClause replaces current record cid with integer' => array(
966 ' AND dummytable.uid=###THIS_CID###',
970 ' AND dummytable.uid=42'
972 'replaceMarkersInWhereClause replaces current record cid with string' => array(
973 ' AND dummytable.uid=###THIS_CID###',
975 '_THIS_CID' => '42string'
977 ' AND dummytable.uid=42'
979 'replaceMarkersInWhereClause replaces storage pid with integer' => array(
980 ' AND dummytable.uid=###STORAGE_PID###',
984 ' AND dummytable.uid=42'
986 'replaceMarkersInWhereClause replaces storage pid with string' => array(
987 ' AND dummytable.uid=###STORAGE_PID###',
989 '_STORAGE_PID' => '42string'
991 ' AND dummytable.uid=42'
993 'replaceMarkersInWhereClause replaces siteroot uid with integer' => array(
994 ' AND dummytable.uid=###SITEROOT###',
998 ' AND dummytable.uid=42'
1000 'replaceMarkersInWhereClause replaces siteroot uid with string' => array(
1001 ' AND dummytable.uid=###SITEROOT###',
1003 '_SITEROOT' => '42string'
1005 ' AND dummytable.uid=42'
1007 'replaceMarkersInWhereClause replaces page tsconfig id with integer' => array(
1008 ' AND dummytable.uid=###PAGE_TSCONFIG_ID###',
1010 'dummyfield' => array(
1011 'PAGE_TSCONFIG_ID' => 42
1014 ' AND dummytable.uid=42'
1016 'replaceMarkersInWhereClause replaces page tsconfig id with string' => array(
1017 ' AND dummytable.uid=###PAGE_TSCONFIG_ID###',
1019 'dummyfield' => array(
1020 'PAGE_TSCONFIG_ID' => '42string'
1023 ' AND dummytable.uid=42'
1025 'replaceMarkersInWhereClause replaces page tsconfig string' => array(
1026 ' AND dummytable.title=\'###PAGE_TSCONFIG_STR###\'',
1028 'dummyfield' => array(
1029 'PAGE_TSCONFIG_STR' => '42'
1032 ' AND dummytable.title=\'42\''
1034 'replaceMarkersInWhereClause replaces all markers' => array(
1035 ' AND dummytable.title=\'###REC_FIELD_dummyfield###\'' .
1036 ' AND dummytable.uid=###REC_FIELD_uid###' .
1037 ' AND dummytable.pid=###CURRENT_PID###' .
1038 ' AND dummytable.l18n_parent=###THIS_UID###' .
1039 ' AND dummytable.cid=###THIS_CID###' .
1040 ' AND dummytable.storage_pid=###STORAGE_PID###' .
1041 ' AND dummytable.siteroot=###SITEROOT###' .
1042 ' AND dummytable.config_uid=###PAGE_TSCONFIG_ID###' .
1043 ' AND dummytable.idlist IN (###PAGE_TSCONFIG_IDLIST###)' .
1044 ' AND dummytable.string=\'###PAGE_TSCONFIG_STR###\'',
1046 '_THIS_ROW' => array(
1047 'dummyfield' => 'Hello World',
1050 '_CURRENT_PID' => '1',
1053 '_STORAGE_PID' => 4,
1055 'dummyfield' => array(
1056 'PAGE_TSCONFIG_ID' => 6,
1057 'PAGE_TSCONFIG_IDLIST' => '1,2,3',
1058 'PAGE_TSCONFIG_STR' => 'string'
1061 ' AND dummytable.title=\'Hello World\' AND dummytable.uid=\'42\' AND dummytable.pid=1' .
1062 ' AND dummytable.l18n_parent=2 AND dummytable.cid=3 AND dummytable.storage_pid=4' .
1063 ' AND dummytable.siteroot=5 AND dummytable.config_uid=6 AND dummytable.idlist IN (1,2,3)' .
1064 ' AND dummytable.string=\'string\'',
1071 * @dataProvider replaceMarkersInWhereClauseDataProvider
1073 public function replaceMarkersInWhereClauseReturnsValidWhereClause($whereClause, $tsConfig, $expected) {
1074 // Mock TYPO3_DB and let it return same values that came in
1075 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
1076 $GLOBALS['TYPO3_DB']->expects($this->any())->method('quoteStr')
1077 ->will($this->returnCallback(
1078 function($quoteStr, $table) {
1082 $GLOBALS['TYPO3_DB']->expects($this->any())->method('fullQuoteStr')
1083 ->will($this->returnCallback(
1084 function($quoteStr, $table) {
1085 return "'" . $quoteStr . "'";
1088 $GLOBALS['TYPO3_DB']->expects($this->any())->method('cleanIntList')
1089 ->will($this->returnCallback(
1090 function($intList) {
1094 $this->assertSame($expected, BackendUtility
::replaceMarkersInWhereClause($whereClause, 'dummytable', 'dummyfield', $tsConfig));
1100 public function replaceMarkersInWhereClauseCleansIdList() {
1101 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
1102 $GLOBALS['TYPO3_DB']->expects($this->once())->method('cleanIntList')->with('1,a,2,b,3,c');
1103 $where = ' AND dummytable.uid IN (###PAGE_TSCONFIG_IDLIST###)';
1105 'dummyfield' => array(
1106 'PAGE_TSCONFIG_IDLIST' => '1,a,2,b,3,c'
1109 BackendUtility
::replaceMarkersInWhereClause($whereClause, 'dummytable', 'dummyfield', $tsConfig);
1115 public function getModTSconfigIgnoresValuesFromUserTsConfigIfNoSet() {
1116 $completeConfiguration = array(
1118 'properties' => array(
1119 'permissions.' => array(
1121 'default.' => array('readAction' => '1'),
1122 '1.' => array('writeAction' => '1'),
1123 '0.' => array('readAction' => '0'),
1129 $GLOBALS['BE_USER'] = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication', array(), array(), '', FALSE);
1130 $GLOBALS['BE_USER']->expects($this->at(0))->method('getTSConfig')->will($this->returnValue($completeConfiguration));
1131 $GLOBALS['BE_USER']->expects($this->at(1))->method('getTSConfig')->will($this->returnValue(array('value' => NULL, 'properties' => NULL)));
1133 /** @var \TYPO3\CMS\Backend\Utility\BackendUtility|\PHPUnit_Framework_MockObject_MockObject $subject */
1134 $subject = $this->getMockClass('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getPagesTSconfig'), array(), '', FALSE);
1135 $subject::staticExpects($this->any())->method('getPagesTSconfig')->will($this->returnValue(array()));
1137 $this->assertSame($completeConfiguration, $subject::getModTSconfig(42, 'notrelevant'));
1141 * Data provider for replaceL10nModeFieldsReplacesFields
1144 public function replaceL10nModeFieldsReplacesFieldsDataProvider() {
1146 'same table: mergeIfNotBlank' => array(
1151 'field3' => 'trans',
1156 'transOrigPointerTable' => '',
1157 'transOrigPointerField' => 'origUid'
1160 'field2' => array('l10n_mode' => 'mergeIfNotBlank'),
1161 'field3' => array('l10n_mode' => 'mergeIfNotBlank')
1167 'field2' => 'basic',
1172 'field2' => 'basic',
1173 'field3' => 'trans',
1176 'other table: mergeIfNotBlank' => array(
1181 'field3' => 'trans',
1186 'transOrigPointerTable' => 'bar',
1187 'transOrigPointerField' => 'origUid'
1192 'field2' => array('l10n_mode' => 'mergeIfNotBlank'),
1193 'field3' => array('l10n_mode' => 'mergeIfNotBlank')
1199 'field2' => 'basic',
1204 'field2' => 'basic',
1205 'field3' => 'trans',
1208 'same table: exclude' => array(
1213 'field3' => 'trans',
1218 'transOrigPointerTable' => '',
1219 'transOrigPointerField' => 'origUid'
1222 'field2' => array('l10n_mode' => 'exclude'),
1223 'field3' => array('l10n_mode' => 'exclude')
1229 'field2' => 'basic',
1234 'field2' => 'basic',
1238 'other table: exclude' => array(
1243 'field3' => 'trans',
1248 'transOrigPointerTable' => 'bar',
1249 'transOrigPointerField' => 'origUid'
1254 'field2' => array('l10n_mode' => 'exclude'),
1255 'field3' => array('l10n_mode' => 'exclude')
1261 'field2' => 'basic',
1266 'field2' => 'basic',
1275 * @dataProvider replaceL10nModeFieldsReplacesFieldsDataProvider
1277 public function replaceL10nModeFieldsReplacesFields($table, $row, $tca, $originalRow, $expected) {
1278 $GLOBALS['TCA'] = $tca;
1279 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
1280 $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_fetch_assoc')->will($this->returnValue($originalRow));
1282 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\TYPO3\CMS\Backend\Utility\BackendUtility $subject */
1283 $subject = $this->getAccessibleMock('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('dummy'));
1284 $this->assertSame($expected, $subject->_call('replaceL10nModeFields', $table, $row));