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