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