[TASK] Create own response instance in controller actions
[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\ServerRequestInterface;
18 use TYPO3\CMS\Backend\Controller\Wizard\SuggestWizardController;
19 use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Test case
24 */
25 class SuggestWizardControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
26 {
27 /**
28 * Subject is not notice free, disable E_NOTICES
29 */
30 protected static $suppressNotices = true;
31
32 /**
33 * @test
34 */
35 public function getFlexFieldConfigurationThrowsExceptionIfSimpleFlexFieldIsNotFound()
36 {
37 $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
38 $serverRequestProphecy->getParsedBody()->willReturn([
39 'value' => 'theSearchValue',
40 'table' => 'aTable',
41 'field' => 'aField',
42 'uid' => 'aUid',
43 'pid' => 'aPid',
44 'dataStructureIdentifier' => ['anIdentifier'],
45 'flexFormSheetName' => 'sDb',
46 'flexFormFieldName' => 'aField',
47 'flexFormContainerName' => '',
48 'flexFormContainerFieldName' => '',
49 ]);
50
51 $dataStructure = [
52 'sheets' => [
53 'sDb' => [
54 'ROOT' => [
55 'el' => [
56 'differentField' => [
57 'TCEforms' => [
58 'config' => [
59 'Sublevel field configuration',
60 ],
61 ],
62 ],
63 ],
64 ],
65 ],
66 ],
67 ];
68 $flexFormToolsProphecy = $this->prophesize(FlexFormTools::class);
69 GeneralUtility::addInstance(FlexFormTools::class, $flexFormToolsProphecy->reveal());
70 $flexFormToolsProphecy->parseDataStructureByIdentifier(json_encode(['anIdentifier']))->willReturn($dataStructure);
71
72 $this->expectException(\RuntimeException::class);
73 $this->expectExceptionCode(1480609491);
74 (new SuggestWizardController())->searchAction($serverRequestProphecy->reveal());
75 }
76
77 /**
78 * @test
79 */
80 public function getFlexFieldConfigurationThrowsExceptionIfSectionContainerFlexFieldIsNotFound()
81 {
82 $serverRequestProphecy = $this->prophesize(ServerRequestInterface::class);
83 $serverRequestProphecy->getParsedBody()->willReturn([
84 'value' => 'theSearchValue',
85 'table' => 'aTable',
86 'field' => 'aField',
87 'uid' => 'aUid',
88 'pid' => 'aPid',
89 'dataStructureIdentifier' => ['anIdentifier'],
90 'flexFormSheetName' => 'sDb',
91 'flexFormFieldName' => 'aField',
92 'flexFormContainerName' => 'aContainer',
93 'flexFormContainerFieldName' => 'aContainerFieldName',
94 ]);
95
96 $dataStructure = [
97 'sheets' => [
98 'sDb' => [
99 'ROOT' => [
100 'el' => [
101 'notTheFieldYouAreLookingFor' => [
102 'TCEforms' => [
103 'config' => [
104 'Sublevel field configuration',
105 ],
106 ],
107 ],
108 ],
109 ],
110 ],
111 ],
112 ];
113 $flexFormToolsProphecy = $this->prophesize(FlexFormTools::class);
114 GeneralUtility::addInstance(FlexFormTools::class, $flexFormToolsProphecy->reveal());
115 $flexFormToolsProphecy->parseDataStructureByIdentifier(json_encode(['anIdentifier']))->willReturn($dataStructure);
116
117 $this->expectException(\RuntimeException::class);
118 $this->expectExceptionCode(1480611208);
119 (new SuggestWizardController())->searchAction($serverRequestProphecy->reveal());
120 }
121
122 /**
123 * @test
124 * @dataProvider isTableHiddenIsProperlyRetrievedDataProvider
125 */
126 public function isTableHiddenIsProperlyRetrieved($expected, $array)
127 {
128 $subject = $this->getAccessibleMock(SuggestWizardController::class, ['dummy'], [], '', false);
129 $this->assertEquals($expected, $subject->_call('isTableHidden', $array));
130 }
131
132 public function isTableHiddenIsProperlyRetrievedDataProvider()
133 {
134 return [
135 'notSetValue' => [false, ['ctrl' => ['hideTable' => null]]],
136 'true' => [true, ['ctrl' => ['hideTable' => true]]],
137 'false' => [false, ['ctrl' => ['hideTable' => false]]],
138 'string with true' => [true, ['ctrl' => ['hideTable' => '1']]],
139 'string with false' => [false, ['ctrl' => ['hideTable' => '0']]],
140 ];
141 }
142 }