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