[TASK] Make sysext/backend/Tests/Unit/ notice free
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Controller / Wizard / SuggestWizardControllerTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Backend\Tests\Unit\Controller\Wizard;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Controller\Wizard\SuggestWizardController;
20 use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23
24 /**
25 * Test case
26 */
27 class SuggestWizardControllerTest extends UnitTestCase
28 {
29 /**
30 * @test
31 */
32 public function getFlexFieldConfigurationThrowsExceptionIfSimpleFlexFieldIsNotFound(): void
33 {
34 $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
35 $serverRequestProphecy->getParsedBody()->willReturn([
36 'value' => 'theSearchValue',
37 'table' => 'aTable',
38 'field' => 'aField',
39 'uid' => 'aUid',
40 'pid' => 'aPid',
41 'dataStructureIdentifier' => ['anIdentifier'],
42 'flexFormSheetName' => 'sDb',
43 'flexFormFieldName' => 'aField',
44 'flexFormContainerName' => '',
45 'flexFormContainerFieldName' => '',
46 ]);
47
48 $dataStructure = [
49 'sheets' => [
50 'sDb' => [
51 'ROOT' => [
52 'el' => [
53 'differentField' => [
54 'TCEforms' => [
55 'config' => [
56 'Sublevel field configuration',
57 ],
58 ],
59 ],
60 ],
61 ],
62 ],
63 ],
64 ];
65 $flexFormToolsProphecy = $this->prophesize(FlexFormTools::class);
66 GeneralUtility::addInstance(FlexFormTools::class, $flexFormToolsProphecy->reveal());
67 $flexFormToolsProphecy->parseDataStructureByIdentifier(json_encode(['anIdentifier']))->willReturn($dataStructure);
68
69 $this->expectException(\RuntimeException::class);
70 $this->expectExceptionCode(1480609491);
71 (new SuggestWizardController())->searchAction($serverRequestProphecy->reveal());
72 }
73
74 /**
75 * @test
76 */
77 public function getFlexFieldConfigurationThrowsExceptionIfSectionContainerFlexFieldIsNotFound(): void
78 {
79 $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
80 $serverRequestProphecy->getParsedBody()->willReturn([
81 'value' => 'theSearchValue',
82 'table' => 'aTable',
83 'field' => 'aField',
84 'uid' => 'aUid',
85 'pid' => 'aPid',
86 'dataStructureIdentifier' => ['anIdentifier'],
87 'flexFormSheetName' => 'sDb',
88 'flexFormFieldName' => 'aField',
89 'flexFormContainerName' => 'aContainer',
90 'flexFormContainerFieldName' => 'aContainerFieldName',
91 ]);
92
93 $dataStructure = [
94 'sheets' => [
95 'sDb' => [
96 'ROOT' => [
97 'el' => [
98 'notTheFieldYouAreLookingFor' => [
99 'TCEforms' => [
100 'config' => [
101 'Sublevel field configuration',
102 ],
103 ],
104 ],
105 ],
106 ],
107 ],
108 ],
109 ];
110 $flexFormToolsProphecy = $this->prophesize(FlexFormTools::class);
111 GeneralUtility::addInstance(FlexFormTools::class, $flexFormToolsProphecy->reveal());
112 $flexFormToolsProphecy->parseDataStructureByIdentifier(json_encode(['anIdentifier']))->willReturn($dataStructure);
113
114 $this->expectException(\RuntimeException::class);
115 $this->expectExceptionCode(1480611208);
116 (new SuggestWizardController())->searchAction($serverRequestProphecy->reveal());
117 }
118
119 /**
120 * @test
121 * @dataProvider isTableHiddenIsProperlyRetrievedDataProvider
122 * @param bool $expected
123 * @param array $array
124 */
125 public function isTableHiddenIsProperlyRetrieved(bool $expected, array $array): void
126 {
127 $subject = $this->getAccessibleMock(SuggestWizardController::class, ['dummy'], [], '', false);
128 $this->assertEquals($expected, $subject->_call('isTableHidden', $array));
129 }
130
131 /**
132 * @return array
133 */
134 public function isTableHiddenIsProperlyRetrievedDataProvider(): array
135 {
136 return [
137 'notSetValue' => [false, ['ctrl' => ['hideTable' => null]]],
138 'true' => [true, ['ctrl' => ['hideTable' => true]]],
139 'false' => [false, ['ctrl' => ['hideTable' => false]]],
140 'string with true' => [true, ['ctrl' => ['hideTable' => '1']]],
141 'string with false' => [false, ['ctrl' => ['hideTable' => '0']]],
142 ];
143 }
144 }