[BUGFIX] getLabelsFromItemsList() retuns no value when no item found
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Utility / BackendUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2013 Oliver Klee (typo3-coding@oliverklee.de)
8 * All rights reserved
9 *
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.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
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.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use TYPO3\CMS\Backend\Utility\BackendUtility;
28
29 /**
30 * Testcase for \TYPO3\CMS\Core\Utility\BackendUtility
31 *
32 * @author Oliver Klee <typo3-coding@oliverklee.de>
33 */
34 class BackendUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
35
36 /**
37 * @var \TYPO3\CMS\Backend\Utility\BackendUtility
38 */
39 private $fixture;
40
41 public function setUp() {
42 $this->fixture = new BackendUtility();
43 }
44
45 public function tearDown() {
46 unset($this->fixture);
47 }
48
49 ///////////////////////////////////////
50 // Tests concerning calcAge
51 ///////////////////////////////////////
52 /**
53 * Data provider for calcAge function
54 *
55 * @return array
56 */
57 public function calcAgeDataProvider() {
58 return array(
59 'Single year' => array(
60 'seconds' => 60 * 60 * 24 * 365,
61 'expectedLabel' => '1 year'
62 ),
63 'Plural years' => array(
64 'seconds' => 60 * 60 * 24 * 365 * 2,
65 'expectedLabel' => '2 yrs'
66 ),
67 'Single negative year' => array(
68 'seconds' => 60 * 60 * 24 * 365 * -1,
69 'expectedLabel' => '-1 year'
70 ),
71 'Plural negative years' => array(
72 'seconds' => 60 * 60 * 24 * 365 * 2 * -1,
73 'expectedLabel' => '-2 yrs'
74 ),
75 'Single day' => array(
76 'seconds' => 60 * 60 * 24,
77 'expectedLabel' => '1 day'
78 ),
79 'Plural days' => array(
80 'seconds' => 60 * 60 * 24 * 2,
81 'expectedLabel' => '2 days'
82 ),
83 'Single negative day' => array(
84 'seconds' => 60 * 60 * 24 * -1,
85 'expectedLabel' => '-1 day'
86 ),
87 'Plural negative days' => array(
88 'seconds' => 60 * 60 * 24 * 2 * -1,
89 'expectedLabel' => '-2 days'
90 ),
91 'Single hour' => array(
92 'seconds' => 60 * 60,
93 'expectedLabel' => '1 hour'
94 ),
95 'Plural hours' => array(
96 'seconds' => 60 * 60 * 2,
97 'expectedLabel' => '2 hrs'
98 ),
99 'Single negative hour' => array(
100 'seconds' => 60 * 60 * -1,
101 'expectedLabel' => '-1 hour'
102 ),
103 'Plural negative hours' => array(
104 'seconds' => 60 * 60 * 2 * -1,
105 'expectedLabel' => '-2 hrs'
106 ),
107 'Single minute' => array(
108 'seconds' => 60,
109 'expectedLabel' => '1 min'
110 ),
111 'Plural minutes' => array(
112 'seconds' => 60 * 2,
113 'expectedLabel' => '2 min'
114 ),
115 'Single negative minute' => array(
116 'seconds' => 60 * -1,
117 'expectedLabel' => '-1 min'
118 ),
119 'Plural negative minutes' => array(
120 'seconds' => 60 * 2 * -1,
121 'expectedLabel' => '-2 min'
122 ),
123 'Zero seconds' => array(
124 'seconds' => 0,
125 'expectedLabel' => '0 min'
126 )
127 );
128 }
129
130 /**
131 * @test
132 * @dataProvider calcAgeDataProvider
133 */
134 public function calcAgeReturnsExpectedValues($seconds, $expectedLabel) {
135 $this->assertSame($expectedLabel, $this->fixture->calcAge($seconds));
136 }
137
138 ///////////////////////////////////////
139 // Tests concerning getProcessedValue
140 ///////////////////////////////////////
141 /**
142 * @test
143 * @see http://forge.typo3.org/issues/20994
144 */
145 public function getProcessedValueForZeroStringIsZero() {
146 $this->assertEquals('0', $this->fixture->getProcessedValue('tt_content', 'header', '0'));
147 }
148
149 /**
150 * @test
151 */
152 public function getProcessedValueForGroup() {
153 $this->assertSame('1, 2', $this->fixture->getProcessedValue('tt_content', 'multimedia', '1,2'));
154 }
155
156 /**
157 * @test
158 */
159 public function getProcessedValueForGroupWithOneAllowedTable() {
160 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $fixture */
161 $fixture = $this->getMock('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getRecordWSOL'));
162 $fixture->staticExpects($this->at(0))->method('getRecordWSOL')->will($this->returnValue(array('title' => 'Page 1')));
163 $fixture->staticExpects($this->at(1))->method('getRecordWSOL')->will($this->returnValue(array('title' => 'Page 2')));
164 $this->assertSame('Page 1, Page 2', $fixture->getProcessedValue('tt_content', 'pages', '1,2'));
165 }
166
167 /**
168 * @test
169 */
170 public function getProcessedValueForGroupWithMultipleAllowedTables() {
171 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $fixture */
172 $fixture = $this->getMock('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getRecordWSOL'));
173 $fixture->staticExpects($this->at(0))->method('getRecordWSOL')->will($this->returnValue(array('title' => 'Page 1')));
174 $fixture->staticExpects($this->at(1))->method('getRecordWSOL')->will($this->returnValue(array('header' => 'Content 2')));
175 $this->assertSame('Page 1, Content 2', $fixture->getProcessedValue('sys_category', 'items', 'pages_1,tt_content_2'));
176 }
177
178 /**
179 * Tests concerning getCommenSelectFields
180 */
181
182 /**
183 * Data provider for getCommonSelectFieldsReturnsCorrectFields
184 *
185 * @return array The test data with $table, $prefix, $presetFields, $tca, $expectedFields
186 */
187 public function getCommonSelectFieldsReturnsCorrectFieldsDataProvider() {
188 return array(
189 'only uid' => array(
190 'table' => 'test_table',
191 'prefix' => '',
192 'presetFields' => array(),
193 'tca' => array(),
194 'expectedFields' => 'uid'
195 ),
196 'label set' => array(
197 'table' => 'test_table',
198 'prefix' => '',
199 'presetFields' => array(),
200 'tca' => array(
201 'ctrl' => array(
202 'label' => 'label'
203 )
204 ),
205 'expectedFields' => 'uid,label'
206 ),
207 'label_alt set' => array(
208 'table' => 'test_table',
209 'prefix' => '',
210 'presetFields' => array(),
211 'tca' => array(
212 'ctrl' => array(
213 'label_alt' => 'label,label2'
214 )
215 ),
216 'expectedFields' => 'uid,label,label2'
217 ),
218 'versioningWS set' => array(
219 'table' => 'test_table',
220 'prefix' => '',
221 'presetFields' => array(),
222 'tca' => array(
223 'ctrl' => array(
224 'versioningWS' => '2'
225 )
226 ),
227 'expectedFields' => 'uid,t3ver_id,t3ver_state,t3ver_wsid,t3ver_count'
228 ),
229 'selicon_field set' => array(
230 'table' => 'test_table',
231 'prefix' => '',
232 'presetFields' => array(),
233 'tca' => array(
234 'ctrl' => array(
235 'selicon_field' => 'field'
236 )
237 ),
238 'expectedFields' => 'uid,field'
239 ),
240 'typeicon_column set' => array(
241 'table' => 'test_table',
242 'prefix' => '',
243 'presetFields' => array(),
244 'tca' => array(
245 'ctrl' => array(
246 'typeicon_column' => 'field'
247 )
248 ),
249 'expectedFields' => 'uid,field'
250 ),
251 'enablecolumns set' => array(
252 'table' => 'test_table',
253 'prefix' => '',
254 'presetFields' => array(),
255 'tca' => array(
256 'ctrl' => array(
257 'enablecolumns' => array(
258 'disabled' => 'hidden',
259 'starttime' => 'start',
260 'endtime' => 'stop',
261 'fe_group' => 'groups'
262 )
263 )
264 ),
265 'expectedFields' => 'uid,hidden,start,stop,groups'
266 ),
267 'label set to uid' => array(
268 'table' => 'test_table',
269 'prefix' => '',
270 'presetFields' => array(),
271 'tca' => array(
272 'ctrl' => array(
273 'label' => 'uid'
274 )
275 ),
276 'expectedFields' => 'uid'
277 )
278 );
279 }
280
281 /**
282 * @test
283 * @dataProvider getCommonSelectFieldsReturnsCorrectFieldsDataProvider
284 */
285 public function getCommonSelectFieldsReturnsCorrectFields($table, $prefix = '', array $presetFields, array $tca, $expectedFields = '') {
286 $tcaBackup = $GLOBALS['TCA'][$table];
287 unset($GLOBALS['TCA'][$table]);
288 $GLOBALS['TCA'][$table] = $tca;
289 $selectFields = $this->fixture->getCommonSelectFields($table, $prefix, $presetFields);
290 unset($GLOBALS['TCA'][$table]);
291 $GLOBALS['TCA'][$table] = $tcaBackup;
292 $this->assertEquals($selectFields, $expectedFields);
293 }
294
295 /**
296 * Tests concerning getLabelFromItemlist
297 */
298
299 /**
300 * Data provider for getLabelFromItemlistReturnsCorrectFields
301 *
302 * @return array The test data with $table, $col, $key, $expectedLabel
303 */
304 public function getLabelFromItemlistReturnsCorrectFieldsDataProvider() {
305 return array(
306 'item set' => array(
307 'table' => 'tt_content',
308 'col' => 'menu_type',
309 'key' => '1',
310 'tca' => array(
311 'columns' => array(
312 'menu_type' => array(
313 'config' => array(
314 'items' => array(
315 array('Item 1', '0'),
316 array('Item 2', '1'),
317 array('Item 3', '3')
318 )
319 )
320 )
321 )
322 ),
323 'expectedLabel' => 'Item 2'
324 ),
325 'item set twice' => array(
326 'table' => 'tt_content',
327 'col' => 'menu_type',
328 'key' => '1',
329 'tca' => array(
330 'columns' => array(
331 'menu_type' => array(
332 'config' => array(
333 'items' => array(
334 array('Item 1', '0'),
335 array('Item 2a', '1'),
336 array('Item 2b', '1'),
337 array('Item 3', '3')
338 )
339 )
340 )
341 )
342 ),
343 'expectedLabel' => 'Item 2a'
344 ),
345 'item not found' => array(
346 'table' => 'tt_content',
347 'col' => 'menu_type',
348 'key' => '5',
349 'tca' => array(
350 'columns' => array(
351 'menu_type' => array(
352 'config' => array(
353 'items' => array(
354 array('Item 1', '0'),
355 array('Item 2', '1'),
356 array('Item 3', '2')
357 )
358 )
359 )
360 )
361 ),
362 'expectedLabel' => NULL
363 )
364 );
365 }
366
367 /**
368 * @test
369 * @dataProvider getLabelFromItemlistReturnsCorrectFieldsDataProvider
370 */
371 public function getLabelFromItemlistReturnsCorrectFields($table, $col = '', $key = '', array $tca, $expectedLabel = '') {
372 $tcaBackup = $GLOBALS['TCA'][$table];
373 unset($GLOBALS['TCA'][$table]);
374 $GLOBALS['TCA'][$table] = $tca;
375 $label = $this->fixture->getLabelFromItemlist($table, $col, $key);
376 unset($GLOBALS['TCA'][$table]);
377 $GLOBALS['TCA'][$table] = $tcaBackup;
378 $this->assertEquals($label, $expectedLabel);
379 }
380
381 /**
382 * Tests concerning getLabelFromItemListMerged
383 */
384
385 /**
386 * Data provider for getLabelFromItemListMerged
387 *
388 * @return array The test data with $pageId, $table, $column, $key, $expectedLabel
389 */
390 public function getLabelFromItemListMergedReturnsCorrectFieldsDataProvider() {
391 return array(
392 'no field found' => array(
393 'pageId' => '123',
394 'table' => 'tt_content',
395 'col' => 'menu_type',
396 'key' => '10',
397 'tca' => array(
398 'columns' => array(
399 'menu_type' => array(
400 'config' => array(
401 'items' => array(
402 array('Item 1', '0'),
403 array('Item 2', '1'),
404 array('Item 3', '3')
405 )
406 )
407 )
408 )
409 ),
410 'expectedLabel' => ''
411 ),
412 'no tsconfig set' => array(
413 'pageId' => '123',
414 'table' => 'tt_content',
415 'col' => 'menu_type',
416 'key' => '1',
417 'tca' => array(
418 'columns' => array(
419 'menu_type' => array(
420 'config' => array(
421 'items' => array(
422 array('Item 1', '0'),
423 array('Item 2', '1'),
424 array('Item 3', '3')
425 )
426 )
427 )
428 )
429 ),
430 'expectedLabel' => 'Item 2'
431 )
432 );
433 }
434
435 /**
436 * @test
437 * @dataProvider getLabelFromItemListMergedReturnsCorrectFieldsDataProvider
438 */
439 public function getLabelFromItemListMergedReturnsCorrectFields($pageId, $table, $column = '', $key = '', array $tca, $expectedLabel = '') {
440 $tcaBackup = $GLOBALS['TCA'][$table];
441 unset($GLOBALS['TCA'][$table]);
442 $GLOBALS['TCA'][$table] = $tca;
443 $label = $this->fixture->getLabelFromItemListMerged($pageId, $table, $column, $key);
444 unset($GLOBALS['TCA'][$table]);
445 $GLOBALS['TCA'][$table] = $tcaBackup;
446 $this->assertEquals($label, $expectedLabel);
447 }
448
449 /**
450 * Tests concerning getFuncCheck
451 */
452
453 /**
454 * @test
455 */
456 public function getFuncCheckReturnsInputTagWithValueAttribute() {
457 $this->assertStringMatchesFormat('<input %Svalue="1"%S/>', BackendUtility::getFuncCheck('params', 'test', TRUE));
458 }
459
460 /**
461 * Tests concerning getLabelsFromItemsList
462 */
463
464 /**
465 * @test
466 */
467 public function getLabelsFromItemsListReturnsValueIfItemIsFound() {
468 $table = 'foobar';
469 $col = 'someColumn';
470 $tca = array(
471 'columns' => array(
472 'someColumn' => array(
473 'config' => array(
474 'items' => array(
475 '0' => array('aFooLabel', 'foo'),
476 '1' => array('aBarLabel', 'bar')
477 )
478 )
479 )
480 )
481 );
482
483 $tcaBackup = $GLOBALS['TCA'][$table];
484 unset($GLOBALS['TCA'][$table]);
485 $GLOBALS['TCA'][$table] = $tca;
486 $label = $this->fixture->getLabelsFromItemsList($table, $col, 'foo,bar');
487 unset($GLOBALS['TCA'][$table]);
488 $GLOBALS['TCA'][$table] = $tcaBackup;
489 $this->assertEquals('aFooLabel, aBarLabel', $label);
490 }
491
492 /**
493 * @test
494 */
495 public function getLabelsFromItemsListReturnsPlainValueIfItemIsNotFound() {
496 $table = 'foobar';
497 $col = 'someColumn';
498 $tca = array(
499 'columns' => array(
500 'someColumn' => array(
501 'config' => array(
502 'items' => array(
503 '0' => array('aFooLabel', 'foo')
504 )
505 )
506 )
507 )
508 );
509
510 $tcaBackup = $GLOBALS['TCA'][$table];
511 unset($GLOBALS['TCA'][$table]);
512 $GLOBALS['TCA'][$table] = $tca;
513 $label = $this->fixture->getLabelsFromItemsList($table, $col, 'foo,something,missing');
514 unset($GLOBALS['TCA'][$table]);
515 $GLOBALS['TCA'][$table] = $tcaBackup;
516 $this->assertEquals('aFooLabel, something, missing', $label);
517 }
518
519 /**
520 * Tests concerning getExcludeFields
521 */
522
523 /**
524 * @return array
525 */
526 public function getExcludeFieldsDataProvider() {
527 return array(
528 'getExcludeFields does not return fields not configured as exclude field' => array(
529 array(
530 'tx_foo' => array(
531 'ctrl' => array(
532 'title' => 'foo',
533 ),
534 'columns' => array(
535 'bar' => array(
536 'label' => 'bar',
537 'exclude' => 1
538 ),
539 'baz' => array(
540 'label' => 'bar',
541 ),
542 )
543 )
544 ),
545 array(
546 array(
547 'foo: bar',
548 'tx_foo:bar',
549 ),
550 )
551 ),
552 'getExcludeFields returns fields from root level tables if root level restriction should be ignored' => array(
553 array(
554 'tx_foo' => array(
555 'ctrl' => array(
556 'title' => 'foo',
557 'rootLevel' => TRUE,
558 'security' => array(
559 'ignoreRootLevelRestriction' => TRUE,
560 ),
561 ),
562 'columns' => array(
563 'bar' => array(
564 'label' => 'bar',
565 'exclude' => 1
566 ),
567 )
568 )
569 ),
570 array(
571 array(
572 'foo: bar',
573 'tx_foo:bar',
574 ),
575 )
576 ),
577 'getExcludeFields does not return fields from root level tables' => array(
578 array(
579 'tx_foo' => array(
580 'ctrl' => array(
581 'title' => 'foo',
582 'rootLevel' => TRUE,
583 ),
584 'columns' => array(
585 'bar' => array(
586 'label' => 'bar',
587 'exclude' => 1
588 ),
589 )
590 )
591 ),
592 array()
593 ),
594 'getExcludeFields does not return fields from admin only level tables' => array(
595 array(
596 'tx_foo' => array(
597 'ctrl' => array(
598 'title' => 'foo',
599 'adminOnly' => TRUE,
600 ),
601 'columns' => array(
602 'bar' => array(
603 'label' => 'bar',
604 'exclude' => 1
605 ),
606 )
607 )
608 ),
609 array()
610 ),
611 'getExcludeFields sorts tables and properties with flexform fields properly' => array(
612 array(
613 'tx_foo' => array(
614 'ctrl' => array(
615 'title' => 'foo'
616 ),
617 'columns' => array(
618 'foo' => array(
619 'label' => 'foo',
620 'exclude' => 1
621 ),
622 'bar' => array(
623 'label' => 'bar',
624 'exclude' => 1
625 ),
626 'abarfoo' => array(
627 'label' => 'abarfoo',
628 'config' => array(
629 'type' => 'flex',
630 'ds' => array(
631 '*,dummy' => '<?xml version="1.0" encoding="utf-8"?>
632 <T3DataStructure>
633 <sheets>
634 <sGeneral>
635 <ROOT>
636 <type>array</type>
637 <el>
638 <xmlTitle>
639 <TCEforms>
640 <exclude>1</exclude>
641 <label>The Title:</label>
642 <config>
643 <type>input</type>
644 <size>48</size>
645 </config>
646 </TCEforms>
647 </xmlTitle>
648 </el>
649 </ROOT>
650 </sGeneral>
651 </sheets>
652 </T3DataStructure>'
653 )
654 )
655 )
656 )
657 ),
658 'tx_foobar' => array(
659 'ctrl' => array(
660 'title' => 'foobar'
661 ),
662 'columns' => array(
663 'foo' => array(
664 'label' => 'foo',
665 'exclude' => 1
666 ),
667 'bar' => array(
668 'label' => 'bar',
669 'exclude' => 1
670 )
671 )
672 ),
673 'tx_bar' => array(
674 'ctrl' => array(
675 'title' => 'bar'
676 ),
677 'columns' => array(
678 'foo' => array(
679 'label' => 'foo',
680 'exclude' => 1
681 ),
682 'bar' => array(
683 'label' => 'bar',
684 'exclude' => 1
685 )
686 )
687 )
688 ),
689 array(
690 array(
691 'bar: bar',
692 'tx_bar:bar'
693 ),
694 array(
695 'bar: foo',
696 'tx_bar:foo'
697 ),
698 array(
699 'abarfoo dummy: The Title:',
700 'tx_foo:abarfoo;dummy;sGeneral;xmlTitle'
701 ),
702 array(
703 'foo: bar',
704 'tx_foo:bar'
705 ),
706 array(
707 'foo: foo',
708 'tx_foo:foo'
709 ),
710 array(
711 'foobar: bar',
712 'tx_foobar:bar'
713 ),
714 array(
715 'foobar: foo',
716 'tx_foobar:foo'
717 ),
718 )
719 )
720 );
721 }
722
723 /**
724 * @param $tca
725 * @param $expected
726 *
727 * @test
728 * @dataProvider getExcludeFieldsDataProvider
729 */
730 public function getExcludeFieldsReturnsCorrectFieldList($tca, $expected) {
731 $GLOBALS['TCA'] = $tca;
732
733 // Stub LanguageService and let sL() return the same value that came in again
734 $GLOBALS['LANG'] = $this->getMock('TYPO3\\CMS\\Lang\\LanguageService', array(), array(), '', FALSE);
735 $GLOBALS['LANG']->expects($this->any())->method('sL')
736 ->will($this->returnCallback(
737 function($name) {
738 return $name;
739 }
740 ));
741
742 $this->assertSame($expected, BackendUtility::getExcludeFields());
743 }
744
745 /**
746 * Tests concerning viewOnClick
747 */
748
749 /**
750 * @test
751 */
752 public function viewOnClickReturnsOnClickCodeWithAlternativeUrl() {
753 // Make sure the hook inside viewOnClick is not fired. This may be removed if unit tests
754 // bootstrap does not initialize TYPO3_CONF_VARS anymore.
755 unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']);
756
757 $alternativeUrl = 'https://typo3.org/about/typo3-the-cms/the-history-of-typo3/#section';
758 $onclickCode = 'var previewWin = window.open(\'' . $alternativeUrl . '\',\'newTYPO3frontendWindow\');';
759 $this->assertStringMatchesFormat(
760 $onclickCode,
761 BackendUtility::viewOnClick(NULL, NULL, NULL, NULL, $alternativeUrl, NULL, FALSE)
762 );
763 }
764
765 /**
766 * Tests concerning replaceMarkersInWhereClause
767 */
768
769 /**
770 * @return array
771 */
772 public function replaceMarkersInWhereClauseDataProvider() {
773 return array(
774 'replaceMarkersInWhereClause replaces record field marker with quoted string' => array(
775 ' AND dummytable.title=\'###REC_FIELD_dummyfield###\'',
776 array(
777 '_THIS_ROW' => array(
778 'dummyfield' => 'Hello World'
779 )
780 ),
781 ' AND dummytable.title=\'Hello World\''
782 ),
783 'replaceMarkersInWhereClause replaces record field marker with fullquoted string' => array(
784 ' AND dummytable.title=###REC_FIELD_dummyfield###',
785 array(
786 '_THIS_ROW' => array(
787 'dummyfield' => 'Hello World'
788 )
789 ),
790 ' AND dummytable.title=\'Hello World\''
791 ),
792 'replaceMarkersInWhereClause replaces multiple record field markers' => array(
793 ' AND dummytable.title=\'###REC_FIELD_dummyfield###\' AND dummytable.pid=###REC_FIELD_pid###',
794 array(
795 '_THIS_ROW' => array(
796 'dummyfield' => 'Hello World',
797 'pid' => 42
798 )
799 ),
800 ' AND dummytable.title=\'Hello World\' AND dummytable.pid=\'42\''
801 ),
802 'replaceMarkersInWhereClause replaces current pid with integer' => array(
803 ' AND dummytable.uid=###CURRENT_PID###',
804 array(
805 '_CURRENT_PID' => 42
806 ),
807 ' AND dummytable.uid=42'
808 ),
809 'replaceMarkersInWhereClause replaces current pid with string' => array(
810 ' AND dummytable.uid=###CURRENT_PID###',
811 array(
812 '_CURRENT_PID' => '42string'
813 ),
814 ' AND dummytable.uid=42'
815 ),
816 'replaceMarkersInWhereClause replaces current record uid with integer' => array(
817 ' AND dummytable.uid=###THIS_UID###',
818 array(
819 '_THIS_UID' => 42
820 ),
821 ' AND dummytable.uid=42'
822 ),
823 'replaceMarkersInWhereClause replaces current record uid with string' => array(
824 ' AND dummytable.uid=###THIS_UID###',
825 array(
826 '_THIS_UID' => '42string'
827 ),
828 ' AND dummytable.uid=42'
829 ),
830 'replaceMarkersInWhereClause replaces current record cid with integer' => array(
831 ' AND dummytable.uid=###THIS_CID###',
832 array(
833 '_THIS_CID' => 42
834 ),
835 ' AND dummytable.uid=42'
836 ),
837 'replaceMarkersInWhereClause replaces current record cid with string' => array(
838 ' AND dummytable.uid=###THIS_CID###',
839 array(
840 '_THIS_CID' => '42string'
841 ),
842 ' AND dummytable.uid=42'
843 ),
844 'replaceMarkersInWhereClause replaces storage pid with integer' => array(
845 ' AND dummytable.uid=###STORAGE_PID###',
846 array(
847 '_STORAGE_PID' => 42
848 ),
849 ' AND dummytable.uid=42'
850 ),
851 'replaceMarkersInWhereClause replaces storage pid with string' => array(
852 ' AND dummytable.uid=###STORAGE_PID###',
853 array(
854 '_STORAGE_PID' => '42string'
855 ),
856 ' AND dummytable.uid=42'
857 ),
858 'replaceMarkersInWhereClause replaces siteroot uid with integer' => array(
859 ' AND dummytable.uid=###SITEROOT###',
860 array(
861 '_SITEROOT' => 42
862 ),
863 ' AND dummytable.uid=42'
864 ),
865 'replaceMarkersInWhereClause replaces siteroot uid with string' => array(
866 ' AND dummytable.uid=###SITEROOT###',
867 array(
868 '_SITEROOT' => '42string'
869 ),
870 ' AND dummytable.uid=42'
871 ),
872 'replaceMarkersInWhereClause replaces page tsconfig id with integer' => array(
873 ' AND dummytable.uid=###PAGE_TSCONFIG_ID###',
874 array(
875 'dummyfield' => array(
876 'PAGE_TSCONFIG_ID' => 42
877 )
878 ),
879 ' AND dummytable.uid=42'
880 ),
881 'replaceMarkersInWhereClause replaces page tsconfig id with string' => array(
882 ' AND dummytable.uid=###PAGE_TSCONFIG_ID###',
883 array(
884 'dummyfield' => array(
885 'PAGE_TSCONFIG_ID' => '42string'
886 )
887 ),
888 ' AND dummytable.uid=42'
889 ),
890 'replaceMarkersInWhereClause replaces page tsconfig id list' => array(
891 ' AND dummytable.uid IN (###PAGE_TSCONFIG_IDLIST###)',
892 array(
893 'dummyfield' => array(
894 'PAGE_TSCONFIG_IDLIST' => '1,a,2,b,3,c'
895 )
896 ),
897 ' AND dummytable.uid IN (1,0,2,0,3,0)'
898 ),
899 'replaceMarkersInWhereClause replaces page tsconfig id list with empty string' => array(
900 ' AND dummytable.uid IN (###PAGE_TSCONFIG_IDLIST###)',
901 array(
902 'dummyfield' => array(
903 'PAGE_TSCONFIG_IDLIST' => ''
904 )
905 ),
906 ' AND dummytable.uid IN (0)'
907 ),
908 'replaceMarkersInWhereClause replaces page tsconfig string' => array(
909 ' AND dummytable.title=\'###PAGE_TSCONFIG_STR###\'',
910 array(
911 'dummyfield' => array(
912 'PAGE_TSCONFIG_STR' => '42'
913 )
914 ),
915 ' AND dummytable.title=\'42\''
916 ),
917 'replaceMarkersInWhereClause replaces all markers' => array(
918 ' AND dummytable.title=\'###REC_FIELD_dummyfield###\'' .
919 ' AND dummytable.uid=###REC_FIELD_uid###' .
920 ' AND dummytable.pid=###CURRENT_PID###' .
921 ' AND dummytable.l18n_parent=###THIS_UID###' .
922 ' AND dummytable.cid=###THIS_CID###' .
923 ' AND dummytable.storage_pid=###STORAGE_PID###' .
924 ' AND dummytable.siteroot=###SITEROOT###' .
925 ' AND dummytable.config_uid=###PAGE_TSCONFIG_ID###' .
926 ' AND dummytable.idlist IN (###PAGE_TSCONFIG_IDLIST###)' .
927 ' AND dummytable.string=\'###PAGE_TSCONFIG_STR###\'',
928 array(
929 '_THIS_ROW' => array(
930 'dummyfield' => 'Hello World',
931 'uid' => 42
932 ),
933 '_CURRENT_PID' => '1',
934 '_THIS_UID' => 2,
935 '_THIS_CID' => 3,
936 '_STORAGE_PID' => 4,
937 '_SITEROOT' => 5,
938 'dummyfield' => array(
939 'PAGE_TSCONFIG_ID' => 6,
940 'PAGE_TSCONFIG_IDLIST' => '1,2,3',
941 'PAGE_TSCONFIG_STR' => 'string'
942 )
943 ),
944 ' AND dummytable.title=\'Hello World\' AND dummytable.uid=\'42\' AND dummytable.pid=1' .
945 ' AND dummytable.l18n_parent=2 AND dummytable.cid=3 AND dummytable.storage_pid=4' .
946 ' AND dummytable.siteroot=5 AND dummytable.config_uid=6 AND dummytable.idlist IN (1,2,3)' .
947 ' AND dummytable.string=\'string\'',
948 ),
949 );
950 }
951
952 /**
953 * @test
954 * @dataProvider replaceMarkersInWhereClauseDataProvider
955 */
956 public function replaceMarkersInWhereClauseReturnsValidWhereClause($whereClause, $tsConfig, $expected) {
957 $this->assertSame($expected, BackendUtility::replaceMarkersInWhereClause($whereClause, 'dummytable', 'dummyfield', $tsConfig));
958 }
959
960 /**
961 * @test
962 */
963 public function getModTSconfigIgnoresValuesFromUserTsConfigIfNoSet() {
964 $completeConfiguration = array(
965 'value' => 'bar',
966 'properties' => array(
967 'permissions.' => array(
968 'file.' => array(
969 'default.' => array('readAction' => '1'),
970 '1.' => array('writeAction' => '1'),
971 '0.' => array('readAction' => '0'),
972 ),
973 )
974 )
975 );
976
977 /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Backend\Utility\BackendUtility $fixture */
978 $fixture = $this->getMock('TYPO3\\CMS\\Backend\\Utility\\BackendUtility', array('getPagesTSconfig'));
979
980 $GLOBALS['BE_USER'] = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
981 $GLOBALS['BE_USER']->expects($this->at(0))->method('getTSConfig')->will($this->returnValue($completeConfiguration));
982 $GLOBALS['BE_USER']->expects($this->at(1))->method('getTSConfig')->will($this->returnValue(array('value' => NULL, 'properties' => NULL)));
983
984 $this->assertSame($completeConfiguration, $fixture->getModTSconfig(42, 'notrelevant'));
985 }
986
987
988 }