‪TYPO3CMS  10.4
FormInlineAjaxControllerTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
20 use Psr\Http\Message\ServerRequestInterface;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪FormInlineAjaxControllerTest extends UnitTestCase
29 {
34  {
35  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
36  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
37  [
38  'ajax' => [
39  'context' => '',
40  ],
41  ]
42  );
43  $this->expectException(\RuntimeException::class);
44  $this->expectExceptionCode(1489751361);
45  (new ‪FormInlineAjaxController())->createAction($requestProphecy->reveal());
46  }
47 
52  {
53  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
54  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
55  [
56  'ajax' => [
57  'context' => json_encode([ 'config' => '' ]),
58  ],
59  ]
60  );
61  $this->expectException(\RuntimeException::class);
62  $this->expectExceptionCode(1489751362);
63  (new ‪FormInlineAjaxController())->createAction($requestProphecy->reveal());
64  }
65 
70  {
71  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
72  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
73  [
74  'ajax' => [
75  'context' => json_encode(
76  [
77  'config' => json_encode([
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());
89  }
90 
95  {
96  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
97  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
98  [
99  'ajax' => [
100  'context' => '',
101  ],
102  ]
103  );
104  $this->expectException(\RuntimeException::class);
105  $this->expectExceptionCode(1489751361);
106  (new ‪FormInlineAjaxController())->detailsAction($requestProphecy->reveal());
107  }
108 
113  {
114  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
115  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
116  [
117  'ajax' => [
118  'context' => json_encode([ 'config' => '' ]),
119  ],
120  ]
121  );
122  $this->expectException(\RuntimeException::class);
123  $this->expectExceptionCode(1489751362);
124  (new ‪FormInlineAjaxController())->detailsAction($requestProphecy->reveal());
125  }
126 
131  {
132  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
133  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
134  [
135  'ajax' => [
136  'context' => json_encode(
137  [
138  'config' => json_encode([
139  'type' => 'inline',
140  ]),
141  'hmac' => 'anInvalidHash',
142  ]
143  ),
144  ],
145  ]
146  );
147  $this->expectException(\RuntimeException::class);
148  $this->expectExceptionCode(1489751363);
149  (new ‪FormInlineAjaxController())->detailsAction($requestProphecy->reveal());
150  }
151 
156  {
157  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
158  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
159  [
160  'ajax' => [
161  'context' => '',
162  ],
163  ]
164  );
165  $this->expectException(\RuntimeException::class);
166  $this->expectExceptionCode(1489751361);
167  (new ‪FormInlineAjaxController())->synchronizeLocalizeAction($requestProphecy->reveal());
168  }
169 
174  {
175  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
176  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
177  [
178  'ajax' => [
179  'context' => json_encode([ 'config' => '' ]),
180  ],
181  ]
182  );
183  $this->expectException(\RuntimeException::class);
184  $this->expectExceptionCode(1489751362);
185  (new ‪FormInlineAjaxController())->synchronizeLocalizeAction($requestProphecy->reveal());
186  }
187 
192  {
193  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
194  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
195  [
196  'ajax' => [
197  'context' => json_encode(
198  [
199  'config' => json_encode([
200  'type' => 'inline',
201  ]),
202  'hmac' => 'anInvalidHash',
203  ]
204  ),
205  ],
206  ]
207  );
208  $this->expectException(\RuntimeException::class);
209  $this->expectExceptionCode(1489751363);
210  (new ‪FormInlineAjaxController())->synchronizeLocalizeAction($requestProphecy->reveal());
211  }
212 
220  {
221  $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
222  $backendUserProphecy->uc = [];
223  $backendUser = $backendUserProphecy->reveal();
224 
225  $mockObject = $this->getAccessibleMock(
226  FormInlineAjaxController::class,
227  ['getBackendUserAuthentication'],
228  [],
229  '',
230  false
231  );
232  $mockObject->method('getBackendUserAuthentication')->willReturn($backendUser);
233  $result = $mockObject->_call('getInlineExpandCollapseStateArray');
234 
235  self::assertEmpty($result);
236  }
237 
245  {
246  $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
247  $backendUserProphecy->uc = ['inlineView' => json_encode(['foo' => 'bar'])];
248  $backendUser = $backendUserProphecy->reveal();
249 
250  $mockObject = $this->getAccessibleMock(
251  FormInlineAjaxController::class,
252  ['getBackendUserAuthentication'],
253  [],
254  '',
255  false
256  );
257  $mockObject->method('getBackendUserAuthentication')->willReturn($backendUser);
258  $result = $mockObject->_call('getInlineExpandCollapseStateArray');
259 
260  self::assertNotEmpty($result);
261  }
262 }
‪TYPO3\CMS\Backend\Controller\FormInlineAjaxController
Definition: FormInlineAjaxController.php:39
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\createActionThrowsExceptionIfContextConfigSectionDoesNotValidate
‪createActionThrowsExceptionIfContextConfigSectionDoesNotValidate()
Definition: FormInlineAjaxControllerTest.php:69
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\detailsActionThrowsExceptionIfContextIsEmpty
‪detailsActionThrowsExceptionIfContextIsEmpty()
Definition: FormInlineAjaxControllerTest.php:94
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionDoesNotValidate
‪synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionDoesNotValidate()
Definition: FormInlineAjaxControllerTest.php:191
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\getInlineExpandCollapseStateArraySwitchesToFallbackIfTheBackendUserDoesNotHaveAnUCInlineViewProperty
‪getInlineExpandCollapseStateArraySwitchesToFallbackIfTheBackendUserDoesNotHaveAnUCInlineViewProperty()
Definition: FormInlineAjaxControllerTest.php:219
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest
Definition: FormInlineAjaxControllerTest.php:29
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Tests\Unit\Controller
Definition: EditDocumentControllerTest.php:16
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\getInlineExpandCollapseStateArrayWillUnserializeUCInlineViewPropertyAsAnArrayWithData
‪getInlineExpandCollapseStateArrayWillUnserializeUCInlineViewPropertyAsAnArrayWithData()
Definition: FormInlineAjaxControllerTest.php:244
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\createActionThrowsExceptionIfContextIsEmpty
‪createActionThrowsExceptionIfContextIsEmpty()
Definition: FormInlineAjaxControllerTest.php:33
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\createActionThrowsExceptionIfContextConfigSectionIsEmpty
‪createActionThrowsExceptionIfContextConfigSectionIsEmpty()
Definition: FormInlineAjaxControllerTest.php:51
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\detailsActionThrowsExceptionIfContextConfigSectionIsEmpty
‪detailsActionThrowsExceptionIfContextConfigSectionIsEmpty()
Definition: FormInlineAjaxControllerTest.php:112
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\detailsActionThrowsExceptionIfContextConfigSectionDoesNotValidate
‪detailsActionThrowsExceptionIfContextConfigSectionDoesNotValidate()
Definition: FormInlineAjaxControllerTest.php:130
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionIsEmpty
‪synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionIsEmpty()
Definition: FormInlineAjaxControllerTest.php:173
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\synchronizeLocalizeActionThrowsExceptionIfContextIsEmpty
‪synchronizeLocalizeActionThrowsExceptionIfContextIsEmpty()
Definition: FormInlineAjaxControllerTest.php:155