‪TYPO3CMS  ‪main
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 PHPUnit\Framework\Attributes\Test;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 final class ‪FormInlineAjaxControllerTest extends UnitTestCase
29 {
30  protected function ‪setUp(): void
31  {
32  parent::setUp();
33  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = '';
34  }
35 
36  #[Test]
38  {
39  $request = (new ‪ServerRequest())->withQueryParams(
40  [
41  'ajax' => [
42  'context' => '',
43  ],
44  ]
45  );
46  $this->expectException(\RuntimeException::class);
47  $this->expectExceptionCode(1489751361);
48  (new ‪FormInlineAjaxController(new ‪FormDataCompiler(), new ‪HashService()))->createAction($request);
49  }
50 
51  #[Test]
53  {
54  $request = (new ‪ServerRequest())->withQueryParams(
55  [
56  'ajax' => [
57  'context' => json_encode([ 'config' => '' ]),
58  ],
59  ]
60  );
61  $this->expectException(\RuntimeException::class);
62  $this->expectExceptionCode(1489751362);
63  (new ‪FormInlineAjaxController(new ‪FormDataCompiler(), new ‪HashService()))->createAction($request);
64  }
65 
66  #[Test]
68  {
69  $request = (new ‪ServerRequest())->withQueryParams(
70  [
71  'ajax' => [
72  'context' => json_encode(
73  [
74  'config' => json_encode([
75  'type' => 'inline',
76  ]),
77  'hmac' => 'anInvalidHash',
78  ]
79  ),
80  ],
81  ]
82  );
83  $this->expectException(\RuntimeException::class);
84  $this->expectExceptionCode(1489751363);
85  (new ‪FormInlineAjaxController(new ‪FormDataCompiler(), new ‪HashService()))->createAction($request);
86  }
87 
88  #[Test]
90  {
91  $request = (new ‪ServerRequest())->withQueryParams(
92  [
93  'ajax' => [
94  'context' => '',
95  ],
96  ]
97  );
98  $this->expectException(\RuntimeException::class);
99  $this->expectExceptionCode(1489751361);
100  (new ‪FormInlineAjaxController(new ‪FormDataCompiler(), new ‪HashService()))->detailsAction($request);
101  }
102 
103  #[Test]
105  {
106  $request = (new ‪ServerRequest())->withQueryParams(
107  [
108  'ajax' => [
109  'context' => json_encode([ 'config' => '' ]),
110  ],
111  ]
112  );
113  $this->expectException(\RuntimeException::class);
114  $this->expectExceptionCode(1489751362);
115  (new ‪FormInlineAjaxController(new ‪FormDataCompiler(), new ‪HashService()))->detailsAction($request);
116  }
117 
118  #[Test]
120  {
121  $request = (new ‪ServerRequest())->withQueryParams(
122  [
123  'ajax' => [
124  'context' => json_encode(
125  [
126  'config' => json_encode([
127  'type' => 'inline',
128  ]),
129  'hmac' => 'anInvalidHash',
130  ]
131  ),
132  ],
133  ]
134  );
135  $this->expectException(\RuntimeException::class);
136  $this->expectExceptionCode(1489751363);
137  (new ‪FormInlineAjaxController(new ‪FormDataCompiler(), new ‪HashService()))->detailsAction($request);
138  }
139 
140  #[Test]
142  {
143  $request = (new ‪ServerRequest())->withQueryParams(
144  [
145  'ajax' => [
146  'context' => '',
147  ],
148  ]
149  );
150  $this->expectException(\RuntimeException::class);
151  $this->expectExceptionCode(1489751361);
152  (new ‪FormInlineAjaxController(new ‪FormDataCompiler(), new ‪HashService()))->synchronizeLocalizeAction($request);
153  }
154 
155  #[Test]
157  {
158  $request = (new ‪ServerRequest())->withQueryParams(
159  [
160  'ajax' => [
161  'context' => json_encode([ 'config' => '' ]),
162  ],
163  ]
164  );
165  $this->expectException(\RuntimeException::class);
166  $this->expectExceptionCode(1489751362);
167  (new ‪FormInlineAjaxController(new ‪FormDataCompiler(), new ‪HashService()))->synchronizeLocalizeAction($request);
168  }
169 
170  #[Test]
172  {
173  $request = (new ‪ServerRequest())->withQueryParams(
174  [
175  'ajax' => [
176  'context' => json_encode(
177  [
178  'config' => json_encode([
179  'type' => 'inline',
180  ]),
181  'hmac' => 'anInvalidHash',
182  ]
183  ),
184  ],
185  ]
186  );
187  $this->expectException(\RuntimeException::class);
188  $this->expectExceptionCode(1489751363);
189  (new ‪FormInlineAjaxController(new ‪FormDataCompiler(), new ‪HashService()))->synchronizeLocalizeAction($request);
190  }
191 
196  #[Test]
198  {
199  $backendUser = $this->createMock(BackendUserAuthentication::class);
200 
201  $mockObject = $this->getAccessibleMock(
202  FormInlineAjaxController::class,
203  ['getBackendUserAuthentication'],
204  [],
205  '',
206  false
207  );
208  $mockObject->method('getBackendUserAuthentication')->willReturn($backendUser);
209  $result = $mockObject->_call('getInlineExpandCollapseStateArray');
210 
211  self::assertEmpty($result);
212  }
213 
218  #[Test]
220  {
221  $backendUser = $this->createMock(BackendUserAuthentication::class);
222  $backendUser->uc = ['inlineView' => json_encode(['foo' => 'bar'])];
223 
224  $mockObject = $this->getAccessibleMock(
225  FormInlineAjaxController::class,
226  ['getBackendUserAuthentication'],
227  [],
228  '',
229  false
230  );
231  $mockObject->method('getBackendUserAuthentication')->willReturn($backendUser);
232  $result = $mockObject->_call('getInlineExpandCollapseStateArray');
233 
234  self::assertNotEmpty($result);
235  }
236 }
‪TYPO3\CMS\Backend\Controller\FormInlineAjaxController
Definition: FormInlineAjaxController.php:43
‪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:89
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionDoesNotValidate
‪synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionDoesNotValidate()
Definition: FormInlineAjaxControllerTest.php:171
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\getInlineExpandCollapseStateArraySwitchesToFallbackIfTheBackendUserDoesNotHaveAnUCInlineViewProperty
‪getInlineExpandCollapseStateArraySwitchesToFallbackIfTheBackendUserDoesNotHaveAnUCInlineViewProperty()
Definition: FormInlineAjaxControllerTest.php:197
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\setUp
‪setUp()
Definition: FormInlineAjaxControllerTest.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest
Definition: FormInlineAjaxControllerTest.php:29
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Tests\Unit\Controller
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\getInlineExpandCollapseStateArrayWillUnserializeUCInlineViewPropertyAsAnArrayWithData
‪getInlineExpandCollapseStateArrayWillUnserializeUCInlineViewPropertyAsAnArrayWithData()
Definition: FormInlineAjaxControllerTest.php:219
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\createActionThrowsExceptionIfContextIsEmpty
‪createActionThrowsExceptionIfContextIsEmpty()
Definition: FormInlineAjaxControllerTest.php:37
‪$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:52
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\detailsActionThrowsExceptionIfContextConfigSectionIsEmpty
‪detailsActionThrowsExceptionIfContextConfigSectionIsEmpty()
Definition: FormInlineAjaxControllerTest.php:104
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\detailsActionThrowsExceptionIfContextConfigSectionDoesNotValidate
‪detailsActionThrowsExceptionIfContextConfigSectionDoesNotValidate()
Definition: FormInlineAjaxControllerTest.php:119
‪TYPO3\CMS\Backend\Form\FormDataCompiler
Definition: FormDataCompiler.php:26
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionIsEmpty
‪synchronizeLocalizeActionThrowsExceptionIfContextConfigSectionIsEmpty()
Definition: FormInlineAjaxControllerTest.php:156
‪TYPO3\CMS\Core\Crypto\HashService
Definition: HashService.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Controller\FormInlineAjaxControllerTest\synchronizeLocalizeActionThrowsExceptionIfContextIsEmpty
‪synchronizeLocalizeActionThrowsExceptionIfContextIsEmpty()
Definition: FormInlineAjaxControllerTest.php:141