[!!!][TASK] Improve flex and TCA handling in FormEngine
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Controller / Wizard / SuggestWizardControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Controller\Wizard;
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 Psr\Http\Message\ResponseInterface;
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
23 /**
24 * Test case
25 */
26 class SuggestWizardControllerTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
27 {
28 /**
29 * @test
30 */
31 public function getFlexFieldConfigurationThrowsExceptionIfSimpleFlexFieldIsNotFound()
32 {
33 $responseProphecy = $this->prophesize(ResponseInterface::class);
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(), $responseProphecy->reveal());
72 }
73
74 /**
75 * @test
76 */
77 public function getFlexFieldConfigurationThrowsExceptionIfSectionContainerFlexFieldIsNotFound()
78 {
79 $responseProphecy = $this->prophesize(ResponseInterface::class);
80 $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
81 $serverRequestProphecy->getParsedBody()->willReturn([
82 'value' => 'theSearchValue',
83 'table' => 'aTable',
84 'field' => 'aField',
85 'uid' => 'aUid',
86 'pid' => 'aPid',
87 'dataStructureIdentifier' => ['anIdentifier'],
88 'flexFormSheetName' => 'sDb',
89 'flexFormFieldName' => 'aField',
90 'flexFormContainerName' => 'aContainer',
91 'flexFormContainerFieldName' => 'aContainerFieldName',
92 ]);
93
94 $dataStructure = [
95 'sheets' => [
96 'sDb' => [
97 'ROOT' => [
98 'el' => [
99 'notTheFieldYouAreLookingFor' => [
100 'TCEforms' => [
101 'config' => [
102 'Sublevel field configuration',
103 ],
104 ],
105 ],
106 ],
107 ],
108 ],
109 ],
110 ];
111 $flexFormToolsProphecy = $this->prophesize(FlexFormTools::class);
112 GeneralUtility::addInstance(FlexFormTools::class, $flexFormToolsProphecy->reveal());
113 $flexFormToolsProphecy->parseDataStructureByIdentifier(json_encode(['anIdentifier']))->willReturn($dataStructure);
114
115 $this->expectException(\RuntimeException::class);
116 $this->expectExceptionCode(1480611208);
117 (new SuggestWizardController())->searchAction($serverRequestProphecy->reveal(), $responseProphecy->reveal());
118 }
119
120 /**
121 * @test
122 * @dataProvider isTableHiddenIsProperlyRetrievedDataProvider
123 */
124 public function isTableHiddenIsProperlyRetrieved($expected, $array)
125 {
126 $subject = $this->getAccessibleMock(SuggestWizardController::class, ['dummy'], [], '', false);
127 $this->assertEquals($expected, $subject->_call('isTableHidden', $array));
128 }
129
130 public function isTableHiddenIsProperlyRetrievedDataProvider()
131 {
132 return [
133 'notSetValue' => [false, ['ctrl' => ['hideTable' => null]]],
134 'true' => [true, ['ctrl' => ['hideTable' => true]]],
135 'false' => [false, ['ctrl' => ['hideTable' => false]]],
136 'string with true' => [true, ['ctrl' => ['hideTable' => '1']]],
137 'string with false' => [false, ['ctrl' => ['hideTable' => '0']]],
138 ];
139 }
140 }