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