‪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 
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
31 class ‪FormInlineAjaxControllerTest extends FunctionalTestCase
32 {
34 
36 
37  protected ‪$testExtensionsToLoad = [
38  'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_irre_csv',
39  ];
40 
44  protected const ‪LANGUAGE_PRESETS = [
45  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
46  'DK' => ['id' => 1, 'title' => 'Dansk', 'locale' => 'dk_DA.UTF8'],
47  ];
48 
52  protected function ‪setUp(): void
53  {
54  parent::setUp();
55 
56  $this->importDataSet('PACKAGE:typo3/testing-framework/Resources/Core/Functional/Fixtures/pages.xml');
57  $this->importCSVDataSet(__DIR__ . '/../Fixtures/tx_testirrecsv_hotel.csv');
58 
59  $this->setUpBackendUserFromFixture(1);
61 
63  'website-local',
64  $this->‪buildSiteConfiguration(1, 'http://localhost/'),
65  [
66  $this->‪buildDefaultLanguageConfiguration('EN', '/en/'),
67  $this->‪buildLanguageConfiguration('DK', '/dk/'),
68  ]
69  );
70 
71  $this->subject = new ‪FormInlineAjaxController();
72  }
73 
78  {
79  $parsedBody = [
80  'ajax' => [
81  0 => 'data-1-tx_testirrecsv_hotel-NEW59c1062549e56282348897-offers-tx_testirrecsv_offer',
82  'context' => json_encode($this->‪getContextForSysLanguageUid(0)),
83  ],
84  ];
85 
86  $request = new ‪ServerRequest();
87  $request = $request->withParsedBody($parsedBody);
88  $response = new ‪Response();
89 
90  $response = $this->subject->createAction($request);
91  $body = (string)$response->getBody();
92  $jsonArray = json_decode($body, true);
93 
94  self::assertNotEmpty($jsonArray['data']);
95  }
96 
101  {
102  $parsedBody = [
103  'ajax' => [
104  0 => 'data-1-tx_testirrecsv_hotel-NEW59c1062549e56282348897-offers-tx_testirrecsv_offer',
105  'context' => json_encode($this->‪getContextForSysLanguageUid(0)),
106  ],
107  ];
108 
109  $request = new ServerRequest();
110  $request = $request->withParsedBody($parsedBody);
111 
112  $response = new Response();
113 
114  $response = $this->subject->createAction($request);
115  $body = (string)$response->getBody();
116  $jsonArray = json_decode($body, true);
117 
118  self::assertNotEmpty($jsonArray['data']);
119  }
120 
125  {
126  $parsedBody = [
127  'ajax' => [
128  0 => 'data-1-tx_testirrecsv_hotel-NEW59c1062549e56282348897-offers-tx_testirrecsv_offer',
129  'context' => json_encode($this->‪getContextForSysLanguageUid(1)),
130  ],
131  ];
132 
133  $request = new ServerRequest();
134  $request = $request->withParsedBody($parsedBody);
135  $response = new Response();
136 
137  $response = $this->subject->createAction($request);
138  $body = (string)$response->getBody();
139  $jsonArray = json_decode($body, true);
140 
141  self::assertMatchesRegularExpression('/<option value="1"[^>]* selected="selected">Dansk<\/option>/', $jsonArray['data']);
142  }
143 
148  {
149  unset(‪$GLOBALS['TCA']['tx_testirrecsv_offer']['ctrl']['languageField']);
150  unset(‪$GLOBALS['TCA']['tx_testirrecsv_offer']['ctrl']['transOrigPointerField']);
151  unset(‪$GLOBALS['TCA']['tx_testirrecsv_offer']['ctrl']['transOrigDiffSourceField']);
152 
153  $parsedBody = [
154  'ajax' => [
155  0 => 'data-1-tx_testirrecsv_hotel-NEW59c1062549e56282348897-offers-tx_testirrecsv_offer',
156  'context' => json_encode($this->‪getContextForSysLanguageUid(1)),
157  ],
158  ];
159 
160  $request = new ServerRequest();
161  $request = $request->withParsedBody($parsedBody);
162  $response = new Response();
163 
164  $response = $this->subject->createAction($request);
165  $body = (string)$response->getBody();
166  $jsonArray = json_decode($body, true);
167 
168  self::assertDoesNotMatchRegularExpression('/<select[^>]* name="data\[tx_testirrecsv_offer\]\[NEW[1-9]+\]\[sys_language_uid\]"[^>]*>/', $jsonArray['data']);
169  }
170 
175  protected function ‪getContextForSysLanguageUid(int $sysLanguageUid): array
176  {
177  $config = [
178  'type' => 'inline',
179  'foreign_table' => 'tx_testirrecsv_offer',
180  'maxitems' => 10,
181  'appearance' => [
182  'showSynchronizationLink' => 1,
183  'showAllLocalizationLink' => 1,
184  'showPossibleLocalizationRecords' => true,
185  'levelLinksPosition' => 'top',
186  'enabledControls' => [
187  'info' => true,
188  'new' => true,
189  'dragdrop' => true,
190  'sort' => true,
191  'hide' => true,
192  'delete' => true,
193  'localize' => true,
194  ],
195  ],
196  'behaviour' => [
197  'localizationMode' => 'none',
198  'localizeChildrenAtParentLocalization' => true,
199  ],
200  'default' => '',
201  'inline' => [
202  'parentSysLanguageUid' => $sysLanguageUid,
203  'first' => false,
204  'last' => false,
205  ],
206  ];
207 
208  $configJson = json_encode($config);
209  return [
210  'config' => $configJson,
211  'hmac' => GeneralUtility::hmac($configJson, 'InlineContext'),
212  ];
213  }
214 }
‪TYPO3\CMS\Backend\Controller\FormInlineAjaxController
Definition: FormInlineAjaxController.php:40
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: FormInlineAjaxControllerTest.php:43
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:36
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildLanguageConfiguration
‪array buildLanguageConfiguration(string $identifier, string $base, array $fallbackIdentifiers=[], string $fallbackType=null)
Definition: SiteBasedTestTrait.php:144
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:58
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest\createActionWithExistingLocalizedParentAndNotLocalizableChildReturnsResponseWithChildData
‪createActionWithExistingLocalizedParentAndNotLocalizableChildReturnsResponseWithChildData()
Definition: FormInlineAjaxControllerTest.php:146
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest\createActionWithNewParentReturnsResponseForInlineChildData
‪createActionWithNewParentReturnsResponseForInlineChildData()
Definition: FormInlineAjaxControllerTest.php:76
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪array buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:126
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:598
‪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:51
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest\$testExtensionsToLoad
‪$testExtensionsToLoad
Definition: FormInlineAjaxControllerTest.php:36
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest\createActionWithExistingLocalizedParentReturnsResponseWithLocalizedChildData
‪createActionWithExistingLocalizedParentReturnsResponseWithLocalizedChildData()
Definition: FormInlineAjaxControllerTest.php:123
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest\$subject
‪FormInlineAjaxController $subject
Definition: FormInlineAjaxControllerTest.php:34
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:70
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪array buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:111
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest
Definition: FormInlineAjaxControllerTest.php:32
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪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:174
‪TYPO3\CMS\Backend\Tests\Functional\Controller\FormInlineAjaxControllerTest\createActionWithExistingParentReturnsResponseForInlineChildData
‪createActionWithExistingParentReturnsResponseForInlineChildData()
Definition: FormInlineAjaxControllerTest.php:99