‪TYPO3CMS  9.5
FormInlineAjaxControllerTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
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;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪FormInlineAjaxControllerTest extends UnitTestCase
27 {
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 
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 
68  {
69  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
70  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
71  [
72  'ajax' => [
73  'context' => json_encode(
74  [
75  'config' => json_encode([
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 
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 
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 
129  {
130  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
131  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
132  [
133  'ajax' => [
134  'context' => json_encode(
135  [
136  'config' => json_encode([
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 
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 
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 
190  {
191  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
192  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
193  [
194  'ajax' => [
195  'context' => json_encode(
196  [
197  'config' => json_encode([
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 
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 
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 }
‪TYPO3\CMS\Backend\Controller\FormInlineAjaxController
Definition: FormInlineAjaxController.php:37
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\createActionThrowsExceptionIfContextConfigSectionDoesNotValidate
‪createActionThrowsExceptionIfContextConfigSectionDoesNotValidate()
Definition: FormInlineAjaxControllerTest.php:67
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\detailsActionThrowsExceptionIfContextIsEmpty
‪detailsActionThrowsExceptionIfContextIsEmpty()
Definition: FormInlineAjaxControllerTest.php:92
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionDoesNotValidate
‪synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionDoesNotValidate()
Definition: FormInlineAjaxControllerTest.php:189
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\getInlineExpandCollapseStateArraySwitchesToFallbackIfTheBackendUserDoesNotHaveAnUCInlineViewProperty
‪getInlineExpandCollapseStateArraySwitchesToFallbackIfTheBackendUserDoesNotHaveAnUCInlineViewProperty()
Definition: FormInlineAjaxControllerTest.php:217
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest
Definition: FormInlineAjaxControllerTest.php:27
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Backend\Tests\Unit\Controller
Definition: EditDocumentControllerTest.php:3
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\getInlineExpandCollapseStateArrayWillUnserializeUCInlineViewPropertyAsAnArrayWithData
‪getInlineExpandCollapseStateArrayWillUnserializeUCInlineViewPropertyAsAnArrayWithData()
Definition: FormInlineAjaxControllerTest.php:242
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\createActionThrowsExceptionIfContextIsEmpty
‪createActionThrowsExceptionIfContextIsEmpty()
Definition: FormInlineAjaxControllerTest.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\createActionThrowsExceptionIfContextConfigSectionIsEmpty
‪createActionThrowsExceptionIfContextConfigSectionIsEmpty()
Definition: FormInlineAjaxControllerTest.php:49
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\detailsActionThrowsExceptionIfContextConfigSectionIsEmpty
‪detailsActionThrowsExceptionIfContextConfigSectionIsEmpty()
Definition: FormInlineAjaxControllerTest.php:110
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\detailsActionThrowsExceptionIfContextConfigSectionDoesNotValidate
‪detailsActionThrowsExceptionIfContextConfigSectionDoesNotValidate()
Definition: FormInlineAjaxControllerTest.php:128
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionIsEmpty
‪synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionIsEmpty()
Definition: FormInlineAjaxControllerTest.php:171
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\synchronizeLocalizeActionThrowsExceptionIfContextIsEmpty
‪synchronizeLocalizeActionThrowsExceptionIfContextIsEmpty()
Definition: FormInlineAjaxControllerTest.php:153