[BUGFIX] Add missing namespace parts
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataGroup / TcaDatabaseRecordTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataGroup;
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 Prophecy\Argument;
18 use Prophecy\Prophecy\ObjectProphecy;
19 use TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord;
20 use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
21 use TYPO3\CMS\Core\Service\DependencyOrderingService;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23
24 /**
25 * Test case
26 */
27 class TcaDatabaseRecordTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
28 {
29 /**
30 * @var TcaDatabaseRecord
31 */
32 protected $subject;
33
34 protected function setUp()
35 {
36 $this->subject = new TcaDatabaseRecord();
37 }
38
39 /**
40 * @test
41 */
42 public function compileReturnsIncomingData()
43 {
44 /** @var DependencyOrderingService|ObjectProphecy $orderingServiceProphecy */
45 $orderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
46 GeneralUtility::addInstance(DependencyOrderingService::class, $orderingServiceProphecy->reveal());
47 $orderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
48
49 $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'] = [];
50
51 $input = ['foo'];
52
53 $this->assertEquals($input, $this->subject->compile($input));
54 }
55
56 /**
57 * @test
58 */
59 public function compileReturnsResultChangedByDataProvider()
60 {
61 /** @var DependencyOrderingService|ObjectProphecy $orderingServiceProphecy */
62 $orderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
63 GeneralUtility::addInstance(DependencyOrderingService::class, $orderingServiceProphecy->reveal());
64 $orderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
65
66 /** @var FormDataProviderInterface|ObjectProphecy $formDataProviderProphecy */
67 $formDataProviderProphecy = $this->prophesize(FormDataProviderInterface::class);
68 $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'] = [
69 FormDataProviderInterface::class => [],
70 ];
71 GeneralUtility::addInstance(FormDataProviderInterface::class, $formDataProviderProphecy->reveal());
72 $providerResult = ['foo'];
73 $formDataProviderProphecy->addData(Argument::cetera())->shouldBeCalled()->willReturn($providerResult);
74
75 $this->assertEquals($providerResult, $this->subject->compile([]));
76 }
77
78 /**
79 * @test
80 */
81 public function compileThrowsExceptionIfDataProviderDoesNotImplementInterface()
82 {
83 /** @var DependencyOrderingService|ObjectProphecy $orderingServiceProphecy */
84 $orderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
85 GeneralUtility::addInstance(DependencyOrderingService::class, $orderingServiceProphecy->reveal());
86 $orderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
87
88 /** @var FormDataProviderInterface|ObjectProphecy $formDataProviderProphecy */
89 $formDataProviderProphecy = $this->prophesize(\stdClass::class);
90 $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaDatabaseRecord'] = [
91 \stdClass::class => [],
92 ];
93 GeneralUtility::addInstance(\stdClass::class, $formDataProviderProphecy->reveal());
94
95 $this->expectException(\UnexpectedValueException::class);
96 $this->expectExceptionCode(1485299408);
97
98 $this->subject->compile([]);
99 }
100 }