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