‪TYPO3CMS  11.5
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 Prophecy\PhpUnit\ProphecyTrait;
21 use Psr\Http\Message\ServerRequestInterface;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪FormInlineAjaxControllerTest extends UnitTestCase
30 {
31  use ProphecyTrait;
32 
33  protected function ‪setUp(): void
34  {
35  parent::setUp();
36  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = '';
37  }
38 
43  {
44  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
45  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
46  [
47  'ajax' => [
48  'context' => '',
49  ],
50  ]
51  );
52  $this->expectException(\RuntimeException::class);
53  $this->expectExceptionCode(1489751361);
54  (new ‪FormInlineAjaxController())->createAction($requestProphecy->reveal());
55  }
56 
61  {
62  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
63  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
64  [
65  'ajax' => [
66  'context' => json_encode([ 'config' => '' ]),
67  ],
68  ]
69  );
70  $this->expectException(\RuntimeException::class);
71  $this->expectExceptionCode(1489751362);
72  (new FormInlineAjaxController())->createAction($requestProphecy->reveal());
73  }
74 
79  {
80  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
81  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
82  [
83  'ajax' => [
84  'context' => json_encode(
85  [
86  'config' => json_encode([
87  'type' => 'inline',
88  ]),
89  'hmac' => 'anInvalidHash',
90  ]
91  ),
92  ],
93  ]
94  );
95  $this->expectException(\RuntimeException::class);
96  $this->expectExceptionCode(1489751363);
97  (new FormInlineAjaxController())->createAction($requestProphecy->reveal());
98  }
99 
104  {
105  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
106  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
107  [
108  'ajax' => [
109  'context' => '',
110  ],
111  ]
112  );
113  $this->expectException(\RuntimeException::class);
114  $this->expectExceptionCode(1489751361);
115  (new FormInlineAjaxController())->detailsAction($requestProphecy->reveal());
116  }
117 
122  {
123  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
124  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
125  [
126  'ajax' => [
127  'context' => json_encode([ 'config' => '' ]),
128  ],
129  ]
130  );
131  $this->expectException(\RuntimeException::class);
132  $this->expectExceptionCode(1489751362);
133  (new FormInlineAjaxController())->detailsAction($requestProphecy->reveal());
134  }
135 
140  {
141  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
142  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
143  [
144  'ajax' => [
145  'context' => json_encode(
146  [
147  'config' => json_encode([
148  'type' => 'inline',
149  ]),
150  'hmac' => 'anInvalidHash',
151  ]
152  ),
153  ],
154  ]
155  );
156  $this->expectException(\RuntimeException::class);
157  $this->expectExceptionCode(1489751363);
158  (new FormInlineAjaxController())->detailsAction($requestProphecy->reveal());
159  }
160 
165  {
166  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
167  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
168  [
169  'ajax' => [
170  'context' => '',
171  ],
172  ]
173  );
174  $this->expectException(\RuntimeException::class);
175  $this->expectExceptionCode(1489751361);
176  (new FormInlineAjaxController())->synchronizeLocalizeAction($requestProphecy->reveal());
177  }
178 
183  {
184  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
185  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
186  [
187  'ajax' => [
188  'context' => json_encode([ 'config' => '' ]),
189  ],
190  ]
191  );
192  $this->expectException(\RuntimeException::class);
193  $this->expectExceptionCode(1489751362);
194  (new FormInlineAjaxController())->synchronizeLocalizeAction($requestProphecy->reveal());
195  }
196 
201  {
202  $requestProphecy = $this->prophesize(ServerRequestInterface::class);
203  $requestProphecy->getParsedBody()->shouldBeCalled()->willReturn(
204  [
205  'ajax' => [
206  'context' => json_encode(
207  [
208  'config' => json_encode([
209  'type' => 'inline',
210  ]),
211  'hmac' => 'anInvalidHash',
212  ]
213  ),
214  ],
215  ]
216  );
217  $this->expectException(\RuntimeException::class);
218  $this->expectExceptionCode(1489751363);
219  (new FormInlineAjaxController())->synchronizeLocalizeAction($requestProphecy->reveal());
220  }
221 
229  {
230  $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
231  $backendUser = $backendUserProphecy->reveal();
232  $backendUser->uc = [];
233 
234  $mockObject = $this->getAccessibleMock(
235  FormInlineAjaxController::class,
236  ['getBackendUserAuthentication'],
237  [],
238  '',
239  false
240  );
241  $mockObject->method('getBackendUserAuthentication')->willReturn($backendUser);
242  $result = $mockObject->_call('getInlineExpandCollapseStateArray');
243 
244  self::assertEmpty($result);
245  }
246 
254  {
255  $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
256  $backendUser = $backendUserProphecy->reveal();
257  $backendUser->uc = ['inlineView' => json_encode(['foo' => 'bar'])];
258 
259  $mockObject = $this->getAccessibleMock(
260  FormInlineAjaxController::class,
261  ['getBackendUserAuthentication'],
262  [],
263  '',
264  false
265  );
266  $mockObject->method('getBackendUserAuthentication')->willReturn($backendUser);
267  $result = $mockObject->_call('getInlineExpandCollapseStateArray');
268 
269  self::assertNotEmpty($result);
270  }
271 }
‪TYPO3\CMS\Backend\Controller\FormInlineAjaxController
Definition: FormInlineAjaxController.php:40
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\createActionThrowsExceptionIfContextConfigSectionDoesNotValidate
‪createActionThrowsExceptionIfContextConfigSectionDoesNotValidate()
Definition: FormInlineAjaxControllerTest.php:77
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\detailsActionThrowsExceptionIfContextIsEmpty
‪detailsActionThrowsExceptionIfContextIsEmpty()
Definition: FormInlineAjaxControllerTest.php:102
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionDoesNotValidate
‪synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionDoesNotValidate()
Definition: FormInlineAjaxControllerTest.php:199
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\getInlineExpandCollapseStateArraySwitchesToFallbackIfTheBackendUserDoesNotHaveAnUCInlineViewProperty
‪getInlineExpandCollapseStateArraySwitchesToFallbackIfTheBackendUserDoesNotHaveAnUCInlineViewProperty()
Definition: FormInlineAjaxControllerTest.php:227
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\setUp
‪setUp()
Definition: FormInlineAjaxControllerTest.php:32
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest
Definition: FormInlineAjaxControllerTest.php:30
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Tests\Unit\Controller
Definition: EditDocumentControllerTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\getInlineExpandCollapseStateArrayWillUnserializeUCInlineViewPropertyAsAnArrayWithData
‪getInlineExpandCollapseStateArrayWillUnserializeUCInlineViewPropertyAsAnArrayWithData()
Definition: FormInlineAjaxControllerTest.php:252
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\createActionThrowsExceptionIfContextIsEmpty
‪createActionThrowsExceptionIfContextIsEmpty()
Definition: FormInlineAjaxControllerTest.php:41
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\createActionThrowsExceptionIfContextConfigSectionIsEmpty
‪createActionThrowsExceptionIfContextConfigSectionIsEmpty()
Definition: FormInlineAjaxControllerTest.php:59
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\detailsActionThrowsExceptionIfContextConfigSectionIsEmpty
‪detailsActionThrowsExceptionIfContextConfigSectionIsEmpty()
Definition: FormInlineAjaxControllerTest.php:120
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\detailsActionThrowsExceptionIfContextConfigSectionDoesNotValidate
‪detailsActionThrowsExceptionIfContextConfigSectionDoesNotValidate()
Definition: FormInlineAjaxControllerTest.php:138
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionIsEmpty
‪synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionIsEmpty()
Definition: FormInlineAjaxControllerTest.php:181
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\synchronizeLocalizeActionThrowsExceptionIfContextIsEmpty
‪synchronizeLocalizeActionThrowsExceptionIfContextIsEmpty()
Definition: FormInlineAjaxControllerTest.php:163