TYPO3 CMS  TYPO3_8-7
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 
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/core/Tests/Functional/Fixtures/pages_language_overlay.xml');
51  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Fixtures/tx_irretutorial_1ncsv_hotel.xml');
52 
53  $this->setUpBackendUserFromFixture(1);
54  Bootstrap::getInstance()->initializeLanguageObject();
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  $this->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  $this->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  $this->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  $this->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  $context = [
163  'config' => [
164  'type' => 'inline',
165  'foreign_table' => 'tx_irretutorial_1ncsv_offer',
166  'maxitems' => 10,
167  'appearance' => [
168  'showSynchronizationLink' => 1,
169  'showAllLocalizationLink' => 1,
170  'showPossibleLocalizationRecords' => true,
171  'showRemovedLocalizationRecords' => true,
172  'levelLinksPosition' => 'top',
173  'enabledControls' => [
174  'info' => true,
175  'new' => true,
176  'dragdrop' => true,
177  'sort' => true,
178  'hide' => true,
179  'delete' => true,
180  'localize' => true,
181  ],
182  ],
183  'behaviour' => [
184  'localizationMode' => 'none',
185  'localizeChildrenAtParentLocalization' => true,
186  ],
187  'default' => '',
188  'minitems' => 0,
189  'inline' => [
190  'parentSysLanguageUid' => $sysLanguageUid,
191  'first' => false,
192  'last' => false,
193  ],
194  ],
195  ];
196 
197  return array_merge(
198  $context,
199  [
200  'hmac' => GeneralUtility::hmac(json_encode($context['config']), 'InlineContext'),
201  ]
202  );
203  }
204 }
static hmac($input, $additionalSecret='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']