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