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