[TASK] Rename tt_content.tx_irretutorial_hotels in tests
[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 const FIELD_ContentHotel = 'tx_irretutorial_1nff_hotels';
47 const FIELD_HotelOffer = 'offers';
48
49 /**
50 * @var string
51 */
52 protected $dataSetDirectory = 'typo3/sysext/core/Tests/Functional/DataHandling/InlineRelationalRecordEditing/ForeignField/DataSet/';
53
54 public function setUp() {
55 parent::setUp();
56 $this->importScenarioDataSet('LiveDefaultPages');
57 $this->importScenarioDataSet('LiveDefaultElements');
58
59 $this->setUpFrontendRootPage(1, array('typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.ts'));
60 }
61
62 /**
63 * Parent content records
64 */
65
66 /**
67 * @test
68 */
69 public function createParentContentRecord() {
70 $this->actionService->createNewRecord(self::TABLE_Content, self::VALUE_PageId, array('header' => 'Testing #1'));
71 $this->assertAssertionDataSet('createParentContentRecord');
72
73 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
74 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Testing #1');
75 }
76
77 /**
78 * @test
79 */
80 public function modifyParentContentRecord() {
81 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdLast, array('header' => 'Testing #1'));
82 $this->assertAssertionDataSet('modifyParentContentRecord');
83
84 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
85 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Testing #1');
86 $this->assertResponseContentStructureHasRecords(
87 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, self::FIELD_ContentHotel,
88 self::TABLE_Hotel, 'title', array('Hotel #1')
89 );
90 }
91
92 /**
93 * @test
94 */
95 public function deleteParentContentRecord() {
96 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdLast);
97 $this->assertAssertionDataSet('deleteParentContentRecord');
98
99 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
100 $this->assertResponseContentDoesNotHaveRecords($responseContent, self::TABLE_Content, 'header', 'Regular Element #2');
101 }
102
103 /**
104 * @test
105 */
106 public function copyParentContentRecord() {
107 $newTableIds = $this->actionService->copyRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageId);
108 $this->assertAssertionDataSet('copyParentContentRecord');
109
110 $newContentId = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
111 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
112 $this->assertResponseContentStructureHasRecords(
113 $responseContent, self::TABLE_Content . ':' . $newContentId, self::FIELD_ContentHotel,
114 self::TABLE_Hotel, 'title', array('Hotel #1')
115 );
116 }
117
118 /**
119 * @test
120 */
121 public function localizeParentContentRecord() {
122 $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_LanguageId);
123 $this->assertAssertionDataSet('localizeParentContentRecord');
124
125 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, self::VALUE_LanguageId)->getResponseContent();
126 $this->assertResponseContentStructureHasRecords(
127 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, self::FIELD_ContentHotel,
128 self::TABLE_Hotel, 'title', array('[Translate to Dansk:] Hotel #1')
129 );
130 }
131
132 /**
133 * @test
134 */
135 public function changeParentContentRecordSorting() {
136 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdLast);
137 $this->assertAssertionDataSet('changeParentContentRecordSorting');
138
139 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
140 $this->assertResponseContentStructureHasRecords(
141 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, self::FIELD_ContentHotel,
142 self::TABLE_Hotel, 'title', array('Hotel #1', 'Hotel #2')
143 );
144 $this->assertResponseContentStructureHasRecords(
145 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, self::FIELD_ContentHotel,
146 self::TABLE_Hotel, 'title', array('Hotel #1')
147 );
148 }
149
150 /**
151 * @test
152 */
153 public function moveParentContentRecordToDifferentPage() {
154 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageIdTarget);
155 $this->assertAssertionDataSet('moveParentContentRecordToDifferentPage');
156
157 $responseContent = $this->getFrontendResponse(self::VALUE_PageIdTarget)->getResponseContent();
158 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Regular Element #2');
159 $this->assertResponseContentStructureHasRecords(
160 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, self::FIELD_ContentHotel,
161 self::TABLE_Hotel, 'title', array('Hotel #1')
162 );
163 }
164
165 /**
166 * @test
167 */
168 public function moveParentContentRecordToDifferentPageAndChangeSorting() {
169 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageIdTarget);
170 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, -self::VALUE_ContentIdLast);
171 $this->assertAssertionDataSet('moveParentContentRecordToDifferentPageAndChangeSorting');
172
173 $responseContent = $this->getFrontendResponse(self::VALUE_PageIdTarget)->getResponseContent();
174 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', array('Regular Element #2', 'Regular Element #1'));
175 $this->assertResponseContentStructureHasRecords(
176 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, self::FIELD_ContentHotel,
177 self::TABLE_Hotel, 'title', array('Hotel #1', 'Hotel #2')
178 );
179 $this->assertResponseContentStructureHasRecords(
180 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, self::FIELD_ContentHotel,
181 self::TABLE_Hotel, 'title', array('Hotel #1')
182 );
183 }
184
185 /**
186 * Page records
187 */
188
189 /**
190 * @test
191 */
192 public function modifyPageRecord() {
193 $this->actionService->modifyRecord(self::TABLE_Page, self::VALUE_PageId, array('title' => 'Testing #1'));
194 $this->assertAssertionDataSet('modifyPageRecord');
195
196 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
197 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Page, 'title', 'Testing #1');
198 }
199
200 /**
201 * @test
202 */
203 public function deletePageRecord() {
204 $this->actionService->deleteRecord(self::TABLE_Page, self::VALUE_PageId);
205 $this->assertAssertionDataSet('deletePageRecord');
206
207 $response = $this->getFrontendResponse(self::VALUE_PageId, 0, 0, 0, FALSE);
208 $this->assertContains('PageNotFoundException', $response->getError());
209 }
210
211 /**
212 * @test
213 */
214 public function copyPageRecord() {
215 $newTableIds = $this->actionService->copyRecord(self::TABLE_Page, self::VALUE_PageId, self::VALUE_PageIdTarget);
216 $this->assertAssertionDataSet('copyPageRecord');
217
218 $newPageId = $newTableIds[self::TABLE_Page][self::VALUE_PageId];
219 $responseContent = $this->getFrontendResponse($newPageId)->getResponseContent();
220 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Hotel, 'title', array('Hotel #1', 'Hotel #2', 'Hotel #1'));
221 }
222
223 /**
224 * IRRE Child Records
225 */
226
227 /**
228 * @test
229 */
230 public function createParentContentRecordWithHotelAndOfferChildRecords() {
231 $newTableIds = $this->actionService->createNewRecords(
232 self::VALUE_PageId,
233 array(
234 self::TABLE_Offer => array('title' => 'Offer #1'),
235 self::TABLE_Hotel => array('title' => 'Hotel #1', self::FIELD_HotelOffer => '__previousUid'),
236 self::TABLE_Content => array('header' => 'Testing #1', self::FIELD_ContentHotel => '__previousUid'),
237 )
238 );
239 $this->assertAssertionDataSet('createParentContentRecordWithHotelAndOfferChildRecords');
240
241 $newContentId = $newTableIds[self::TABLE_Content][0];
242 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
243 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Testing #1');
244 $this->assertResponseContentStructureHasRecords(
245 $responseContent, self::TABLE_Content . ':' . $newContentId, self::FIELD_ContentHotel,
246 self::TABLE_Hotel, 'title', 'Hotel #1'
247 );
248 }
249
250 /**
251 * @test
252 */
253 public function createAndCopyParentContentRecordWithHotelAndOfferChildRecords() {
254 $newTableIds = $this->actionService->createNewRecords(
255 self::VALUE_PageId,
256 array(
257 self::TABLE_Offer => array('title' => 'Offer #1'),
258 self::TABLE_Hotel => array('title' => 'Hotel #1', self::FIELD_HotelOffer => '__previousUid'),
259 self::TABLE_Content => array('header' => 'Testing #1', self::FIELD_ContentHotel => '__previousUid'),
260 )
261 );
262 $newContentId = $newTableIds[self::TABLE_Content][0];
263 $newHotelId = $newTableIds[self::TABLE_Hotel][0];
264 $copiedTableIds = $this->actionService->copyRecord(self::TABLE_Content, $newContentId, self::VALUE_PageId);
265 $this->assertAssertionDataSet('createAndCopyParentContentRecordWithHotelAndOfferChildRecords');
266
267 $copiedContentId = $copiedTableIds[self::TABLE_Content][$newContentId];
268 $copiedHotelId = $copiedTableIds[self::TABLE_Hotel][$newHotelId];
269 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
270 $this->assertResponseContentStructureHasRecords(
271 $responseContent, self::TABLE_Content . ':' . $newContentId, self::FIELD_ContentHotel,
272 self::TABLE_Hotel, 'title', 'Hotel #1'
273 );
274 $this->assertResponseContentStructureHasRecords(
275 $responseContent, self::TABLE_Content . ':' . $copiedContentId, self::FIELD_ContentHotel,
276 self::TABLE_Hotel, 'title', 'Hotel #1'
277 );
278 $this->assertResponseContentStructureHasRecords(
279 $responseContent, self::TABLE_Hotel . ':' . $copiedHotelId, self::FIELD_HotelOffer,
280 self::TABLE_Offer, 'title', 'Offer #1'
281 );
282 }
283
284 /**
285 * @test
286 */
287 public function createAndLocalizeParentContentRecordWithHotelAndOfferChildRecords() {
288 // @todo Localizing the new child records is broken in the Core
289 $newTableIds = $this->actionService->createNewRecords(
290 self::VALUE_PageId,
291 array(
292 self::TABLE_Offer => array('title' => 'Offer #1'),
293 self::TABLE_Hotel => array('title' => 'Hotel #1', self::FIELD_HotelOffer => '__previousUid'),
294 self::TABLE_Content => array('header' => 'Testing #1', self::FIELD_ContentHotel => '__previousUid'),
295 )
296 );
297 $newContentId = $newTableIds[self::TABLE_Content][0];
298 $newHotelId = $newTableIds[self::TABLE_Hotel][0];
299 $localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Content, $newContentId, self::VALUE_LanguageId);
300 $this->assertAssertionDataSet('createAndLocalizeParentContentRecordWithHotelAndOfferChildRecords');
301
302 $localizedContentId = $localizedTableIds[self::TABLE_Content][$newContentId];
303 $localizedHotelId = $localizedTableIds[self::TABLE_Hotel][$newHotelId];
304 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, self::VALUE_LanguageId)->getResponseContent();
305
306 // @todo Does not work since children don't point to live-default record
307 /*
308 $this->assertResponseContentStructureHasRecords(
309 $responseContent, self::TABLE_Content . ':' . $localizedContentId, self::FIELD_ContentHotel,
310 self::TABLE_Hotel, 'title', '[Translate to Dansk:] Hotel #1'
311 );
312 $this->assertResponseContentStructureHasRecords(
313 $responseContent, self::TABLE_Hotel . ':' . $localizedHotelId, self::FIELD_HotelOffer,
314 self::TABLE_Offer, 'title', '[Translate to Dansk:] Offer #1'
315 );
316 */
317 }
318
319 /**
320 * @test
321 */
322 public function modifyOnlyHotelChildRecord() {
323 $this->actionService->modifyRecord(self::TABLE_Hotel, 4, array('title' => 'Testing #1'));
324 $this->assertAssertionDataSet('modifyOnlyHotelChildRecord');
325
326 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
327 $this->assertResponseContentStructureHasRecords(
328 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, self::FIELD_ContentHotel,
329 self::TABLE_Hotel, 'title', array('Hotel #1', 'Testing #1')
330 );
331 }
332
333 /**
334 * @test
335 */
336 public function modifyParentRecordAndChangeHotelChildRecordsSorting() {
337 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, array(self::FIELD_ContentHotel => '4,3'));
338 $this->assertAssertionDataSet('modifyParentRecordAndChangeHotelChildRecordsSorting');
339
340 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
341 $this->assertResponseContentStructureHasRecords(
342 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, self::FIELD_ContentHotel,
343 self::TABLE_Hotel, 'title', array('Hotel #2', 'Hotel #1')
344 );
345 }
346
347 /**
348 * @test
349 */
350 public function modifyParentRecordWithHotelChildRecord() {
351 $this->actionService->modifyRecords(
352 self::VALUE_PageId,
353 array(
354 self::TABLE_Hotel => array('uid' => 4, 'title' => 'Testing #1'),
355 self::TABLE_Content => array('uid' => self::VALUE_ContentIdFirst, self::FIELD_ContentHotel => '3,4'),
356 )
357 );
358 $this->assertAssertionDataSet('modifyParentRecordWithHotelChildRecord');
359
360 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
361 $this->assertResponseContentStructureHasRecords(
362 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, self::FIELD_ContentHotel,
363 self::TABLE_Hotel, 'title', array('Hotel #1', 'Testing #1')
364 );
365 }
366
367 /**
368 * @test
369 */
370 public function modifyParentRecordAndAddHotelChildRecord() {
371 $this->actionService->modifyRecords(
372 self::VALUE_PageId,
373 array(
374 self::TABLE_Hotel => array('uid' => '__NEW', 'title' => 'Hotel #2'),
375 self::TABLE_Content => array('uid' => self::VALUE_ContentIdLast, self::FIELD_ContentHotel => '5,__previousUid'),
376 )
377 );
378 $this->assertAssertionDataSet('modifyParentRecordAndAddHotelChildRecord');
379
380 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
381 $this->assertResponseContentStructureHasRecords(
382 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, self::FIELD_ContentHotel,
383 self::TABLE_Hotel, 'title', array('Hotel #1', 'Hotel #2')
384 );
385 }
386
387 /**
388 * @test
389 */
390 public function modifyParentRecordAndDeleteHotelChildRecord() {
391 $this->actionService->modifyRecord(
392 self::TABLE_Content,
393 self::VALUE_ContentIdFirst,
394 array(self::FIELD_ContentHotel => '3'),
395 array(self::TABLE_Hotel => array(4))
396 );
397 $this->assertAssertionDataSet('modifyParentRecordAndDeleteHotelChildRecord');
398
399 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
400 $this->assertResponseContentStructureHasRecords(
401 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, self::FIELD_ContentHotel,
402 self::TABLE_Hotel, 'title', 'Hotel #1'
403 );
404 $this->assertResponseContentStructureDoesNotHaveRecords(
405 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, self::FIELD_ContentHotel,
406 self::TABLE_Hotel, 'title', 'Hotel #2'
407 );
408 }
409
410 }