TYPO3 CMS  TYPO3_7-6
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 
28 {
32  protected $subject;
33 
37  protected $testExtensionsToLoad = [
38  'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/irre_tutorial',
39  ];
40 
41  protected function setUp()
42  {
43  parent::setUp();
44 
45  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/pages.xml');
46  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/pages_language_overlay.xml');
47  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/sys_language.xml');
48  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/backend/Tests/Functional/Fixtures/tx_irretutorial_1ncsv_hotel.xml');
49 
50  $this->setUpBackendUserFromFixture(1);
51  Bootstrap::getInstance()->initializeLanguageObject();
52 
53  $this->subject = new FormInlineAjaxController();
54  }
55 
60  {
61  $parsedBody = [
62  'ajax' => [
63  0 => 'data-1-tx_irretutorial_1ncsv_hotel-NEW59c1062549e56282348897-offers-tx_irretutorial_1ncsv_offer',
64  'context' => json_encode($this->getContext()),
65  ],
66  ];
67 
68  $request = new ServerRequest();
69  $request = $request->withParsedBody($parsedBody);
70  $response = new Response();
71 
72  $response = $this->subject->createAction($request, $response);
73  $body = (string)$response->getBody();
74  $jsonArray = json_decode($body, true);
75 
76  $this->assertNotEmpty($jsonArray['data']);
77  }
78 
83  {
84  $parsedBody = [
85  'ajax' => [
86  0 => 'data-1-tx_irretutorial_1ncsv_hotel-1-offers-tx_irretutorial_1ncsv_offer',
87  'context' => json_encode($this->getContext()),
88  ],
89  ];
90 
91  $request = new ServerRequest();
92  $request = $request->withParsedBody($parsedBody);
93 
94  $response = new Response();
95 
96  $response = $this->subject->createAction($request, $response);
97  $body = (string)$response->getBody();
98  $jsonArray = json_decode($body, true);
99 
100  $this->assertNotEmpty($jsonArray['data']);
101  }
102 
107  {
108  $parsedBody = [
109  'ajax' => [
110  0 => 'data-1-tx_irretutorial_1ncsv_hotel-2-offers-tx_irretutorial_1ncsv_offer',
111  'context' => json_encode($this->getContext()),
112  ],
113  ];
114 
115  $request = new ServerRequest();
116  $request = $request->withParsedBody($parsedBody);
117  $response = new Response();
118 
119  $response = $this->subject->createAction($request, $response);
120  $body = (string)$response->getBody();
121  $jsonArray = json_decode($body, true);
122 
123  $this->assertRegExp('/<option value="1"[^>]* selected="selected">Dansk<\/option>/', $jsonArray['data']);
124  }
125 
130  {
131  unset($GLOBALS['TCA']['tx_irretutorial_1ncsv_offer']['ctrl']['languageField']);
132  unset($GLOBALS['TCA']['tx_irretutorial_1ncsv_offer']['ctrl']['transOrigPointerField']);
133  unset($GLOBALS['TCA']['tx_irretutorial_1ncsv_offer']['ctrl']['transOrigDiffSourceField']);
134 
135  $parsedBody = [
136  'ajax' => [
137  0 => 'data-1-tx_irretutorial_1ncsv_hotel-2-offers-tx_irretutorial_1ncsv_offer',
138  'context' => json_encode($this->getContext())
139  ],
140  ];
141 
142  $request = new ServerRequest();
143  $request = $request->withParsedBody($parsedBody);
144  $response = new Response();
145 
146  $response = $this->subject->createAction($request, $response);
147  $body = (string)$response->getBody();
148  $jsonArray = json_decode($body, true);
149 
150  $this->assertNotRegExp('/<select[^>]* name="data\[tx_irretutorial_1ncsv_offer\]\[NEW[1-9]+\]\[sys_language_uid\]"[^>]*>/', $jsonArray['data']);
151  }
152 
156  protected function getContext()
157  {
158  $context = [
159  'config' => [
160  'type' => 'inline',
161  'foreign_table' => 'tx_irretutorial_1ncsv_offer',
162  'maxitems' => 10,
163  'appearance' => [
164  'showSynchronizationLink' => 1,
165  'showAllLocalizationLink' => 1,
166  'showPossibleLocalizationRecords' => true,
167  'showRemovedLocalizationRecords' => true,
168  'levelLinksPosition' => 'top',
169  'enabledControls' => [
170  'info' => true,
171  'new' => true,
172  'dragdrop' => true,
173  'sort' => true,
174  'hide' => true,
175  'delete' => true,
176  'localize' => true,
177  ],
178  ],
179  'behaviour' => [
180  'localizationMode' => 'select',
181  'localizeChildrenAtParentLocalization' => true,
182  ],
183  'default' => '',
184  'minitems' => 0,
185  'inline' => [
186  'first' => false,
187  'last' => false,
188  ],
189  ],
190  ];
191 
192  return array_merge(
193  $context,
194  [
195  'hmac' => GeneralUtility::hmac(serialize($context['config'])),
196  ]
197  );
198  }
199 }
static hmac($input, $additionalSecret='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']