fdea3018f3a60880976476a98d69b7f4d8f248d1
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / DataHandling / ManyToMany / AbstractActionTestCase.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\DataHandling\ManyToMany;
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(__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_ContentIdFirst = 297;
37 const VALUE_ContentIdLast = 298;
38 const VALUE_LanguageId = 1;
39 const VALUE_CategoryIdFirst = 28;
40 const VALUE_CategoryIdSecond = 29;
41
42 const TABLE_Content = 'tt_content';
43 const TABLE_Category = 'sys_category';
44 const TABLE_ContentCategory_ManyToMany = 'sys_category_record_mm';
45
46 /**
47 * @var string
48 */
49 protected $dataSetDirectory = 'typo3/sysext/core/Tests/Functional/DataHandling/ManyToMany/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 * MM Relations
61 */
62
63 /**
64 * @test
65 */
66 public function addCategoryRelation() {
67 $this->actionService->modifyReferences(
68 self::TABLE_Content, self::VALUE_ContentIdFirst, 'categories', array(self::VALUE_CategoryIdFirst, self::VALUE_CategoryIdSecond, 31)
69 );
70 $this->assertAssertionDataSet('addCategoryRelation');
71
72 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
73 $this->assertResponseContentStructureHasRecords(
74 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, 'categories',
75 self::TABLE_Category, 'title', array('Category A', 'Category B', 'Category A.A')
76 );
77 }
78
79 /**
80 * @test
81 */
82 public function deleteCategoryRelation() {
83 $this->actionService->modifyReferences(
84 self::TABLE_Content, self::VALUE_ContentIdFirst, 'categories', array(self::VALUE_CategoryIdFirst)
85 );
86 $this->assertAssertionDataSet('deleteCategoryRelation');
87
88 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
89 $this->assertResponseContentStructureHasRecords(
90 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, 'categories',
91 self::TABLE_Category, 'title', array('Category A')
92 );
93 $this->assertResponseContentStructureDoesNotHaveRecords(
94 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, 'categories',
95 self::TABLE_Category, 'title', array('Category B', 'Category C', 'Category A.A')
96 );
97 }
98
99 /**
100 * @test
101 */
102 public function changeCategoryRelationSorting() {
103 $this->actionService->modifyReferences(
104 self::TABLE_Content, self::VALUE_ContentIdFirst, 'categories', array(self::VALUE_CategoryIdSecond, self::VALUE_CategoryIdFirst)
105 );
106 $this->assertAssertionDataSet('changeCategoryRelationSorting');
107
108 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
109 $this->assertResponseContentStructureHasRecords(
110 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, 'categories',
111 self::TABLE_Category, 'title', array('Category A', 'Category B')
112 );
113 }
114
115 /**
116 * @test
117 */
118 public function modifyCategoryRecordOfCategoryRelation() {
119 $this->actionService->modifyRecord(self::TABLE_Category, self::VALUE_CategoryIdFirst, array('title' => 'Testing #1'));
120 $this->assertAssertionDataSet('modifyCategoryRecordOfCategoryRelation');
121
122 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
123 $this->assertResponseContentStructureHasRecords(
124 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, 'categories',
125 self::TABLE_Category, 'title', array('Testing #1', 'Category B')
126 );
127 }
128
129 /**
130 * @test
131 */
132 public function modifyContentRecordOfCategoryRelation() {
133 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, array('header' => 'Testing #1'));
134 $this->assertAssertionDataSet('modifyContentRecordOfCategoryRelation');
135
136 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
137 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Testing #1');
138 }
139
140 /**
141 * @test
142 */
143 public function modifyBothRecordsOfCategoryRelation() {
144 $this->actionService->modifyRecord(self::TABLE_Category, self::VALUE_CategoryIdFirst, array('title' => 'Testing #1'));
145 $this->actionService->modifyRecord(self::TABLE_Content, self::VALUE_ContentIdFirst, array('header' => 'Testing #1'));
146 $this->assertAssertionDataSet('modifyBothRecordsOfCategoryRelation');
147
148 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
149 $this->assertResponseContentStructureHasRecords(
150 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, 'categories',
151 self::TABLE_Category, 'title', array('Testing #1', 'Category B')
152 );
153 $this->assertResponseContentHasRecords($responseContent, self::TABLE_Content, 'header', 'Testing #1');
154 }
155
156 /**
157 * @test
158 */
159 public function deleteContentRecordOfCategoryRelation() {
160 $this->actionService->deleteRecord(self::TABLE_Content, self::VALUE_ContentIdLast);
161 $this->assertAssertionDataSet('deleteContentRecordOfCategoryRelation');
162
163 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
164 $this->assertResponseContentDoesNotHaveRecords($responseContent, self::TABLE_Content, 'header', 'Testing #1');
165 }
166
167 /**
168 * @test
169 */
170 public function deleteCategoryRecordOfCategoryRelation() {
171 $this->actionService->deleteRecord(self::TABLE_Category, self::VALUE_CategoryIdFirst);
172 $this->assertAssertionDataSet('deleteCategoryRecordOfCategoryRelation');
173
174 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
175 $this->assertResponseContentStructureDoesNotHaveRecords(
176 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, 'categories',
177 self::TABLE_Category, 'title', array('Category A')
178 );
179 }
180
181 /**
182 * @test
183 */
184 public function copyContentRecordOfCategoryRelation() {
185 $newTableIds = $this->actionService->copyRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageId);
186 $this->assertAssertionDataSet('copyContentRecordOfCategoryRelation');
187
188 $newContentId = $newTableIds[self::TABLE_Content][self::VALUE_ContentIdLast];
189 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
190 $this->assertResponseContentStructureHasRecords(
191 $responseContent, self::TABLE_Content . ':' . $newContentId, 'categories',
192 self::TABLE_Category, 'title', array('Category B', 'Category C')
193 );
194 }
195
196 /**
197 * @test
198 */
199 public function copyCategoryRecordOfCategoryRelation() {
200 $this->actionService->copyRecord(self::TABLE_Category, self::VALUE_CategoryIdFirst, 0);
201 $this->assertAssertionDataSet('copyCategoryRecordOfCategoryRelation');
202
203 $responseContent = $this->getFrontendResponse(self::VALUE_PageId)->getResponseContent();
204 $this->assertResponseContentStructureHasRecords(
205 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, 'categories',
206 self::TABLE_Category, 'title', 'Category A'
207 // @todo Actually it should be twice "Category A" since the category got copied
208 // self::TABLE_Category, 'title', array('Category A', 'Category A')
209 );
210 }
211
212 /**
213 * @test
214 */
215 public function localizeContentRecordOfCategoryRelation() {
216 $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_LanguageId);
217 $this->assertAssertionDataSet('localizeContentRecordOfCategoryRelation');
218
219 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, self::VALUE_LanguageId)->getResponseContent();
220 $this->assertResponseContentStructureHasRecords(
221 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, 'categories',
222 self::TABLE_Category, 'title', array('Category B', 'Category C')
223 );
224 }
225
226 /**
227 * @test
228 */
229 public function localizeCategoryRecordOfCategoryRelation() {
230 $this->actionService->localizeRecord(self::TABLE_Category, self::VALUE_CategoryIdFirst, self::VALUE_LanguageId);
231 $this->assertAssertionDataSet('localizeCategoryRecordOfCategoryRelation');
232
233 $responseContent = $this->getFrontendResponse(self::VALUE_PageId, self::VALUE_LanguageId)->getResponseContent();
234 $this->assertResponseContentStructureHasRecords(
235 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdFirst, 'categories',
236 self::TABLE_Category, 'title', array('Category A', 'Category B')
237 // @todo Actually it should contain the localized category
238 // self::TABLE_Category, 'title', array('[Translate to Dansk:] Category A', 'Category B')
239 );
240 }
241
242 /**
243 * @test
244 */
245 public function moveContentRecordOfCategoryRelationToDifferentPage() {
246 $this->actionService->moveRecord(self::TABLE_Content, self::VALUE_ContentIdLast, self::VALUE_PageIdTarget);
247 $this->assertAssertionDataSet('moveContentRecordOfCategoryRelationToDifferentPage');
248
249 $responseContent = $this->getFrontendResponse(self::VALUE_PageIdTarget)->getResponseContent();
250 $this->assertResponseContentStructureHasRecords(
251 $responseContent, self::TABLE_Content . ':' . self::VALUE_ContentIdLast, 'categories',
252 self::TABLE_Category, 'title', array('Category B', 'Category C')
253 );
254 }
255
256 }