[BUGFIX] Add missing namespace parts
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataGroup / OrderedProviderListTest.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\OrderedProviderList;
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 OrderedProviderListTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
28 {
29 /**
30 * @var OrderedProviderList
31 */
32 protected $subject;
33
34 protected function setUp()
35 {
36 $this->subject = new OrderedProviderList();
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 $input = ['foo'];
50
51 $this->subject->setProviderList([]);
52 $this->assertEquals($input, $this->subject->compile($input));
53 }
54
55 /**
56 * @test
57 */
58 public function compileReturnsResultChangedByDataProvider()
59 {
60 /** @var DependencyOrderingService|ObjectProphecy $orderingServiceProphecy */
61 $orderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
62 GeneralUtility::addInstance(DependencyOrderingService::class, $orderingServiceProphecy->reveal());
63 $orderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
64
65 /** @var FormDataProviderInterface|ObjectProphecy $formDataProviderProphecy */
66 $formDataProviderProphecy = $this->prophesize(FormDataProviderInterface::class);
67 GeneralUtility::addInstance(FormDataProviderInterface::class, $formDataProviderProphecy->reveal());
68 $providerResult = ['foo'];
69 $formDataProviderProphecy->addData(Argument::cetera())->shouldBeCalled()->willReturn($providerResult);
70
71 $this->subject->setProviderList([
72 FormDataProviderInterface::class => [],
73 ]);
74 $this->assertEquals($providerResult, $this->subject->compile([]));
75 }
76
77 /**
78 * @test
79 */
80 public function compileThrowsExceptionIfDataProviderDoesNotImplementInterface()
81 {
82 /** @var DependencyOrderingService|ObjectProphecy $orderingServiceProphecy */
83 $orderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
84 GeneralUtility::addInstance(DependencyOrderingService::class, $orderingServiceProphecy->reveal());
85 $orderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
86
87 /** @var FormDataProviderInterface|ObjectProphecy $formDataProviderProphecy */
88 $formDataProviderProphecy = $this->prophesize(\stdClass::class);
89 GeneralUtility::addInstance(\stdClass::class, $formDataProviderProphecy->reveal());
90
91 $this->expectException(\UnexpectedValueException::class);
92 $this->expectExceptionCode(1485299408);
93
94 $this->subject->setProviderList([
95 \stdClass::class => [],
96 ]);
97 $this->subject->compile([]);
98 }
99 }