TYPO3 CMS  TYPO3_6-2
BackendUtilityTest.php
Go to the documentation of this file.
1 <?php
3 
18 
25 
27  // Tests concerning calcAge
29 
34  public function calcAgeDataProvider() {
35  return array(
36  'Single year' => array(
37  'seconds' => 60 * 60 * 24 * 365,
38  'expectedLabel' => '1 year'
39  ),
40  'Plural years' => array(
41  'seconds' => 60 * 60 * 24 * 365 * 2,
42  'expectedLabel' => '2 yrs'
43  ),
44  'Single negative year' => array(
45  'seconds' => 60 * 60 * 24 * 365 * -1,
46  'expectedLabel' => '-1 year'
47  ),
48  'Plural negative years' => array(
49  'seconds' => 60 * 60 * 24 * 365 * 2 * -1,
50  'expectedLabel' => '-2 yrs'
51  ),
52  'Single day' => array(
53  'seconds' => 60 * 60 * 24,
54  'expectedLabel' => '1 day'
55  ),
56  'Plural days' => array(
57  'seconds' => 60 * 60 * 24 * 2,
58  'expectedLabel' => '2 days'
59  ),
60  'Single negative day' => array(
61  'seconds' => 60 * 60 * 24 * -1,
62  'expectedLabel' => '-1 day'
63  ),
64  'Plural negative days' => array(
65  'seconds' => 60 * 60 * 24 * 2 * -1,
66  'expectedLabel' => '-2 days'
67  ),
68  'Single hour' => array(
69  'seconds' => 60 * 60,
70  'expectedLabel' => '1 hour'
71  ),
72  'Plural hours' => array(
73  'seconds' => 60 * 60 * 2,
74  'expectedLabel' => '2 hrs'
75  ),
76  'Single negative hour' => array(
77  'seconds' => 60 * 60 * -1,
78  'expectedLabel' => '-1 hour'
79  ),
80  'Plural negative hours' => array(
81  'seconds' => 60 * 60 * 2 * -1,
82  'expectedLabel' => '-2 hrs'
83  ),
84  'Single minute' => array(
85  'seconds' => 60,
86  'expectedLabel' => '1 min'
87  ),
88  'Plural minutes' => array(
89  'seconds' => 60 * 2,
90  'expectedLabel' => '2 min'
91  ),
92  'Single negative minute' => array(
93  'seconds' => 60 * -1,
94  'expectedLabel' => '-1 min'
95  ),
96  'Plural negative minutes' => array(
97  'seconds' => 60 * 2 * -1,
98  'expectedLabel' => '-2 min'
99  ),
100  'Zero seconds' => array(
101  'seconds' => 0,
102  'expectedLabel' => '0 min'
103  )
104  );
105  }
106 
111  public function calcAgeReturnsExpectedValues($seconds, $expectedLabel) {
112  $this->assertSame($expectedLabel, BackendUtility::calcAge($seconds));
113  }
114 
116  // Tests concerning getProcessedValue
118 
123  $GLOBALS['TCA'] = array(
124  'tt_content' => array(
125  'columns' => array(
126  'header' => array(
127  'config' => array(
128  'type' => 'input',
129  ),
130  ),
131  ),
132  ),
133  );
134  $this->assertEquals('0', BackendUtility::getProcessedValue('tt_content', 'header', '0'));
135  }
136 
140  public function getProcessedValueForGroup() {
141  $GLOBALS['TCA'] = array(
142  'tt_content' => array(
143  'columns' => array(
144  'multimedia' => array(
145  'config' => array(
146  'type' => 'group',
147  ),
148  ),
149  ),
150  ),
151  );
152  $this->assertSame('1, 2', BackendUtility::getProcessedValue('tt_content', 'multimedia', '1,2'));
153  }
154 
158  public function getProcessedValueForGroupWithOneAllowedTable() {
159  // Disable getRecordWSOL and getRecordTitle dependency by returning stable results
161  $className = $this->getUniqueId('BackendUtility');
162  $subject = __NAMESPACE__ . '\\' . $className;
163  eval(
164  'namespace ' . __NAMESPACE__ . ';' .
165  'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
166  ' static public function getRecordWSOL() {' .
167  ' static $called = 0;' .
168  ' ++$called;' .
169  ' if ($called === 1) {' .
170  ' return array(\'title\' => \'Page 1\');' .
171  ' }' .
172  ' if ($called === 2) {' .
173  ' return array(\'title\' => \'Page 2\');' .
174  ' }' .
175  ' }' .
176  ' static public function getRecordTitle() {' .
177  ' static $called = 0;' .
178  ' ++$called;' .
179  ' if ($called === 1) {' .
180  ' return \'Page 1\';' .
181  ' }' .
182  ' if ($called === 2) {' .
183  ' return \'Page 2\';' .
184  ' }' .
185  ' }' .
186  '}'
187  );
188 
189  $GLOBALS['TCA'] = array(
190  'tt_content' => array(
191  'columns' => array(
192  'pages' => array(
193  'config' => array(
194  'type' => 'group',
195  'allowed' => 'pages',
196  'internal_type' => 'db',
197  'maxitems' => 22,
198  'minitems' => 0,
199  'show_thumbs' => 1,
200  'size' => 3,
201  ),
202  ),
203  ),
204  ),
205  );
206 
207  $this->assertSame('Page 1, Page 2', $subject::getProcessedValue('tt_content', 'pages', '1,2'));
208  }
209 
213  public function getProcessedValueForGroupWithMultipleAllowedTables() {
214  // Disable getRecordWSOL and getRecordTitle dependency by returning stable results
216  $className = $this->getUniqueId('BackendUtility');
217  $subject = __NAMESPACE__ . '\\' . $className;
218  eval(
219  'namespace ' . __NAMESPACE__ . ';' .
220  'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
221  ' static public function getRecordWSOL() {' .
222  ' static $called = 0;' .
223  ' ++$called;' .
224  ' if ($called === 1) {' .
225  ' return array(\'title\' => \'Page 1\');' .
226  ' }' .
227  ' if ($called === 2) {' .
228  ' return array(\'header\' => \'Configuration 2\');' .
229  ' }' .
230  ' }' .
231  ' static public function getRecordTitle() {' .
232  ' static $called = 0;' .
233  ' ++$called;' .
234  ' if ($called === 1) {' .
235  ' return \'Page 1\';' .
236  ' }' .
237  ' if ($called === 2) {' .
238  ' return \'Configuration 2\';' .
239  ' }' .
240  ' }' .
241  '}'
242  );
243 
244  $GLOBALS['TCA'] = array(
245  'index_config' => array(
246  'columns' => array(
247  'indexcfgs' => array(
248  'config' => array(
249  'type' => 'group',
250  'internal_type' => 'db',
251  'allowed' => 'index_config,pages',
252  'size' => 5,
253  ),
254  ),
255  ),
256  ),
257  );
258 
259  $this->assertSame('Page 1, Configuration 2', $subject::getProcessedValue('index_config', 'indexcfgs', 'pages_1,index_config_2'));
260  }
261 
265  public function getProcessedValueForSelectWithMMRelation() {
266  $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
267  $GLOBALS['TYPO3_DB']->expects($this->any())->method('fullQuoteStr')
268  ->will($this->returnCallback(
269  function($quoteStr, $table) {
270  return "'" . $quoteStr . "'";
271  }
272  ));
273  $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTquery')->will($this->returnValue(0));
274  $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_free_result');
275  $GLOBALS['TYPO3_DB']->expects($this->any())->method('sql_fetch_assoc')
276  ->will($this->returnCallback(
277  function($res) {
278  static $called = 0;
279  ++$called;
280  switch ($called) {
281  // SELECT * FROM sys_category_record_mm
282  case 1:
283  return array(
284  'uid_local' => 1, // uid of a sys_category record
285  'uid_foreign' => 1, // uid of a pages record
286  );
287  case 2:
288  return array(
289  'uid_local' => 2, // uid of a sys_category record
290  'uid_foreign' => 1, // uid of a pages record
291  );
292  case 3:
293  return NULL;
294  // SELECT * FROM sys_catgory
295  case 4:
296  return array(
297  'uid' => 1,
298  'title' => 'Category 1',
299  );
300  case 5:
301  return array(
302  'uid' => 2,
303  'title' => 'Category 2',
304  );
305  case 6:
306  return NULL;
307  }
308  }
309  ));
310 
311  // Disable getRecordTitle dependency by returning stable results
313  $className = $this->getUniqueId('BackendUtility');
314  $subject = __NAMESPACE__ . '\\' . $className;
315  eval(
316  'namespace ' . __NAMESPACE__ . ';' .
317  'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
318  ' static public function getRecordTitle($table, $row) {' .
319  ' return $row["title"];' .
320  ' }' .
321  '}'
322  );
323 
324  $GLOBALS['TCA'] = array(
325  'pages' => array(
326  'columns' => array(
327  'categories' => array(
328  'config' => array(
329  'type' => 'select',
330  'foreign_table' => 'sys_category',
331  'MM' => 'sys_category_record_mm',
332  'MM_match_fields' => array(
333  'fieldname' => 'categories',
334  'tablesnames' => 'pages',
335  ),
336  'MM_opposite_field' => 'items',
337  ),
338  ),
339  ),
340  ),
341  'sys_category' => array(
342  'columns' => array(
343  'items' => array(
344  'config' => array(
345  'type' => 'group',
346  'internal_type' => 'db',
347  'allowed' => '*',
348  'MM' => 'sys_category_record_mm',
349  'MM_oppositeUsage' => array(),
350  )
351  )
352  ),
353  ),
354  );
355 
356  $this->assertSame('Category 1; Category 2', $subject::getProcessedValue('pages', 'categories', '2', 0, FALSE, FALSE, 1));
357  }
358 
369  return array(
370  'only uid' => array(
371  'table' => 'test_table',
372  'prefix' => '',
373  'presetFields' => array(),
374  'tca' => array(),
375  'expectedFields' => 'uid'
376  ),
377  'label set' => array(
378  'table' => 'test_table',
379  'prefix' => '',
380  'presetFields' => array(),
381  'tca' => array(
382  'ctrl' => array(
383  'label' => 'label'
384  )
385  ),
386  'expectedFields' => 'uid,label'
387  ),
388  'label_alt set' => array(
389  'table' => 'test_table',
390  'prefix' => '',
391  'presetFields' => array(),
392  'tca' => array(
393  'ctrl' => array(
394  'label_alt' => 'label,label2'
395  )
396  ),
397  'expectedFields' => 'uid,label,label2'
398  ),
399  'versioningWS set' => array(
400  'table' => 'test_table',
401  'prefix' => '',
402  'presetFields' => array(),
403  'tca' => array(
404  'ctrl' => array(
405  'versioningWS' => '2'
406  )
407  ),
408  'expectedFields' => 'uid,t3ver_id,t3ver_state,t3ver_wsid,t3ver_count'
409  ),
410  'selicon_field set' => array(
411  'table' => 'test_table',
412  'prefix' => '',
413  'presetFields' => array(),
414  'tca' => array(
415  'ctrl' => array(
416  'selicon_field' => 'field'
417  )
418  ),
419  'expectedFields' => 'uid,field'
420  ),
421  'typeicon_column set' => array(
422  'table' => 'test_table',
423  'prefix' => '',
424  'presetFields' => array(),
425  'tca' => array(
426  'ctrl' => array(
427  'typeicon_column' => 'field'
428  )
429  ),
430  'expectedFields' => 'uid,field'
431  ),
432  'enablecolumns set' => array(
433  'table' => 'test_table',
434  'prefix' => '',
435  'presetFields' => array(),
436  'tca' => array(
437  'ctrl' => array(
438  'enablecolumns' => array(
439  'disabled' => 'hidden',
440  'starttime' => 'start',
441  'endtime' => 'stop',
442  'fe_group' => 'groups'
443  )
444  )
445  ),
446  'expectedFields' => 'uid,hidden,start,stop,groups'
447  ),
448  'label set to uid' => array(
449  'table' => 'test_table',
450  'prefix' => '',
451  'presetFields' => array(),
452  'tca' => array(
453  'ctrl' => array(
454  'label' => 'uid'
455  )
456  ),
457  'expectedFields' => 'uid'
458  )
459  );
460  }
461 
466  public function getCommonSelectFieldsReturnsCorrectFields($table, $prefix = '', array $presetFields, array $tca, $expectedFields = '') {
467  $GLOBALS['TCA'][$table] = $tca;
468  $selectFields = BackendUtility::getCommonSelectFields($table, $prefix, $presetFields);
469  $this->assertEquals($selectFields, $expectedFields);
470  }
471 
482  return array(
483  'item set' => array(
484  'table' => 'tt_content',
485  'col' => 'menu_type',
486  'key' => '1',
487  'tca' => array(
488  'columns' => array(
489  'menu_type' => array(
490  'config' => array(
491  'items' => array(
492  array('Item 1', '0'),
493  array('Item 2', '1'),
494  array('Item 3', '3')
495  )
496  )
497  )
498  )
499  ),
500  'expectedLabel' => 'Item 2'
501  ),
502  'item set twice' => array(
503  'table' => 'tt_content',
504  'col' => 'menu_type',
505  'key' => '1',
506  'tca' => array(
507  'columns' => array(
508  'menu_type' => array(
509  'config' => array(
510  'items' => array(
511  array('Item 1', '0'),
512  array('Item 2a', '1'),
513  array('Item 2b', '1'),
514  array('Item 3', '3')
515  )
516  )
517  )
518  )
519  ),
520  'expectedLabel' => 'Item 2a'
521  ),
522  'item not found' => array(
523  'table' => 'tt_content',
524  'col' => 'menu_type',
525  'key' => '5',
526  'tca' => array(
527  'columns' => array(
528  'menu_type' => array(
529  'config' => array(
530  'items' => array(
531  array('Item 1', '0'),
532  array('Item 2', '1'),
533  array('Item 3', '2')
534  )
535  )
536  )
537  )
538  ),
539  'expectedLabel' => NULL
540  )
541  );
542  }
543 
548  public function getLabelFromItemlistReturnsCorrectFields($table, $col = '', $key = '', array $tca, $expectedLabel = '') {
549  $GLOBALS['TCA'][$table] = $tca;
550  $label = BackendUtility::getLabelFromItemlist($table, $col, $key);
551  $this->assertEquals($label, $expectedLabel);
552  }
553 
564  return array(
565  'no field found' => array(
566  'pageId' => '123',
567  'table' => 'tt_content',
568  'col' => 'menu_type',
569  'key' => '10',
570  'tca' => array(
571  'columns' => array(
572  'menu_type' => array(
573  'config' => array(
574  'items' => array(
575  array('Item 1', '0'),
576  array('Item 2', '1'),
577  array('Item 3', '3')
578  )
579  )
580  )
581  )
582  ),
583  'expectedLabel' => ''
584  ),
585  'no tsconfig set' => array(
586  'pageId' => '123',
587  'table' => 'tt_content',
588  'col' => 'menu_type',
589  'key' => '1',
590  'tca' => array(
591  'columns' => array(
592  'menu_type' => array(
593  'config' => array(
594  'items' => array(
595  array('Item 1', '0'),
596  array('Item 2', '1'),
597  array('Item 3', '3')
598  )
599  )
600  )
601  )
602  ),
603  'expectedLabel' => 'Item 2'
604  )
605  );
606  }
607 
612  public function getLabelFromItemListMergedReturnsCorrectFields($pageId, $table, $column = '', $key = '', array $tca, $expectedLabel = '') {
613  // Disable getPagesTSconfig by returning stable result
615  $className = $this->getUniqueId('BackendUtility');
616  $subject = __NAMESPACE__ . '\\' . $className;
617  eval(
618  'namespace ' . __NAMESPACE__ . ';' .
619  'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
620  ' static public function getPagesTSconfig() {' .
621  ' return array();' .
622  ' }' .
623  '}'
624  );
625 
626  $GLOBALS['TCA'][$table] = $tca;
627 
628  $this->assertEquals($expectedLabel, $subject::getLabelFromItemListMerged($pageId, $table, $column, $key));
629  }
630 
639  $this->assertStringMatchesFormat('<input %Svalue="1"%S/>', BackendUtility::getFuncCheck('params', 'test', TRUE));
640  }
641 
650  $table = 'foobar';
651  $col = 'someColumn';
652  $tca = array(
653  'columns' => array(
654  'someColumn' => array(
655  'config' => array(
656  'items' => array(
657  '0' => array('aFooLabel', 'foo'),
658  '1' => array('aBarLabel', 'bar')
659  )
660  )
661  )
662  )
663  );
664  // Stub LanguageService and let sL() return the same value that came in again
665  $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
666  $GLOBALS['LANG']->expects($this->any())->method('sL')
667  ->will($this->returnCallback(
668  function($name) {
669  return $name;
670  }
671  ));
672 
673  $GLOBALS['TCA'][$table] = $tca;
674  $label = BackendUtility::getLabelsFromItemsList($table, $col, 'foo,bar');
675  $this->assertEquals('aFooLabel, aBarLabel', $label);
676  }
677 
682  $table = 'foobar';
683  $col = 'someColumn';
684  $tca = array(
685  'columns' => array(
686  'someColumn' => array(
687  'config' => array(
688  'type' => 'select',
689  'items' => array(
690  '0' => array('aFooLabel', 'foo'),
691  '1' => array('aBarLabel', 'bar')
692  )
693  )
694  )
695  )
696  );
697  // Stub LanguageService and let sL() return the same value that came in again
698  $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
699  $GLOBALS['LANG']->charSet = 'utf-8';
700  $GLOBALS['LANG']->csConvObj = $this->getMock('TYPO3\\CMS\\Core\\Charset\\CharsetConverter');
701  $GLOBALS['LANG']->expects($this->any())->method('sL')
702  ->will($this->returnCallback(
703  function($name) {
704  return $name;
705  }
706  ));
707  $GLOBALS['LANG']->csConvObj->expects($this->any())->method('crop')
708  ->will($this->returnCallback(
709  function($charset, $string, $len, $crop = '') {
710  return $string;
711  }
712  ));
713 
714  $GLOBALS['TCA'][$table] = $tca;
715  $label = BackendUtility::getProcessedValue($table, $col, 'foo,invalidKey,bar');
716  $this->assertEquals('aFooLabel, aBarLabel', $label);
717  }
718 
723  $table = 'foobar';
724  $col = 'someColumn';
725  $tca = array(
726  'columns' => array(
727  'someColumn' => array(
728  'config' => array(
729  'type' => 'select',
730  'items' => array(
731  '0' => array('aFooLabel', 'foo')
732  )
733  )
734  )
735  )
736  );
737  // Stub LanguageService and let sL() return the same value that came in again
738  $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
739  $GLOBALS['LANG']->charSet = 'utf-8';
740  $GLOBALS['LANG']->csConvObj = $this->getMock('TYPO3\\CMS\\Core\\Charset\\CharsetConverter');
741  $GLOBALS['LANG']->expects($this->any())->method('sL')
742  ->will($this->returnCallback(
743  function($name) {
744  return $name;
745  }
746  ));
747  $GLOBALS['LANG']->csConvObj->expects($this->any())->method('crop')
748  ->will($this->returnCallback(
749  function($charset, $string, $len, $crop = '') {
750  return $string;
751  }
752  ));
753 
754  $GLOBALS['TCA'][$table] = $tca;
755  $label = BackendUtility::getProcessedValue($table, $col, 'invalidKey');
756  $this->assertEquals('invalidKey', $label);
757  }
758 
766  public function getExcludeFieldsDataProvider() {
767  return array(
768  'getExcludeFields does not return fields not configured as exclude field' => array(
769  array(
770  'tx_foo' => array(
771  'ctrl' => array(
772  'title' => 'foo',
773  ),
774  'columns' => array(
775  'bar' => array(
776  'label' => 'bar',
777  'exclude' => 1
778  ),
779  'baz' => array(
780  'label' => 'bar',
781  ),
782  )
783  )
784  ),
785  array(
786  array(
787  'foo: bar',
788  'tx_foo:bar',
789  ),
790  )
791  ),
792  'getExcludeFields returns fields from root level tables if root level restriction should be ignored' => array(
793  array(
794  'tx_foo' => array(
795  'ctrl' => array(
796  'title' => 'foo',
797  'rootLevel' => TRUE,
798  'security' => array(
799  'ignoreRootLevelRestriction' => TRUE,
800  ),
801  ),
802  'columns' => array(
803  'bar' => array(
804  'label' => 'bar',
805  'exclude' => 1
806  ),
807  )
808  )
809  ),
810  array(
811  array(
812  'foo: bar',
813  'tx_foo:bar',
814  ),
815  )
816  ),
817  'getExcludeFields does not return fields from root level tables' => array(
818  array(
819  'tx_foo' => array(
820  'ctrl' => array(
821  'title' => 'foo',
822  'rootLevel' => TRUE,
823  ),
824  'columns' => array(
825  'bar' => array(
826  'label' => 'bar',
827  'exclude' => 1
828  ),
829  )
830  )
831  ),
832  array()
833  ),
834  'getExcludeFields does not return fields from admin only level tables' => array(
835  array(
836  'tx_foo' => array(
837  'ctrl' => array(
838  'title' => 'foo',
839  'adminOnly' => TRUE,
840  ),
841  'columns' => array(
842  'bar' => array(
843  'label' => 'bar',
844  'exclude' => 1
845  ),
846  )
847  )
848  ),
849  array()
850  ),
851  );
852  }
853 
861  public function getExcludeFieldsReturnsCorrectFieldList($tca, $expected) {
863  $className = $this->getUniqueId('BackendUtility');
864  $subject = __NAMESPACE__ . '\\' . $className;
865  eval(
866  'namespace ' . __NAMESPACE__ . ';' .
867  'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
868  ' static public function getRegisteredFlexForms() {' .
869  ' return array();' .
870  ' }' .
871  '}'
872  );
873 
874  $GLOBALS['TCA'] = $tca;
875 
876  // Stub LanguageService and let sL() return the same value that came in again
877  $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
878  $GLOBALS['LANG']->expects($this->any())->method('sL')
879  ->will($this->returnCallback(
880  function($name) {
881  return $name;
882  }
883  ));
884 
885  $this->assertSame($expected, $subject::getExcludeFields());
886  }
887 
891  public function getExcludeFieldsReturnsCorrectListWithFlexFormFields() {
892  $GLOBALS['TCA'] = array(
893  'tx_foo' => array(
894  'ctrl' => array(
895  'title' => 'foo'
896  ),
897  'columns' => array(
898  'foo' => array(
899  'label' => 'foo',
900  'exclude' => 1
901  ),
902  'bar' => array(
903  'label' => 'bar',
904  'exclude' => 1
905  ),
906  'abarfoo' => array(
907  'label' => 'abarfoo',
908  'config' => array(
909  'type' => 'flex',
910  'ds' => array(
911  '*,dummy' => '',
912  )
913  )
914  )
915  )
916  ),
917  'tx_foobar' => array(
918  'ctrl' => array(
919  'title' => 'foobar'
920  ),
921  'columns' => array(
922  'foo' => array(
923  'label' => 'foo',
924  'exclude' => 1
925  ),
926  'bar' => array(
927  'label' => 'bar',
928  'exclude' => 1
929  )
930  )
931  ),
932  'tx_bar' => array(
933  'ctrl' => array(
934  'title' => 'bar'
935  ),
936  'columns' => array(
937  'foo' => array(
938  'label' => 'foo',
939  'exclude' => 1
940  ),
941  'bar' => array(
942  'label' => 'bar',
943  'exclude' => 1
944  )
945  )
946  )
947  );
948 
949  $expectedResult = array(
950  array(
951  'bar: bar',
952  'tx_bar:bar'
953  ),
954  array(
955  'bar: foo',
956  'tx_bar:foo'
957  ),
958  array(
959  'abarfoo dummy: The Title:',
960  'tx_foo:abarfoo;dummy;sGeneral;xmlTitle'
961  ),
962  array(
963  'foo: bar',
964  'tx_foo:bar'
965  ),
966  array(
967  'foo: foo',
968  'tx_foo:foo'
969  ),
970  array(
971  'foobar: bar',
972  'tx_foobar:bar'
973  ),
974  array(
975  'foobar: foo',
976  'tx_foobar:foo'
977  ),
978  );
979 
980  // Stub LanguageService and let sL() return the same value that came in again
981  $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
982  $GLOBALS['LANG']->expects($this->any())->method('sL')
983  ->will($this->returnCallback(
984  function($name) {
985  return $name;
986  }
987  ));
988 
990  $className = $this->getUniqueId('BackendUtility');
991  $subject = __NAMESPACE__ . '\\' . $className;
992  eval(
993  'namespace ' . __NAMESPACE__ . ';' .
994  'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
995  ' static public function getRegisteredFlexForms($table) {' .
996  ' static $called = 0;' .
997  ' ++$called;' .
998  ' if ($called === 1) {' .
999  ' return array();' .
1000  ' }' .
1001  ' if ($called === 2) {' .
1002  ' if ($table !== \'tx_foo\') {' .
1003  ' throw new Exception(\'Expected tx_foo as argument on call 2\', 1399638572);' .
1004  ' }' .
1005  ' $parsedFlexForm = array(' .
1006  ' \'abarfoo\' => array(' .
1007  ' \'dummy\' => array(' .
1008  ' \'title\' => \'dummy\',' .
1009  ' \'ds\' => array(' .
1010  ' \'sheets\' => array(' .
1011  ' \'sGeneral\' => array(' .
1012  ' \'ROOT\' => array(' .
1013  ' \'type\' => \'array\',' .
1014  ' \'el\' => array(' .
1015  ' \'xmlTitle\' => array(' .
1016  ' \'TCEforms\' => array(' .
1017  ' \'exclude\' => 1,' .
1018  ' \'label\' => \'The Title:\',' .
1019  ' \'config\' => array(' .
1020  ' \'type\' => \'input\',' .
1021  ' \'size\' => 48,' .
1022  ' ),' .
1023  ' ),' .
1024  ' ),' .
1025  ' ),' .
1026  ' ),' .
1027  ' ),' .
1028  ' ),' .
1029  ' ),' .
1030  ' ),' .
1031  ' ),' .
1032  ' );' .
1033  ' return $parsedFlexForm;' .
1034  ' }' .
1035  ' if ($called === 3) {' .
1036  ' return array();' .
1037  ' }' .
1038  ' }' .
1039  '}'
1040  );
1041 
1042  $this->assertSame($expectedResult, $subject::getExcludeFields());
1043  }
1044 
1053  // Make sure the hook inside viewOnClick is not fired. This may be removed if unit tests
1054  // bootstrap does not initialize TYPO3_CONF_VARS anymore.
1055  unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']);
1056 
1057  $alternativeUrl = 'https://typo3.org/about/typo3-the-cms/the-history-of-typo3/#section';
1058  $onclickCode = 'var previewWin = window.open(\'' . $alternativeUrl . '\',\'newTYPO3frontendWindow\');';
1059  $this->assertStringMatchesFormat(
1060  $onclickCode,
1061  BackendUtility::viewOnClick(NULL, NULL, NULL, NULL, $alternativeUrl, NULL, FALSE)
1062  );
1063  }
1064 
1073  return array(
1074  'replaceMarkersInWhereClause replaces record field marker with quoted string' => array(
1075  ' AND dummytable.title=\'###REC_FIELD_dummyfield###\'',
1076  array(
1077  '_THIS_ROW' => array(
1078  'dummyfield' => 'Hello World'
1079  )
1080  ),
1081  ' AND dummytable.title=\'Hello World\''
1082  ),
1083  'replaceMarkersInWhereClause replaces record field marker with fullquoted string' => array(
1084  ' AND dummytable.title=###REC_FIELD_dummyfield###',
1085  array(
1086  '_THIS_ROW' => array(
1087  'dummyfield' => 'Hello World'
1088  )
1089  ),
1090  ' AND dummytable.title=\'Hello World\''
1091  ),
1092  'replaceMarkersInWhereClause replaces multiple record field markers' => array(
1093  ' AND dummytable.title=\'###REC_FIELD_dummyfield###\' AND dummytable.pid=###REC_FIELD_pid###',
1094  array(
1095  '_THIS_ROW' => array(
1096  'dummyfield' => 'Hello World',
1097  'pid' => 42
1098  )
1099  ),
1100  ' AND dummytable.title=\'Hello World\' AND dummytable.pid=\'42\''
1101  ),
1102  'replaceMarkersInWhereClause replaces current pid with integer' => array(
1103  ' AND dummytable.uid=###CURRENT_PID###',
1104  array(
1105  '_CURRENT_PID' => 42
1106  ),
1107  ' AND dummytable.uid=42'
1108  ),
1109  'replaceMarkersInWhereClause replaces current pid with string' => array(
1110  ' AND dummytable.uid=###CURRENT_PID###',
1111  array(
1112  '_CURRENT_PID' => '42string'
1113  ),
1114  ' AND dummytable.uid=42'
1115  ),
1116  'replaceMarkersInWhereClause replaces current record uid with integer' => array(
1117  ' AND dummytable.uid=###THIS_UID###',
1118  array(
1119  '_THIS_UID' => 42
1120  ),
1121  ' AND dummytable.uid=42'
1122  ),
1123  'replaceMarkersInWhereClause replaces current record uid with string' => array(
1124  ' AND dummytable.uid=###THIS_UID###',
1125  array(
1126  '_THIS_UID' => '42string'
1127  ),
1128  ' AND dummytable.uid=42'
1129  ),
1130  'replaceMarkersInWhereClause replaces current record cid with integer' => array(
1131  ' AND dummytable.uid=###THIS_CID###',
1132  array(
1133  '_THIS_CID' => 42
1134  ),
1135  ' AND dummytable.uid=42'
1136  ),
1137  'replaceMarkersInWhereClause replaces current record cid with string' => array(
1138  ' AND dummytable.uid=###THIS_CID###',
1139  array(
1140  '_THIS_CID' => '42string'
1141  ),
1142  ' AND dummytable.uid=42'
1143  ),
1144  'replaceMarkersInWhereClause replaces storage pid with integer' => array(
1145  ' AND dummytable.uid=###STORAGE_PID###',
1146  array(
1147  '_STORAGE_PID' => 42
1148  ),
1149  ' AND dummytable.uid=42'
1150  ),
1151  'replaceMarkersInWhereClause replaces storage pid with string' => array(
1152  ' AND dummytable.uid=###STORAGE_PID###',
1153  array(
1154  '_STORAGE_PID' => '42string'
1155  ),
1156  ' AND dummytable.uid=42'
1157  ),
1158  'replaceMarkersInWhereClause replaces siteroot uid with integer' => array(
1159  ' AND dummytable.uid=###SITEROOT###',
1160  array(
1161  '_SITEROOT' => 42
1162  ),
1163  ' AND dummytable.uid=42'
1164  ),
1165  'replaceMarkersInWhereClause replaces siteroot uid with string' => array(
1166  ' AND dummytable.uid=###SITEROOT###',
1167  array(
1168  '_SITEROOT' => '42string'
1169  ),
1170  ' AND dummytable.uid=42'
1171  ),
1172  'replaceMarkersInWhereClause replaces page tsconfig id with integer' => array(
1173  ' AND dummytable.uid=###PAGE_TSCONFIG_ID###',
1174  array(
1175  'dummyfield' => array(
1176  'PAGE_TSCONFIG_ID' => 42
1177  )
1178  ),
1179  ' AND dummytable.uid=42'
1180  ),
1181  'replaceMarkersInWhereClause replaces page tsconfig id with string' => array(
1182  ' AND dummytable.uid=###PAGE_TSCONFIG_ID###',
1183  array(
1184  'dummyfield' => array(
1185  'PAGE_TSCONFIG_ID' => '42string'
1186  )
1187  ),
1188  ' AND dummytable.uid=42'
1189  ),
1190  'replaceMarkersInWhereClause replaces page tsconfig string' => array(
1191  ' AND dummytable.title=\'###PAGE_TSCONFIG_STR###\'',
1192  array(
1193  'dummyfield' => array(
1194  'PAGE_TSCONFIG_STR' => '42'
1195  )
1196  ),
1197  ' AND dummytable.title=\'42\''
1198  ),
1199  'replaceMarkersInWhereClause replaces all markers' => array(
1200  ' AND dummytable.title=\'###REC_FIELD_dummyfield###\'' .
1201  ' AND dummytable.uid=###REC_FIELD_uid###' .
1202  ' AND dummytable.pid=###CURRENT_PID###' .
1203  ' AND dummytable.l18n_parent=###THIS_UID###' .
1204  ' AND dummytable.cid=###THIS_CID###' .
1205  ' AND dummytable.storage_pid=###STORAGE_PID###' .
1206  ' AND dummytable.siteroot=###SITEROOT###' .
1207  ' AND dummytable.config_uid=###PAGE_TSCONFIG_ID###' .
1208  ' AND dummytable.idlist IN (###PAGE_TSCONFIG_IDLIST###)' .
1209  ' AND dummytable.string=\'###PAGE_TSCONFIG_STR###\'',
1210  array(
1211  '_THIS_ROW' => array(
1212  'dummyfield' => 'Hello World',
1213  'uid' => 42
1214  ),
1215  '_CURRENT_PID' => '1',
1216  '_THIS_UID' => 2,
1217  '_THIS_CID' => 3,
1218  '_STORAGE_PID' => 4,
1219  '_SITEROOT' => 5,
1220  'dummyfield' => array(
1221  'PAGE_TSCONFIG_ID' => 6,
1222  'PAGE_TSCONFIG_IDLIST' => '1,2,3',
1223  'PAGE_TSCONFIG_STR' => 'string'
1224  )
1225  ),
1226  ' AND dummytable.title=\'Hello World\' AND dummytable.uid=\'42\' AND dummytable.pid=1' .
1227  ' AND dummytable.l18n_parent=2 AND dummytable.cid=3 AND dummytable.storage_pid=4' .
1228  ' AND dummytable.siteroot=5 AND dummytable.config_uid=6 AND dummytable.idlist IN (1,2,3)' .
1229  ' AND dummytable.string=\'string\'',
1230  ),
1231  );
1232  }
1233 
1238  public function replaceMarkersInWhereClauseReturnsValidWhereClause($whereClause, $tsConfig, $expected) {
1239  // Mock TYPO3_DB and let it return same values that came in
1240  $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
1241  $GLOBALS['TYPO3_DB']->expects($this->any())->method('quoteStr')
1242  ->will($this->returnCallback(
1243  function($quoteStr, $table) {
1244  return $quoteStr;
1245  }
1246  ));
1247  $GLOBALS['TYPO3_DB']->expects($this->any())->method('fullQuoteStr')
1248  ->will($this->returnCallback(
1249  function($quoteStr, $table) {
1250  return "'" . $quoteStr . "'";
1251  }
1252  ));
1253  $GLOBALS['TYPO3_DB']->expects($this->any())->method('cleanIntList')
1254  ->will($this->returnCallback(
1255  function($intList) {
1256  return $intList;
1257  }
1258  ));
1259  $this->assertSame($expected, BackendUtility::replaceMarkersInWhereClause($whereClause, 'dummytable', 'dummyfield', $tsConfig));
1260  }
1261 
1266  $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
1267  $GLOBALS['TYPO3_DB']->expects($this->once())->method('cleanIntList')->with('1,a,2,b,3,c');
1268  $where = ' AND dummytable.uid IN (###PAGE_TSCONFIG_IDLIST###)';
1269  $tsConfig = array(
1270  'dummyfield' => array(
1271  'PAGE_TSCONFIG_IDLIST' => '1,a,2,b,3,c'
1272  ),
1273  );
1274  BackendUtility::replaceMarkersInWhereClause($where, 'dummytable', 'dummyfield', $tsConfig);
1275  }
1276 
1280  public function getModTSconfigIgnoresValuesFromUserTsConfigIfNoSet() {
1281  $completeConfiguration = array(
1282  'value' => 'bar',
1283  'properties' => array(
1284  'permissions.' => array(
1285  'file.' => array(
1286  'default.' => array('readAction' => '1'),
1287  '1.' => array('writeAction' => '1'),
1288  '0.' => array('readAction' => '0'),
1289  ),
1290  )
1291  )
1292  );
1293 
1294  $GLOBALS['BE_USER'] = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication', array(), array(), '', FALSE);
1295  $GLOBALS['BE_USER']->expects($this->at(0))->method('getTSConfig')->will($this->returnValue($completeConfiguration));
1296  $GLOBALS['BE_USER']->expects($this->at(1))->method('getTSConfig')->will($this->returnValue(array('value' => NULL, 'properties' => NULL)));
1297 
1299  $className = $this->getUniqueId('BackendUtility');
1300  $subject = __NAMESPACE__ . '\\' . $className;
1301  eval(
1302  'namespace ' . __NAMESPACE__ . ';' .
1303  'class ' . $className . ' extends \\TYPO3\\CMS\\Backend\\Utility\\BackendUtility {' .
1304  ' static public function getPagesTSconfig() {' .
1305  ' return array();' .
1306  ' }' .
1307  '}'
1308  );
1309 
1310  $this->assertSame($completeConfiguration, $subject::getModTSconfig(42, 'notrelevant'));
1311  }
1312 
1318  return array(
1319  'same table: mergeIfNotBlank' => array(
1320  'foo',
1321  array(
1322  'origUid' => 1,
1323  'field2' => 'fdas',
1324  'field3' => 'trans',
1325  ),
1326  array(
1327  'foo' => array(
1328  'ctrl' => array(
1329  'transOrigPointerTable' => '',
1330  'transOrigPointerField' => 'origUid'
1331  ),
1332  'columns' => array(
1333  'field2' => array('l10n_mode' => 'mergeIfNotBlank'),
1334  'field3' => array('l10n_mode' => 'mergeIfNotBlank')
1335  )
1336  )
1337  ),
1338  array(
1339  'origUid' => 0,
1340  'field2' => 'basic',
1341  'field3' => '',
1342  ),
1343  array(
1344  'origUid' => 1,
1345  'field2' => 'fdas',
1346  'field3' => 'trans',
1347  )
1348  ),
1349  'other table: mergeIfNotBlank' => array(
1350  'foo',
1351  array(
1352  'origUid' => 1,
1353  'field2' => '',
1354  'field3' => 'trans',
1355  ),
1356  array(
1357  'foo' => array(
1358  'ctrl' => array(
1359  'transOrigPointerTable' => 'bar',
1360  'transOrigPointerField' => 'origUid'
1361  )
1362  ),
1363  'bar' => array(
1364  'columns' => array(
1365  'field2' => array('l10n_mode' => 'mergeIfNotBlank'),
1366  'field3' => array('l10n_mode' => 'mergeIfNotBlank')
1367  )
1368  )
1369  ),
1370  array(
1371  'origUid' => 0,
1372  'field2' => 'basic',
1373  'field3' => '',
1374  ),
1375  array(
1376  'origUid' => 1,
1377  'field2' => 'basic',
1378  'field3' => 'trans',
1379  )
1380  ),
1381  'same table: exclude' => array(
1382  'foo',
1383  array(
1384  'origUid' => 1,
1385  'field2' => 'fdas',
1386  'field3' => 'trans',
1387  ),
1388  array(
1389  'foo' => array(
1390  'ctrl' => array(
1391  'transOrigPointerTable' => '',
1392  'transOrigPointerField' => 'origUid'
1393  ),
1394  'columns' => array(
1395  'field2' => array('l10n_mode' => 'exclude'),
1396  'field3' => array('l10n_mode' => 'exclude')
1397  )
1398  )
1399  ),
1400  array(
1401  'origUid' => 0,
1402  'field2' => 'basic',
1403  'field3' => '',
1404  ),
1405  array(
1406  'origUid' => 1,
1407  'field2' => 'basic',
1408  'field3' => '',
1409  )
1410  ),
1411  'other table: exclude' => array(
1412  'foo',
1413  array(
1414  'origUid' => 1,
1415  'field2' => 'fdas',
1416  'field3' => 'trans',
1417  ),
1418  array(
1419  'foo' => array(
1420  'ctrl' => array(
1421  'transOrigPointerTable' => 'bar',
1422  'transOrigPointerField' => 'origUid'
1423  )
1424  ),
1425  'bar' => array(
1426  'columns' => array(
1427  'field2' => array('l10n_mode' => 'exclude'),
1428  'field3' => array('l10n_mode' => 'exclude')
1429  )
1430  )
1431  ),
1432  array(
1433  'origUid' => 0,
1434  'field2' => 'basic',
1435  'field3' => '',
1436  ),
1437  array(
1438  'origUid' => 1,
1439  'field2' => 'basic',
1440  'field3' => '',
1441  )
1442  ),
1443  );
1444  }
1445 
1450  public function replaceL10nModeFieldsReplacesFields($table, $row, $tca, $originalRow, $expected) {
1451  $GLOBALS['TCA'] = $tca;
1452  $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
1453  $GLOBALS['TYPO3_DB']->expects($this->any())->method('exec_SELECTgetSingleRow')->will($this->returnValue($originalRow));
1454 
1456  $subject = $this->getAccessibleMock('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('dummy'));
1457  $this->assertSame($expected, $subject->_call('replaceL10nModeFields', $table, $row));
1458  }
1459 }
static getFuncCheck($mainParams, $elementName, $currentValue, $script='', $addParams='', $tagParams='')
replaceMarkersInWhereClauseReturnsValidWhereClause($whereClause, $tsConfig, $expected)
static replaceMarkersInWhereClause($whereClause, $table, $field='', $tsConfig=array())
static calcAge($seconds, $labels=' min|hrs|days|yrs|min|hour|day|year')
static viewOnClick($pageUid, $backPath='', $rootLine='', $anchorSection='', $alternativeUrl='', $additionalGetVars='', $switchFocus=TRUE)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
getCommonSelectFieldsReturnsCorrectFields($table, $prefix='', array $presetFields, array $tca, $expectedFields='')
static getCommonSelectFields($table, $prefix='', $fields=array())
getLabelFromItemlistReturnsCorrectFields($table, $col='', $key='', array $tca, $expectedLabel='')
static getLabelsFromItemsList($table, $column, $key)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getLabelFromItemlist($table, $col, $key)