[TASK] Clean up TSFE constructor initialization
[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 $dataStructureIdentifier = '{"type":"tca","tableName":"tt_content","fieldName":"pi_flexform","dataStructureKey":"blog_example,list"}';
35 $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
36 $serverRequestProphecy->getParsedBody()->willReturn([
37 'value' => 'theSearchValue',
38 'table' => 'aTable',
39 'field' => 'aField',
40 'uid' => 'aUid',
41 'pid' => 'aPid',
42 'dataStructureIdentifier' => $dataStructureIdentifier,
43 'flexFormSheetName' => 'sDb',
44 'flexFormFieldName' => 'aField',
45 'flexFormContainerName' => '',
46 'flexFormContainerFieldName' => '',
47 ]);
48
49 $dataStructure = [
50 'sheets' => [
51 'sDb' => [
52 'ROOT' => [
53 'el' => [
54 'differentField' => [
55 'TCEforms' => [
56 'config' => [
57 'Sublevel field configuration',
58 ],
59 ],
60 ],
61 ],
62 ],
63 ],
64 ],
65 ];
66 $flexFormToolsProphecy = $this->prophesize(FlexFormTools::class);
67 GeneralUtility::addInstance(FlexFormTools::class, $flexFormToolsProphecy->reveal());
68 $flexFormToolsProphecy->parseDataStructureByIdentifier($dataStructureIdentifier)->willReturn($dataStructure);
69
70 $this->expectException(\RuntimeException::class);
71 $this->expectExceptionCode(1480609491);
72 (new SuggestWizardController())->searchAction($serverRequestProphecy->reveal());
73 }
74
75 /**
76 * @test
77 */
78 public function getFlexFieldConfigurationThrowsExceptionIfSectionContainerFlexFieldIsNotFound(): void
79 {
80 $dataStructureIdentifier = '{"type":"tca","tableName":"tt_content","fieldName":"pi_flexform","dataStructureKey":"blog_example,list"}';
81 $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
82 $serverRequestProphecy->getParsedBody()->willReturn([
83 'value' => 'theSearchValue',
84 'table' => 'aTable',
85 'field' => 'aField',
86 'uid' => 'aUid',
87 'pid' => 'aPid',
88 'dataStructureIdentifier' => $dataStructureIdentifier,
89 'flexFormSheetName' => 'sDb',
90 'flexFormFieldName' => 'aField',
91 'flexFormContainerName' => 'aContainer',
92 'flexFormContainerFieldName' => 'aContainerFieldName',
93 ]);
94
95 $dataStructure = [
96 'sheets' => [
97 'sDb' => [
98 'ROOT' => [
99 'el' => [
100 'notTheFieldYouAreLookingFor' => [
101 'TCEforms' => [
102 'config' => [
103 'Sublevel field configuration',
104 ],
105 ],
106 ],
107 ],
108 ],
109 ],
110 ],
111 ];
112 $flexFormToolsProphecy = $this->prophesize(FlexFormTools::class);
113 GeneralUtility::addInstance(FlexFormTools::class, $flexFormToolsProphecy->reveal());
114 $flexFormToolsProphecy->parseDataStructureByIdentifier($dataStructureIdentifier)->willReturn($dataStructure);
115
116 $this->expectException(\RuntimeException::class);
117 $this->expectExceptionCode(1480611208);
118 (new SuggestWizardController())->searchAction($serverRequestProphecy->reveal());
119 }
120
121 /**
122 * @test
123 * @dataProvider isTableHiddenIsProperlyRetrievedDataProvider
124 * @param bool $expected
125 * @param array $array
126 */
127 public function isTableHiddenIsProperlyRetrieved(bool $expected, array $array): void
128 {
129 $subject = $this->getAccessibleMock(SuggestWizardController::class, ['dummy'], [], '', false);
130 $this->assertEquals($expected, $subject->_call('isTableHidden', $array));
131 }
132
133 /**
134 * @return array
135 */
136 public function isTableHiddenIsProperlyRetrievedDataProvider(): array
137 {
138 return [
139 'notSetValue' => [false, ['ctrl' => ['hideTable' => null]]],
140 'true' => [true, ['ctrl' => ['hideTable' => true]]],
141 'false' => [false, ['ctrl' => ['hideTable' => false]]],
142 'string with true' => [true, ['ctrl' => ['hideTable' => '1']]],
143 'string with false' => [false, ['ctrl' => ['hideTable' => '0']]],
144 ];
145 }
146 }