[TASK] Removes eval() in core data handler unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / DataHandling / DataHandlerTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\DataHandler;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
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.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
18 use TYPO3\CMS\Core\DataHandling\DataHandler;
19 use TYPO3\CMS\Core\Tests\Unit\DataHandling\Fixtures\AllowAccessHookFixture;
20 use TYPO3\CMS\Core\Tests\Unit\DataHandling\Fixtures\InvalidHookFixture;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Core\Database\DatabaseConnection;
23
24 /**
25 * Test case
26 *
27 * @author Oliver Klee <typo3-coding@oliverklee.de>
28 * @author Tolleiv Nietsch <info@tolleiv.de>
29 */
30 class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
31
32 /**
33 * @var array A backup of registered singleton instances
34 */
35 protected $singletonInstances = array();
36
37 /**
38 * @var DataHandler|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
39 */
40 protected $subject;
41
42 /**
43 * @var BackendUserAuthentication a mock logged-in back-end user
44 */
45 protected $backEndUser;
46
47 /**
48 * @var DatabaseConnection|\PHPUnit_Framework_MockObject_MockObject
49 */
50 protected $mockDatabaseConnection;
51
52 /**
53 * Set up the tests
54 */
55 protected function setUp() {
56 $GLOBALS['TCA'] = array();
57 $this->singletonInstances = GeneralUtility::getSingletonInstances();
58 $this->backEndUser = $this->getMock(BackendUserAuthentication::class);
59 $this->mockDatabaseConnection = $this->getMock(DatabaseConnection::class, array(), array(), '', FALSE);
60 $GLOBALS['TYPO3_DB'] = $this->mockDatabaseConnection;
61 $this->subject = $this->getAccessibleMock(DataHandler::class, ['dummy']);
62 $this->subject->start(array(), '', $this->backEndUser);
63 }
64
65 /**
66 * Tear down the tests
67 */
68 protected function tearDown() {
69 GeneralUtility::resetSingletonInstances($this->singletonInstances);
70 parent::tearDown();
71 }
72
73 //////////////////////////////////////
74 // Tests for the basic functionality
75 //////////////////////////////////////
76 /**
77 * @test
78 */
79 public function fixtureCanBeCreated() {
80 $this->assertTrue($this->subject instanceof DataHandler);
81 }
82
83 //////////////////////////////////////////
84 // Test concerning checkModifyAccessList
85 //////////////////////////////////////////
86 /**
87 * @test
88 */
89 public function adminIsAllowedToModifyNonAdminTable() {
90 $this->subject->admin = TRUE;
91 $this->assertTrue($this->subject->checkModifyAccessList('tt_content'));
92 }
93
94 /**
95 * @test
96 */
97 public function nonAdminIsNorAllowedToModifyNonAdminTable() {
98 $this->subject->admin = FALSE;
99 $this->assertFalse($this->subject->checkModifyAccessList('tt_content'));
100 }
101
102 /**
103 * @test
104 */
105 public function nonAdminWithTableModifyAccessIsAllowedToModifyNonAdminTable() {
106 $this->subject->admin = FALSE;
107 $this->backEndUser->groupData['tables_modify'] = 'tt_content';
108 $this->assertTrue($this->subject->checkModifyAccessList('tt_content'));
109 }
110
111 /**
112 * @test
113 */
114 public function adminIsAllowedToModifyAdminTable() {
115 $this->subject->admin = TRUE;
116 $this->assertTrue($this->subject->checkModifyAccessList('be_users'));
117 }
118
119 /**
120 * @test
121 */
122 public function nonAdminIsNotAllowedToModifyAdminTable() {
123 $this->subject->admin = FALSE;
124 $this->assertFalse($this->subject->checkModifyAccessList('be_users'));
125 }
126
127 /**
128 * @test
129 */
130 public function nonAdminWithTableModifyAccessIsNotAllowedToModifyAdminTable() {
131 $tableName = $this->getUniqueId('aTable');
132 $GLOBALS['TCA'] = array(
133 $tableName => array(
134 'ctrl' => array(
135 'adminOnly' => TRUE,
136 ),
137 ),
138 );
139 $this->subject->admin = FALSE;
140 $this->backEndUser->groupData['tables_modify'] = $tableName;
141 $this->assertFalse($this->subject->checkModifyAccessList($tableName));
142 }
143
144 /**
145 * @test
146 */
147 public function evalCheckValueDouble2() {
148 $testData = array(
149 '-0,5' => '-0.50',
150 '1000' => '1000.00',
151 '1000,10' => '1000.10',
152 '1000,0' => '1000.00',
153 '600.000.000,00' => '600000000.00',
154 '60aaa00' => '6000.00'
155 );
156 foreach ($testData as $value => $expectedReturnValue) {
157 $returnValue = $this->subject->checkValue_input_Eval($value, array('double2'), '');
158 $this->assertSame($returnValue['value'], $expectedReturnValue);
159 }
160 }
161
162 /**
163 * Data provider for inputValueCheckRecognizesStringValuesAsIntegerValuesCorrectly
164 *
165 * @return array
166 */
167 public function inputValuesStringsDataProvider() {
168 return array(
169 '"0" returns zero as integer' => array(
170 '0',
171 0
172 ),
173 '"-1999999" is interpreted correctly as -1999999 and is lot lower than -200000' => array(
174 '-1999999',
175 -1999999
176 ),
177 '"3000000" is interpreted correctly as 3000000 but is higher then 200000 and set to 200000' => array(
178 '3000000',
179 2000000
180 ),
181 );
182 }
183
184 /**
185 * @test
186 * @dataProvider inputValuesStringsDataProvider
187 * @param string $value
188 * @param int $expectedReturnValue
189 */
190 public function inputValueCheckRecognizesStringValuesAsIntegerValuesCorrectly($value, $expectedReturnValue) {
191 $tcaFieldConf = array(
192 'input' => array(),
193 'eval' => 'int',
194 'range' => array(
195 'lower' => '-2000000',
196 'upper' => '2000000'
197 )
198 );
199 $returnValue = $this->subject->_call('checkValueForInput', $value, $tcaFieldConf, '', 0, 0, '');
200 $this->assertSame($returnValue['value'], $expectedReturnValue);
201 }
202
203 /**
204 * @return array
205 */
206 public function inputValueCheckCallsGetDateTimeFormatsForDatetimeFieldsDataProvider() {
207 return array(
208 'dbType = date' => array(
209 'date'
210 ),
211 'dbType = datetime' => array(
212 'datetime'
213 )
214 );
215 }
216
217 /**
218 * @test
219 * @dataProvider inputValueCheckCallsGetDateTimeFormatsForDatetimeFieldsDataProvider
220 * @param string $dbType
221 */
222 public function inputValueCheckCallsGetDateTimeFormatsForDatetimeFields($dbType) {
223 $tcaFieldConf = array(
224 'input' => array(),
225 'dbType' => $dbType
226 );
227 $this->mockDatabaseConnection->expects($this->once())->method('getDateTimeFormats');
228 $this->subject->_call('checkValueForInput', '', $tcaFieldConf, '', 0, 0, '');
229 }
230
231 /**
232 * @return array
233 */
234 public function inputValueCheckDoesNotCallGetDateTimeFormatsForNonDatetimeFieldsDataProvider() {
235 return array(
236 'tca without dbType' => array(
237 array(
238 'input' => array()
239 )
240 ),
241 'tca with dbType != date/datetime' => array(
242 array(
243 'input' => array(),
244 'dbType' => 'foo'
245 )
246 )
247 );
248 }
249
250 /**
251 * @test
252 * @param array $tcaFieldConf
253 * @dataProvider inputValueCheckDoesNotCallGetDateTimeFormatsForNonDatetimeFieldsDataProvider
254 */
255 public function inputValueCheckDoesNotCallGetDateTimeFormatsForNonDatetimeFields($tcaFieldConf) {
256 $this->mockDatabaseConnection->expects($this->never())->method('getDateTimeFormats');
257 $this->subject->_call('checkValueForInput', '', $tcaFieldConf, '', 0, 0, '');
258 }
259
260
261 ///////////////////////////////////////////
262 // Tests concerning checkModifyAccessList
263 ///////////////////////////////////////////
264 //
265 /**
266 * Tests whether a wrong interface on the 'checkModifyAccessList' hook throws an exception.
267 *
268 * @test
269 * @expectedException \UnexpectedValueException
270 */
271 public function doesCheckModifyAccessListThrowExceptionOnWrongHookInterface() {
272 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = InvalidHookFixture::class;
273 $this->subject->checkModifyAccessList('tt_content');
274 }
275
276 /**
277 * Tests whether the 'checkModifyAccessList' hook is called correctly.
278 *
279 * @test
280 */
281 public function doesCheckModifyAccessListHookGetsCalled() {
282 $hookClass = $this->getUniqueId('tx_coretest');
283 $hookMock = $this->getMock(\TYPO3\CMS\Core\DataHandling\DataHandlerCheckModifyAccessListHookInterface::class, array('checkModifyAccessList'), array(), $hookClass);
284 $hookMock->expects($this->once())->method('checkModifyAccessList');
285 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass;
286 $GLOBALS['T3_VAR']['getUserObj'][$hookClass] = $hookMock;
287 $this->subject->checkModifyAccessList('tt_content');
288 }
289
290 /**
291 * Tests whether the 'checkModifyAccessList' hook modifies the $accessAllowed variable.
292 *
293 * @test
294 */
295 public function doesCheckModifyAccessListHookModifyAccessAllowed() {
296 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = AllowAccessHookFixture::class;
297 $this->assertTrue($this->subject->checkModifyAccessList('tt_content'));
298 }
299
300 /////////////////////////////////////
301 // Tests concerning process_datamap
302 /////////////////////////////////////
303 /**
304 * @test
305 */
306 public function processDatamapForFrozenNonZeroWorkspaceReturnsFalse() {
307 /** @var DataHandler $subject */
308 $subject = $this->getMock(DataHandler::class, array('newlog'));
309 $this->backEndUser->workspace = 1;
310 $this->backEndUser->workspaceRec = array('freeze' => TRUE);
311 $subject->BE_USER = $this->backEndUser;
312 $this->assertFalse($subject->process_datamap());
313 }
314
315 /**
316 * @test
317 */
318 public function processDatamapWhenEditingRecordInWorkspaceCreatesNewRecordInWorkspace() {
319 // Unset possible hooks on method under test
320 // @TODO: Can be removed if unit test boostrap is fixed to not load LocalConfiguration anymore
321 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'] = array();
322
323 $GLOBALS['TCA'] = array(
324 'pages' => array(
325 'columns' => array(),
326 ),
327 );
328
329 /** @var $subject DataHandler|\PHPUnit_Framework_MockObject_MockObject */
330 $subject = $this->getMock(
331 DataHandler::class,
332 array('newlog', 'checkModifyAccessList', 'tableReadOnly', 'checkRecordUpdateAccess')
333 );
334
335 $subject->bypassWorkspaceRestrictions = FALSE;
336 $subject->datamap = array(
337 'pages' => array(
338 '1' => array(
339 'header' => 'demo'
340 )
341 )
342 );
343 $subject->expects($this->once())->method('checkModifyAccessList')->with('pages')->will($this->returnValue(TRUE));
344 $subject->expects($this->once())->method('tableReadOnly')->with('pages')->will($this->returnValue(FALSE));
345 $subject->expects($this->once())->method('checkRecordUpdateAccess')->will($this->returnValue(TRUE));
346
347 /** @var BackendUserAuthentication|\PHPUnit_Framework_MockObject_MockObject $backEndUser */
348 $backEndUser = $this->getMock(BackendUserAuthentication::class);
349 $backEndUser->workspace = 1;
350 $backEndUser->workspaceRec = array('freeze' => FALSE);
351 $backEndUser->expects($this->once())->method('workspaceAllowAutoCreation')->will($this->returnValue(TRUE));
352 $backEndUser->expects($this->once())->method('workspaceCannotEditRecord')->will($this->returnValue(TRUE));
353 $backEndUser->expects($this->once())->method('recordEditAccessInternals')->with('pages', 1)->will($this->returnValue(TRUE));
354 $subject->BE_USER = $backEndUser;
355 $createdTceMain = $this->getMock(DataHandler::class, array());
356 $createdTceMain->expects($this->once())->method('start')->with(array(), array(
357 'pages' => array(
358 1 => array(
359 'version' => array(
360 'action' => 'new',
361 'treeLevels' => -1,
362 'label' => 'Auto-created for WS #1'
363 )
364 )
365 )
366 ));
367 $createdTceMain->expects($this->never())->method('process_datamap');
368 $createdTceMain->expects($this->once())->method('process_cmdmap');
369 GeneralUtility::addInstance(DataHandler::class, $createdTceMain);
370 $subject->process_datamap();
371 }
372
373 /**
374 * @test
375 */
376 public function doesCheckFlexFormValueHookGetsCalled() {
377 $hookClass = $this->getUniqueId('tx_coretest');
378 $hookMock = $this->getMock($hookClass, array('checkFlexFormValue_beforeMerge'));
379 $hookMock->expects($this->once())->method('checkFlexFormValue_beforeMerge');
380 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkFlexFormValue'][] = $hookClass;
381 $GLOBALS['T3_VAR']['getUserObj'][$hookClass] = $hookMock;
382 $this->subject->_call('checkValueForFlex', [], [], [], '', 0, '', '', 0, 0, 0, [], '');
383 }
384
385 /////////////////////////////////////
386 // Tests concerning log
387 /////////////////////////////////////
388 /**
389 * @test
390 */
391 public function logCallsWriteLogOfBackendUserIfLoggingIsEnabled() {
392 $backendUser = $this->getMock(BackendUserAuthentication::class);
393 $backendUser->expects($this->once())->method('writelog');
394 $this->subject->enableLogging = TRUE;
395 $this->subject->BE_USER = $backendUser;
396 $this->subject->log('', 23, 0, 42, 0, 'details');
397 }
398
399 /**
400 * @test
401 */
402 public function logDoesNotCallWriteLogOfBackendUserIfLoggingIsDisabled() {
403 $backendUser = $this->getMock(BackendUserAuthentication::class);
404 $backendUser->expects($this->never())->method('writelog');
405 $this->subject->enableLogging = FALSE;
406 $this->subject->BE_USER = $backendUser;
407 $this->subject->log('', 23, 0, 42, 0, 'details');
408 }
409
410 /**
411 * @test
412 */
413 public function logAddsEntryToLocalErrorLogArray() {
414 $backendUser = $this->getMock(BackendUserAuthentication::class);
415 $this->subject->BE_USER = $backendUser;
416 $this->subject->enableLogging = TRUE;
417 $this->subject->errorLog = array();
418 $logDetailsUnique = $this->getUniqueId('details');
419 $this->subject->log('', 23, 0, 42, 1, $logDetailsUnique);
420 $this->assertStringEndsWith($logDetailsUnique, $this->subject->errorLog[0]);
421 }
422
423 /**
424 * @test
425 */
426 public function logFormatsDetailMessageWithAdditionalDataInLocalErrorArray() {
427 $backendUser = $this->getMock(BackendUserAuthentication::class);
428 $this->subject->BE_USER = $backendUser;
429 $this->subject->enableLogging = TRUE;
430 $this->subject->errorLog = array();
431 $logDetails = $this->getUniqueId('details');
432 $this->subject->log('', 23, 0, 42, 1, '%1$s' . $logDetails . '%2$s', -1, array('foo', 'bar'));
433 $expected = 'foo' . $logDetails . 'bar';
434 $this->assertStringEndsWith($expected, $this->subject->errorLog[0]);
435 }
436
437 /**
438 * @param bool $expected
439 * @param string $submittedValue
440 * @param string $storedValue
441 * @param string $storedType
442 * @param bool $allowNull
443 *
444 * @dataProvider equalSubmittedAndStoredValuesAreDeterminedDataProvider
445 * @test
446 */
447 public function equalSubmittedAndStoredValuesAreDetermined($expected, $submittedValue, $storedValue, $storedType, $allowNull) {
448 $result = $this->callInaccessibleMethod(
449 $this->subject,
450 'isSubmittedValueEqualToStoredValue',
451 $submittedValue, $storedValue, $storedType, $allowNull
452 );
453 $this->assertEquals($expected, $result);
454 }
455
456 /**
457 * @return array
458 */
459 public function equalSubmittedAndStoredValuesAreDeterminedDataProvider() {
460 return array(
461 // String
462 'string value "" vs. ""' => array(
463 TRUE,
464 '', '', 'string', FALSE
465 ),
466 'string value 0 vs. "0"' => array(
467 TRUE,
468 0, '0', 'string', FALSE
469 ),
470 'string value 1 vs. "1"' => array(
471 TRUE,
472 1, '1', 'string', FALSE
473 ),
474 'string value "0" vs. ""' => array(
475 FALSE,
476 '0', '', 'string', FALSE
477 ),
478 'string value 0 vs. ""' => array(
479 FALSE,
480 0, '', 'string', FALSE
481 ),
482 'string value null vs. ""' => array(
483 TRUE,
484 NULL, '', 'string', FALSE
485 ),
486 // Integer
487 'integer value 0 vs. 0' => array(
488 TRUE,
489 0, 0, 'int', FALSE
490 ),
491 'integer value "0" vs. "0"' => array(
492 TRUE,
493 '0', '0', 'int', FALSE
494 ),
495 'integer value 0 vs. "0"' => array(
496 TRUE,
497 0, '0', 'int', FALSE
498 ),
499 'integer value "" vs. "0"' => array(
500 TRUE,
501 '', '0', 'int', FALSE
502 ),
503 'integer value "" vs. 0' => array(
504 TRUE,
505 '', 0, 'int', FALSE
506 ),
507 'integer value "0" vs. 0' => array(
508 TRUE,
509 '0', 0, 'int', FALSE
510 ),
511 'integer value 1 vs. 1' => array(
512 TRUE,
513 1, 1, 'int', FALSE
514 ),
515 'integer value 1 vs. "1"' => array(
516 TRUE,
517 1, '1', 'int', FALSE
518 ),
519 'integer value "1" vs. "1"' => array(
520 TRUE,
521 '1', '1', 'int', FALSE
522 ),
523 'integer value "1" vs. 1' => array(
524 TRUE,
525 '1', 1, 'int', FALSE
526 ),
527 'integer value "0" vs. "1"' => array(
528 FALSE,
529 '0', '1', 'int', FALSE
530 ),
531 // String with allowed NULL values
532 'string with allowed null value "" vs. ""' => array(
533 TRUE,
534 '', '', 'string', TRUE
535 ),
536 'string with allowed null value 0 vs. "0"' => array(
537 TRUE,
538 0, '0', 'string', TRUE
539 ),
540 'string with allowed null value 1 vs. "1"' => array(
541 TRUE,
542 1, '1', 'string', TRUE
543 ),
544 'string with allowed null value "0" vs. ""' => array(
545 FALSE,
546 '0', '', 'string', TRUE
547 ),
548 'string with allowed null value 0 vs. ""' => array(
549 FALSE,
550 0, '', 'string', TRUE
551 ),
552 'string with allowed null value null vs. ""' => array(
553 FALSE,
554 NULL, '', 'string', TRUE
555 ),
556 'string with allowed null value "" vs. null' => array(
557 FALSE,
558 '', NULL, 'string', TRUE
559 ),
560 'string with allowed null value null vs. null' => array(
561 TRUE,
562 NULL, NULL, 'string', TRUE
563 ),
564 // Integer with allowed NULL values
565 'integer with allowed null value 0 vs. 0' => array(
566 TRUE,
567 0, 0, 'int', TRUE
568 ),
569 'integer with allowed null value "0" vs. "0"' => array(
570 TRUE,
571 '0', '0', 'int', TRUE
572 ),
573 'integer with allowed null value 0 vs. "0"' => array(
574 TRUE,
575 0, '0', 'int', TRUE
576 ),
577 'integer with allowed null value "" vs. "0"' => array(
578 TRUE,
579 '', '0', 'int', TRUE
580 ),
581 'integer with allowed null value "" vs. 0' => array(
582 TRUE,
583 '', 0, 'int', TRUE
584 ),
585 'integer with allowed null value "0" vs. 0' => array(
586 TRUE,
587 '0', 0, 'int', TRUE
588 ),
589 'integer with allowed null value 1 vs. 1' => array(
590 TRUE,
591 1, 1, 'int', TRUE
592 ),
593 'integer with allowed null value "1" vs. "1"' => array(
594 TRUE,
595 '1', '1', 'int', TRUE
596 ),
597 'integer with allowed null value "1" vs. 1' => array(
598 TRUE,
599 '1', 1, 'int', TRUE
600 ),
601 'integer with allowed null value 1 vs. "1"' => array(
602 TRUE,
603 1, '1', 'int', TRUE
604 ),
605 'integer with allowed null value "0" vs. "1"' => array(
606 FALSE,
607 '0', '1', 'int', TRUE
608 ),
609 'integer with allowed null value null vs. ""' => array(
610 FALSE,
611 NULL, '', 'int', TRUE
612 ),
613 'integer with allowed null value "" vs. null' => array(
614 FALSE,
615 '', NULL, 'int', TRUE
616 ),
617 'integer with allowed null value null vs. null' => array(
618 TRUE,
619 NULL, NULL, 'int', TRUE
620 ),
621 'integer with allowed null value null vs. "0"' => array(
622 FALSE,
623 NULL, '0', 'int', TRUE
624 ),
625 'integer with allowed null value null vs. 0' => array(
626 FALSE,
627 NULL, 0, 'int', TRUE
628 ),
629 'integer with allowed null value "0" vs. null' => array(
630 FALSE,
631 '0', NULL, 'int', TRUE
632 ),
633 );
634 }
635
636 /**
637 * @param bool $expected
638 * @param array $eval
639 * @dataProvider getPlaceholderTitleForTableLabelReturnsLabelThatsMatchesLabelFieldConditionsDataProvider
640 * @test
641 */
642 public function getPlaceholderTitleForTableLabelReturnsLabelThatsMatchesLabelFieldConditions($expected, $eval) {
643 $table = 'phpunit_dummy';
644
645 /** @var DataHandler|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
646 $subject = $this->getAccessibleMock(
647 DataHandler::class,
648 array('dummy')
649 );
650
651 $backendUser = $this->getMock(BackendUserAuthentication::class);
652 $subject->BE_USER = $backendUser;
653 $subject->BE_USER->workspace = 1;
654
655 $GLOBALS['TCA'][$table] = array();
656 $GLOBALS['TCA'][$table]['ctrl'] = array('label' => 'dummy');
657 $GLOBALS['TCA'][$table]['columns'] = array(
658 'dummy' => array(
659 'config' => array(
660 'eval' => $eval
661 )
662 )
663 );
664
665 $this->assertEquals($expected, $subject->_call('getPlaceholderTitleForTableLabel', $table));
666 }
667
668 /**
669 * @return array
670 */
671 public function getPlaceholderTitleForTableLabelReturnsLabelThatsMatchesLabelFieldConditionsDataProvider() {
672 return array(
673 array(
674 0.10,
675 'double2'
676 ),
677 array(
678 0,
679 'int'
680 ),
681 array(
682 '0',
683 'datetime'
684 ),
685 array(
686 '[PLACEHOLDER, WS#1]',
687 ''
688 )
689 );
690 }
691
692 /**
693 * @test
694 */
695 public function deleteRecord_procBasedOnFieldTypeRespectsEnableCascadingDelete() {
696 $table = $this->getUniqueId('foo_');
697 $conf = array(
698 'type' => 'inline',
699 'foreign_table' => $this->getUniqueId('foreign_foo_'),
700 'behaviour' => array(
701 'enableCascadingDelete' => 0,
702 )
703 );
704
705 /** @var \TYPO3\CMS\Core\Database\RelationHandler $mockRelationHandler */
706 $mockRelationHandler = $this->getMock(\TYPO3\CMS\Core\Database\RelationHandler::class, array(), array(), '', FALSE);
707 $mockRelationHandler->itemArray = array(
708 '1' => array('table' => $this->getUniqueId('bar_'), 'id' => 67)
709 );
710
711 /** @var DataHandler|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $mockDataHandler */
712 $mockDataHandler = $this->getAccessibleMock(DataHandler::class, array('getInlineFieldType', 'deleteAction', 'createRelationHandlerInstance'), array(), '', FALSE);
713 $mockDataHandler->expects($this->once())->method('getInlineFieldType')->will($this->returnValue('field'));
714 $mockDataHandler->expects($this->once())->method('createRelationHandlerInstance')->will($this->returnValue($mockRelationHandler));
715 $mockDataHandler->expects($this->never())->method('deleteAction');
716 $mockDataHandler->deleteRecord_procBasedOnFieldType($table, 42, 'foo', 'bar', $conf);
717 }
718
719 /**
720 * @return array
721 */
722 public function checkValue_checkReturnsExpectedValuesDataProvider() {
723 return array(
724 'None item selected' => array(
725 0,
726 0
727 ),
728 'All items selected' => array(
729 7,
730 7
731 ),
732 'Item 1 and 2 are selected' => array(
733 3,
734 3
735 ),
736 'Value is higher than allowed' => array(
737 15,
738 7
739 ),
740 'Negative value' => array(
741 -5,
742 0
743 )
744 );
745 }
746
747 /**
748 * @param string $value
749 * @param string $expectedValue
750 *
751 * @dataProvider checkValue_checkReturnsExpectedValuesDataProvider
752 * @test
753 */
754 public function checkValue_checkReturnsExpectedValues($value, $expectedValue) {
755 $expectedResult = array(
756 'value' => $expectedValue
757 );
758 $result = array();
759 $tcaFieldConfiguration = array(
760 'items' => array(
761 array('Item 1', 0),
762 array('Item 2', 0),
763 array('Item 3', 0)
764 )
765 );
766 $this->assertSame($expectedResult, $this->subject->_call('checkValueForCheck', $result, $value, $tcaFieldConfiguration, '', 0, 0, ''));
767 }
768
769 }