‪TYPO3CMS  10.4
FormInlineAjaxControllerTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
23 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24 
28 class ‪FormInlineAjaxControllerTest extends FunctionalTestCase
29 {
33  protected ‪$subject;
34 
38  protected ‪$testExtensionsToLoad = [
39  'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/irre_tutorial',
40  ];
41 
45  protected function ‪setUp(): void
46  {
47  parent::setUp();
48 
49  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
50  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/sys_language.xml');
51  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Fixtures/tx_irretutorial_1ncsv_hotel.xml');
52 
53  $this->setUpBackendUserFromFixture(1);
55 
56  $this->subject = new ‪FormInlineAjaxController();
57  }
58 
63  {
64  $parsedBody = [
65  'ajax' => [
66  0 => 'data-1-tx_irretutorial_1ncsv_hotel-NEW59c1062549e56282348897-offers-tx_irretutorial_1ncsv_offer',
67  'context' => json_encode($this->‪getContextForSysLanguageUid(0)),
68  ],
69  ];
70 
71  $request = new ‪ServerRequest();
72  $request = $request->withParsedBody($parsedBody);
73  $response = new ‪Response();
74 
75  $response = $this->subject->createAction($request, $response);
76  $body = (string)$response->getBody();
77  $jsonArray = json_decode($body, true);
78 
79  self::assertNotEmpty($jsonArray['data']);
80  }
81 
86  {
87  $parsedBody = [
88  'ajax' => [
89  0 => 'data-1-tx_irretutorial_1ncsv_hotel-NEW59c1062549e56282348897-offers-tx_irretutorial_1ncsv_offer',
90  'context' => json_encode($this->‪getContextForSysLanguageUid(0)),
91  ],
92  ];
93 
94  $request = new ‪ServerRequest();
95  $request = $request->withParsedBody($parsedBody);
96 
97  $response = new ‪Response();
98 
99  $response = $this->subject->createAction($request, $response);
100  $body = (string)$response->getBody();
101  $jsonArray = json_decode($body, true);
102 
103  self::assertNotEmpty($jsonArray['data']);
104  }
105 
110  {
111  $parsedBody = [
112  'ajax' => [
113  0 => 'data-1-tx_irretutorial_1ncsv_hotel-NEW59c1062549e56282348897-offers-tx_irretutorial_1ncsv_offer',
114  'context' => json_encode($this->‪getContextForSysLanguageUid(1)),
115  ],
116  ];
117 
118  $request = new ‪ServerRequest();
119  $request = $request->withParsedBody($parsedBody);
120  $response = new ‪Response();
121 
122  $response = $this->subject->createAction($request, $response);
123  $body = (string)$response->getBody();
124  $jsonArray = json_decode($body, true);
125 
126  self::assertRegExp('/<option value="1"[^>]* selected="selected">Dansk<\/option>/', $jsonArray['data']);
127  }
128 
133  {
134  unset(‪$GLOBALS['TCA']['tx_irretutorial_1ncsv_offer']['ctrl']['languageField']);
135  unset(‪$GLOBALS['TCA']['tx_irretutorial_1ncsv_offer']['ctrl']['transOrigPointerField']);
136  unset(‪$GLOBALS['TCA']['tx_irretutorial_1ncsv_offer']['ctrl']['transOrigDiffSourceField']);
137 
138  $parsedBody = [
139  'ajax' => [
140  0 => 'data-1-tx_irretutorial_1ncsv_hotel-NEW59c1062549e56282348897-offers-tx_irretutorial_1ncsv_offer',
141  'context' => json_encode($this->‪getContextForSysLanguageUid(1)),
142  ],
143  ];
144 
145  $request = new ‪ServerRequest();
146  $request = $request->withParsedBody($parsedBody);
147  $response = new ‪Response();
148 
149  $response = $this->subject->createAction($request, $response);
150  $body = (string)$response->getBody();
151  $jsonArray = json_decode($body, true);
152 
153  self::assertNotRegExp('/<select[^>]* name="data\[tx_irretutorial_1ncsv_offer\]\[NEW[1-9]+\]\[sys_language_uid\]"[^>]*>/', $jsonArray['data']);
154  }
155 
160  protected function ‪getContextForSysLanguageUid(int $sysLanguageUid): array
161  {
162  $config = [
163  'type' => 'inline',
164  'foreign_table' => 'tx_irretutorial_1ncsv_offer',
165  'maxitems' => 10,
166  'appearance' => [
167  'showSynchronizationLink' => 1,
168  'showAllLocalizationLink' => 1,
169  'showPossibleLocalizationRecords' => true,
170  'showRemovedLocalizationRecords' => true,
171  'levelLinksPosition' => 'top',
172  'enabledControls' => [
173  'info' => true,
174  'new' => true,
175  'dragdrop' => true,
176  'sort' => true,
177  'hide' => true,
178  'delete' => true,
179  'localize' => true,
180  ],
181  ],
182  'behaviour' => [
183  'localizationMode' => 'none',
184  'localizeChildrenAtParentLocalization' => true,
185  ],
186  'default' => '',
187  'minitems' => 0,
188  'inline' => [
189  'parentSysLanguageUid' => $sysLanguageUid,
190  'first' => false,
191  'last' => false,
192  ],
193  ];
194 
195  $configJson = json_encode($config);
196  return [
197  'config' => $configJson,
198  'hmac' => GeneralUtility::hmac($configJson, 'InlineContext'),
199  ];
200  }
201 }
‪TYPO3\CMS\Backend\Controller\FormInlineAjaxController
Definition: FormInlineAjaxController.php:39
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest\createActionWithExistingLocalizedParentAndNotLocalizableChildReturnsResponseWithChildData
‪createActionWithExistingLocalizedParentAndNotLocalizableChildReturnsResponseWithChildData()
Definition: FormInlineAjaxControllerTest.php:130
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest\createActionWithNewParentReturnsResponseForInlineChildData
‪createActionWithNewParentReturnsResponseForInlineChildData()
Definition: FormInlineAjaxControllerTest.php:60
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: FormInlineAjaxControllerTest.php:36
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:617
‪TYPO3\CMS\Core\Http\Response
Definition: Response.php:30
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest\setUp
‪setUp()
Definition: FormInlineAjaxControllerTest.php:43
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest\createActionWithExistingLocalizedParentReturnsResponseWithLocalizedChildData
‪createActionWithExistingLocalizedParentReturnsResponseWithLocalizedChildData()
Definition: FormInlineAjaxControllerTest.php:107
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest\$subject
‪FormInlineAjaxController $subject
Definition: FormInlineAjaxControllerTest.php:32
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:66
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest
Definition: FormInlineAjaxControllerTest.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Tests\Functional\Controller
Definition: EditDocumentControllerTest.php:18
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest\getContextForSysLanguageUid
‪array getContextForSysLanguageUid(int $sysLanguageUid)
Definition: FormInlineAjaxControllerTest.php:158
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest\createActionWithExistingParentReturnsResponseForInlineChildData
‪createActionWithExistingParentReturnsResponseForInlineChildData()
Definition: FormInlineAjaxControllerTest.php:83