[CLEANUP] Remove/Replace non-standard phpdoc annotations
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Controller / FormInlineAjaxControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Controller;
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\FormInlineAjaxController;
20 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
21
22 /**
23 * Test case
24 */
25 class FormInlineAjaxControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
26 {
27 /**
28 * @test
29 */
30 public function createActionThrowsExceptionIfContextIsEmpty()
31 {
32 $responseProphecy = $this->prophesize(ResponseInterface::class);
33 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
34 $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
35 [
36 'ajax' => [
37 'context' => '',
38 ],
39 ]
40 );
41 $this->expectException(\RuntimeException::class);
42 $this->expectExceptionCode(1489751361);
43 (new FormInlineAjaxController())->createAction($requestProphecy->reveal(), $responseProphecy->reveal());
44 }
45
46 /**
47 * @test
48 */
49 public function createActionThrowsExceptionIfContextConfigSectionIsEmpty()
50 {
51 $responseProphecy = $this->prophesize(ResponseInterface::class);
52 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
53 $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
54 [
55 'ajax' => [
56 'context' => json_encode([ 'config' => '' ]),
57 ],
58 ]
59 );
60 $this->expectException(\RuntimeException::class);
61 $this->expectExceptionCode(1489751362);
62 (new FormInlineAjaxController())->createAction($requestProphecy->reveal(), $responseProphecy->reveal());
63 }
64
65 /**
66 * @test
67 */
68 public function createActionThrowsExceptionIfContextConfigSectionDoesNotValidate()
69 {
70 $responseProphecy = $this->prophesize(ResponseInterface::class);
71 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
72 $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
73 [
74 'ajax' => [
75 'context' => json_encode(
76 [
77 'config' => [
78 'type' => 'inline',
79 ],
80 'hmac' => 'anInvalidHash',
81 ]
82 ),
83 ],
84 ]
85 );
86 $this->expectException(\RuntimeException::class);
87 $this->expectExceptionCode(1489751363);
88 (new FormInlineAjaxController())->createAction($requestProphecy->reveal(), $responseProphecy->reveal());
89 }
90
91 /**
92 * @test
93 */
94 public function detailsActionThrowsExceptionIfContextIsEmpty()
95 {
96 $responseProphecy = $this->prophesize(ResponseInterface::class);
97 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
98 $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
99 [
100 'ajax' => [
101 'context' => '',
102 ],
103 ]
104 );
105 $this->expectException(\RuntimeException::class);
106 $this->expectExceptionCode(1489751361);
107 (new FormInlineAjaxController())->detailsAction($requestProphecy->reveal(), $responseProphecy->reveal());
108 }
109
110 /**
111 * @test
112 */
113 public function detailsActionThrowsExceptionIfContextConfigSectionIsEmpty()
114 {
115 $responseProphecy = $this->prophesize(ResponseInterface::class);
116 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
117 $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
118 [
119 'ajax' => [
120 'context' => json_encode([ 'config' => '' ]),
121 ],
122 ]
123 );
124 $this->expectException(\RuntimeException::class);
125 $this->expectExceptionCode(1489751362);
126 (new FormInlineAjaxController())->detailsAction($requestProphecy->reveal(), $responseProphecy->reveal());
127 }
128
129 /**
130 * @test
131 */
132 public function detailsActionThrowsExceptionIfContextConfigSectionDoesNotValidate()
133 {
134 $responseProphecy = $this->prophesize(ResponseInterface::class);
135 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
136 $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
137 [
138 'ajax' => [
139 'context' => json_encode(
140 [
141 'config' => [
142 'type' => 'inline',
143 ],
144 'hmac' => 'anInvalidHash',
145 ]
146 ),
147 ],
148 ]
149 );
150 $this->expectException(\RuntimeException::class);
151 $this->expectExceptionCode(1489751363);
152 (new FormInlineAjaxController())->detailsAction($requestProphecy->reveal(), $responseProphecy->reveal());
153 }
154
155 /**
156 * @test
157 */
158 public function synchronizeLocalizeActionThrowsExceptionIfContextIsEmpty()
159 {
160 $responseProphecy = $this->prophesize(ResponseInterface::class);
161 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
162 $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
163 [
164 'ajax' => [
165 'context' => '',
166 ],
167 ]
168 );
169 $this->expectException(\RuntimeException::class);
170 $this->expectExceptionCode(1489751361);
171 (new FormInlineAjaxController())->synchronizeLocalizeAction($requestProphecy->reveal(), $responseProphecy->reveal());
172 }
173
174 /**
175 * @test
176 */
177 public function synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionIsEmpty()
178 {
179 $responseProphecy = $this->prophesize(ResponseInterface::class);
180 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
181 $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
182 [
183 'ajax' => [
184 'context' => json_encode([ 'config' => '' ]),
185 ],
186 ]
187 );
188 $this->expectException(\RuntimeException::class);
189 $this->expectExceptionCode(1489751362);
190 (new FormInlineAjaxController())->synchronizeLocalizeAction($requestProphecy->reveal(), $responseProphecy->reveal());
191 }
192
193 /**
194 * @test
195 */
196 public function synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionDoesNotValidate()
197 {
198 $responseProphecy = $this->prophesize(ResponseInterface::class);
199 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
200 $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
201 [
202 'ajax' => [
203 'context' => json_encode(
204 [
205 'config' => [
206 'type' => 'inline',
207 ],
208 'hmac' => 'anInvalidHash',
209 ]
210 ),
211 ],
212 ]
213 );
214 $this->expectException(\RuntimeException::class);
215 $this->expectExceptionCode(1489751363);
216 (new FormInlineAjaxController())->synchronizeLocalizeAction($requestProphecy->reveal(), $responseProphecy->reveal());
217 }
218
219 /**
220 * Fallback for IRRE items without inline view attribute
221 * @see https://forge.typo3.org/issues/76561
222 *
223 * @test
224 */
225 public function getInlineExpandCollapseStateArraySwitchesToFallbackIfTheBackendUserDoesNotHaveAnUCInlineViewProperty()
226 {
227 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
228 $backendUserProphecy->uc = [];
229 $backendUser = $backendUserProphecy->reveal();
230
231 $mockObject = $this->getAccessibleMock(
232 FormInlineAjaxController::class,
233 ['getBackendUserAuthentication'],
234 [],
235 '',
236 false
237 );
238 $mockObject->method('getBackendUserAuthentication')->willReturn($backendUser);
239 $result = $mockObject->_call('getInlineExpandCollapseStateArray');
240
241 $this->assertEmpty($result);
242 }
243
244 /**
245 * Unserialize uc inline view string for IRRE item
246 * @see https://forge.typo3.org/issues/76561
247 *
248 * @test
249 */
250 public function getInlineExpandCollapseStateArrayWillUnserializeUCInlineViewPropertyAsAnArrayWithData()
251 {
252 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
253 $backendUserProphecy->uc = ['inlineView' => serialize(['foo' => 'bar'])];
254 $backendUser = $backendUserProphecy->reveal();
255
256 $mockObject = $this->getAccessibleMock(
257 FormInlineAjaxController::class,
258 ['getBackendUserAuthentication'],
259 [],
260 '',
261 false
262 );
263 $mockObject->method('getBackendUserAuthentication')->willReturn($backendUser);
264 $result = $mockObject->_call('getInlineExpandCollapseStateArray');
265
266 $this->assertNotEmpty($result);
267 }
268 }