373ebb2416f9719ed06053ff380b37e763959ec0
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / DataHandling / InlineRelationalRecordEditing / ForeignField / AbstractActionTestCase.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\DataHandling\InlineRelationalRecordEditing\ForeignField;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2014 Oliver Hader <oliver.hader@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 require_once dirname(dirname(dirname(__FILE__))) . '/AbstractDataHandlerActionTestCase.php';
28
29 /**
30 * Functional test for the DataHandler
31 */
32 abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase {
33
34 const VALUE_PageId = 89;
35 const VALUE_PageIdTarget = 90;
36 const VALUE_PageIdWebsite = 1;
37 const VALUE_ContentIdFirst = 297;
38 const VALUE_ContentIdLast = 298;
39 const VALUE_LanguageId = 1;
40
41 const TABLE_Page = 'pages';
42 const TABLE_Content = 'tt_content';
43 const TABLE_Hotel = 'tx_irretutorial_1nff_hotel';
44 const TABLE_Offer = 'tx_irretutorial_1nff_offer';
45
46 /**
47 * @var string
48 */
49 protected $dataSetDirectory = 'typo3/sysext/core/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/DataSet/';
50
51 public function setUp() {
52 parent::setUp();
53 $this->importScenarioDataSet('LiveDefaultPages');
54 $this->importScenarioDataSet('LiveDefaultElements');
55
56 $this->setUpFrontendRootPage(1, array('typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.ts'));
57 }
58
59 /**
60 * Parent content records
61 */
62
63 /**
64 * @test
65 */
66 public function createParentContentRecord() {
67 $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, array('header' => 'Testing #1'));
68 $this->assertAssertionDataSet('createParentContentRecord');
69
70 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
71 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Testing #1');
72 }
73
74 /**
75 * @test
76 */
77 public function modifyParentContentRecord() {
78 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdLast, array('header' => 'Testing #1'));
79 $this->assertAssertionDataSet('modifyParentContentRecord');
80
81 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
82 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Testing #1');
83 $this->assertResponseContentStructureHasRecords(
84 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, 'tx_irretutorial_hotels',
85 self::TABLE_Hotel, 'title', array('Hotel #1')
86 );
87 }
88
89 /**
90 * @test
91 */
92 public function deleteParentContentRecord() {
93 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdLast);
94 $this->assertAssertionDataSet('deleteParentContentRecord');
95
96 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
97 $this->assertResponseContentDoesNotHaveRecords($responseContent, self::TABLE_Content, 'header', 'Regular Element #2');
98 }
99
100 /**
101 * @test
102 */
103 public function copyParentContentRecord() {
104 $newTableIds = $this->actionService->copyRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageId);
105 $this->assertAssertionDataSet('copyParentContentRecord');
106
107 $newContentId = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
108 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
109 $this->assertResponseContentStructureHasRecords(
110 $responseContent, self::TABLE_Content . ':' . $newContentId, 'tx_irretutorial_hotels',
111 self::TABLE_Hotel, 'title', array('Hotel #1')
112 );
113 }
114
115 /**
116 * @test
117 */
118 public function localizeParentContentRecord() {
119 $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_LanguageId);
120 $this->assertAssertionDataSet('localizeParentContentRecord');
121
122 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, self::VALUE_LanguageId)->getResponseContent();
123 $this->assertResponseContentStructureHasRecords(
124 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, 'tx_irretutorial_hotels',
125 self::TABLE_Hotel, 'title', array('[Translate to Dansk:] Hotel #1')
126 );
127 }
128
129 /**
130 * @test
131 */
132 public function changeParentContentRecordSorting() {
133 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdLast);
134 $this->assertAssertionDataSet('changeParentContentRecordSorting');
135
136 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
137 $this->assertResponseContentStructureHasRecords(
138 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, 'tx_irretutorial_hotels',
139 self::TABLE_Hotel, 'title', array('Hotel #1', 'Hotel #2')
140 );
141 $this->assertResponseContentStructureHasRecords(
142 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, 'tx_irretutorial_hotels',
143 self::TABLE_Hotel, 'title', array('Hotel #1')
144 );
145 }
146
147 /**
148 * @test
149 */
150 public function moveParentContentRecordToDifferentPage() {
151 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageIdTarget);
152 $this->assertAssertionDataSet('moveParentContentRecordToDifferentPage');
153
154 $responseContent = $this->getFrontendResponse(self::VALUE_PageIdTarget)->getResponseContent();
155 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Regular Element #2');
156 $this->assertResponseContentStructureHasRecords(
157 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, 'tx_irretutorial_hotels',
158 self::TABLE_Hotel, 'title', array('Hotel #1')
159 );
160 }
161
162 /**
163 * @test
164 */
165 public function moveParentContentRecordToDifferentPageAndChangeSorting() {
166 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageIdTarget);
167 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdLast);
168 $this->assertAssertionDataSet('moveParentContentRecordToDifferentPageAndChangeSorting');
169
170 $responseContent = $this->getFrontendResponse(self::VALUE_PageIdTarget)->getResponseContent();
171 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', array('Regular Element #2', 'Regular Element #1'));
172 $this->assertResponseContentStructureHasRecords(
173 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, 'tx_irretutorial_hotels',
174 self::TABLE_Hotel, 'title', array('Hotel #1', 'Hotel #2')
175 );
176 $this->assertResponseContentStructureHasRecords(
177 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, 'tx_irretutorial_hotels',
178 self::TABLE_Hotel, 'title', array('Hotel #1')
179 );
180 }
181
182 /**
183 * Page records
184 */
185
186 /**
187 * @test
188 */
189 public function modifyPageRecord() {
190 $this->actionService->modifyRecord(self::TABLE_Page, self::VALUE_PageId, array('title' => 'Testing #1'));
191 $this->assertAssertionDataSet('modifyPageRecord');
192
193 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
194 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Page, 'title', 'Testing #1');
195 }
196
197 /**
198 * @test
199 */
200 public function deletePageRecord() {
201 $this->actionService->deleteRecord(self::TABLE_Page, self::VALUE_PageId);
202 $this->assertAssertionDataSet('deletePageRecord');
203
204 $response = $this->getFrontendResponse(self::VALUE_PageId, 0, 0, 0, FALSE);
205 $this->assertContains('PageNotFoundException', $response->getError());
206 }
207
208 /**
209 * @test
210 */
211 public function copyPageRecord() {
212 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
213 $this->assertAssertionDataSet('copyPageRecord');
214
215 $newPageId = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
216 $responseContent = $this->getFrontendResponse($newPageId)->getResponseContent();
217 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Hotel, 'title', array('Hotel #1', 'Hotel #2', 'Hotel #1'));
218 }
219
220 /**
221 * IRRE Child Records
222 */
223
224 /**
225 * @test
226 */
227 public function createParentContentRecordWithHotelAndOfferChildRecords() {
228 $newTableIds = $this->actionService->createNewRecords(
229 self::VALUE_PageId,
230 array(
231 self::TABLE_Offer => array('title' => 'Offer #1'),
232 self::TABLE_Hotel => array('title' => 'Hotel #1', 'offers' => '__previousUid'),
233 self::TABLE_Content => array('header' => 'Testing #1', 'tx_irretutorial_hotels' => '__previousUid'),
234 )
235 );
236 $this->assertAssertionDataSet('createParentContentRecordWithHotelAndOfferChildRecords');
237
238 $newContentId = $newTableIds[self::TABLE_Content][0];
239 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
240 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Testing #1');
241 $this->assertResponseContentStructureHasRecords(
242 $responseContent, self::TABLE_Content . ':' . $newContentId, 'tx_irretutorial_hotels',
243 self::TABLE_Hotel, 'title', 'Hotel #1'
244 );
245 }
246
247 /**
248 * @test
249 */
250 public function createAndCopyParentContentRecordWithHotelAndOfferChildRecords() {
251 $newTableIds = $this->actionService->createNewRecords(
252 self::VALUE_PageId,
253 array(
254 self::TABLE_Offer => array('title' => 'Offer #1'),
255 self::TABLE_Hotel => array('title' => 'Hotel #1', 'offers' => '__previousUid'),
256 self::TABLE_Content => array('header' => 'Testing #1', 'tx_irretutorial_hotels' => '__previousUid'),
257 )
258 );
259 $newContentId = $newTableIds[self::TABLE_Content][0];
260 $newHotelId = $newTableIds[self::TABLE_Hotel][0];
261 $copiedTableIds = $this->actionService->copyRecord(self::TABLE_Content, $newContentId, self::VALUE_PageId);
262 $this->assertAssertionDataSet('createAndCopyParentContentRecordWithHotelAndOfferChildRecords');
263
264 $copiedContentId = $copiedTableIds[self::TABLE_Content][$newContentId];
265 $copiedHotelId = $copiedTableIds[self::TABLE_Hotel][$newHotelId];
266 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
267 $this->assertResponseContentStructureHasRecords(
268 $responseContent, self::TABLE_Content . ':' . $newContentId, 'tx_irretutorial_hotels',
269 self::TABLE_Hotel, 'title', 'Hotel #1'
270 );
271 $this->assertResponseContentStructureHasRecords(
272 $responseContent, self::TABLE_Content . ':' . $copiedContentId, 'tx_irretutorial_hotels',
273 self::TABLE_Hotel, 'title', 'Hotel #1'
274 );
275 $this->assertResponseContentStructureHasRecords(
276 $responseContent, self::TABLE_Hotel . ':' . $copiedHotelId, 'offers',
277 self::TABLE_Offer, 'title', 'Offer #1'
278 );
279 }
280
281 /**
282 * @test
283 */
284 public function createAndLocalizeParentContentRecordWithHotelAndOfferChildRecords() {
285 // @todo Localizing the new child records is broken in the Core
286 $newTableIds = $this->actionService->createNewRecords(
287 self::VALUE_PageId,
288 array(
289 self::TABLE_Offer => array('title' => 'Offer #1'),
290 self::TABLE_Hotel => array('title' => 'Hotel #1', 'offers' => '__previousUid'),
291 self::TABLE_Content => array('header' => 'Testing #1', 'tx_irretutorial_hotels' => '__previousUid'),
292 )
293 );
294 $newContentId = $newTableIds[self::TABLE_Content][0];
295 $newHotelId = $newTableIds[self::TABLE_Hotel][0];
296 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Content, $newContentId, self::VALUE_LanguageId);
297 $this->assertAssertionDataSet('createAndLocalizeParentContentRecordWithHotelAndOfferChildRecords');
298
299 $localizedContentId = $localizedTableIds[self::TABLE_Content][$newContentId];
300 $localizedHotelId = $localizedTableIds[self::TABLE_Hotel][$newHotelId];
301 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, self::VALUE_LanguageId)->getResponseContent();
302
303 // @todo Does not work since children don't point to live-default record
304 /*
305 $this->assertResponseContentStructureHasRecords(
306 $responseContent, self::TABLE_Content . ':' . $localizedContentId, 'tx_irretutorial_hotels',
307 self::TABLE_Hotel, 'title', '[Translate to Dansk:] Hotel #1'
308 );
309 $this->assertResponseContentStructureHasRecords(
310 $responseContent, self::TABLE_Hotel . ':' . $localizedHotelId, 'offers',
311 self::TABLE_Offer, 'title', '[Translate to Dansk:] Offer #1'
312 );
313 */
314 }
315
316 /**
317 * @test
318 */
319 public function modifyOnlyHotelChildRecord() {
320 $this->actionService->modifyRecord(self::TABLE_Hotel, 4, array('title' => 'Testing #1'));
321 $this->assertAssertionDataSet('modifyOnlyHotelChildRecord');
322
323 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
324 $this->assertResponseContentStructureHasRecords(
325 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, 'tx_irretutorial_hotels',
326 self::TABLE_Hotel, 'title', array('Hotel #1', 'Testing #1')
327 );
328 }
329
330 /**
331 * @test
332 */
333 public function modifyParentRecordAndChangeHotelChildRecordsSorting() {
334 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, array('tx_irretutorial_hotels' => '4,3'));
335 $this->assertAssertionDataSet('modifyParentRecordAndChangeHotelChildRecordsSorting');
336
337 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
338 $this->assertResponseContentStructureHasRecords(
339 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, 'tx_irretutorial_hotels',
340 self::TABLE_Hotel, 'title', array('Hotel #2', 'Hotel #1')
341 );
342 }
343
344 /**
345 * @test
346 */
347 public function modifyParentRecordWithHotelChildRecord() {
348 $this->actionService->modifyRecords(
349 self::VALUE_PageId,
350 array(
351 self::TABLE_Hotel => array('uid' => 4, 'title' => 'Testing #1'),
352 self::TABLE_Content => array('uid' => self::VALUE_ContentIdFirst, 'tx_irretutorial_hotels' => '3,4'),
353 )
354 );
355 $this->assertAssertionDataSet('modifyParentRecordWithHotelChildRecord');
356
357 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
358 $this->assertResponseContentStructureHasRecords(
359 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, 'tx_irretutorial_hotels',
360 self::TABLE_Hotel, 'title', array('Hotel #1', 'Testing #1')
361 );
362 }
363
364 /**
365 * @test
366 */
367 public function modifyParentRecordAndAddHotelChildRecord() {
368 $this->actionService->modifyRecords(
369 self::VALUE_PageId,
370 array(
371 self::TABLE_Hotel => array('uid' => '__NEW', 'title' => 'Hotel #2'),
372 self::TABLE_Content => array('uid' => self::VALUE_ContentIdLast, 'tx_irretutorial_hotels' => '5,__previousUid'),
373 )
374 );
375 $this->assertAssertionDataSet('modifyParentRecordAndAddHotelChildRecord');
376
377 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
378 $this->assertResponseContentStructureHasRecords(
379 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, 'tx_irretutorial_hotels',
380 self::TABLE_Hotel, 'title', array('Hotel #1', 'Hotel #2')
381 );
382 }
383
384 /**
385 * @test
386 */
387 public function modifyParentRecordAndDeleteHotelChildRecord() {
388 $this->actionService->modifyRecord(
389 self::TABLE_Content,
390 self::VALUE_ContentIdFirst,
391 array('tx_irretutorial_hotels' => '3'),
392 array(self::TABLE_Hotel => array(4))
393 );
394 $this->assertAssertionDataSet('modifyParentRecordAndDeleteHotelChildRecord');
395
396 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
397 $this->assertResponseContentStructureHasRecords(
398 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, 'tx_irretutorial_hotels',
399 self::TABLE_Hotel, 'title', 'Hotel #1'
400 );
401 $this->assertResponseContentStructureDoesNotHaveRecords(
402 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, 'tx_irretutorial_hotels',
403 self::TABLE_Hotel, 'title', 'Hotel #2'
404 );
405 }
406
407 }