‪TYPO3CMS  ‪main
ActionTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
22 use TYPO3\TestingFramework\Core\Functional\Framework\Constraint\RequestSection\DoesNotHaveRecordConstraint;
23 use TYPO3\TestingFramework\Core\Functional\Framework\Constraint\RequestSection\HasRecordConstraint;
24 use TYPO3\TestingFramework\Core\Functional\Framework\Constraint\RequestSection\StructureDoesNotHaveRecordConstraint;
25 use TYPO3\TestingFramework\Core\Functional\Framework\Constraint\RequestSection\StructureHasRecordConstraint;
26 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
27 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\ResponseContent;
28 
30 {
31  #[Test]
32  public function ‪verifyCleanReferenceIndex(): void
33  {
34  // The test verifies the imported data set has a clean reference index by the check in tearDown()
35  self::assertTrue(true);
36  }
37 
38  #[Test]
39  public function ‪modifyContent(): void
40  {
41  parent::modifyContent();
42  $this->assertCSVDataSet(__DIR__ . '/DataSet/modifyContent.csv');
43 
44  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(self::VALUE_PageId));
45  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections();
46  self::assertThat($responseSections, (new HasRecordConstraint())
47  ->setTable(self::TABLE_Content)->setField('header')->setValues('Testing #1'));
48  self::assertThat($responseSections, (new StructureHasRecordConstraint())
49  ->setRecordIdentifier(self::TABLE_Content . ':' . self::VALUE_ContentIdLast)->setRecordField(self::FIELD_ContentImage)
50  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('This is Kasper', 'Taken at T3BOARD'));
51  }
52 
53  #[Test]
54  public function ‪deleteContent(): void
55  {
56  parent::deleteContent();
57  $this->assertCSVDataSet(__DIR__ . '/DataSet/deleteContent.csv');
58 
59  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(self::VALUE_PageId));
60  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections();
61  self::assertThat($responseSections, (new HasRecordConstraint())
62  ->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #1'));
63  self::assertThat($responseSections, (new DoesNotHaveRecordConstraint())
64  ->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #2'));
65  }
66 
67  #[Test]
68  public function ‪copyContent(): void
69  {
70  parent::copyContent();
71  $this->assertCSVDataSet(__DIR__ . '/DataSet/copyContent.csv');
72 
73  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(self::VALUE_PageId));
74  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections();
75  self::assertThat($responseSections, (new HasRecordConstraint())
76  ->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #2 (copy 1)'));
77  self::assertThat($responseSections, (new StructureHasRecordConstraint())
78  ->setRecordIdentifier(self::TABLE_Content . ':' . $this->recordIds['copiedContentId'])->setRecordField(self::FIELD_ContentImage)
79  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('This is Kasper', 'Taken at T3BOARD'));
80  }
81 
82  #[Test]
83  public function ‪copyContentToLanguage(): void
84  {
85  // Create translated page first
86  $this->actionService->copyRecordToLanguage(self::TABLE_Page, self::VALUE_PageId, self::VALUE_LanguageId);
87  parent::copyContentToLanguage();
88  $this->assertCSVDataSet(__DIR__ . '/DataSet/copyContentToLanguage.csv');
89 
90  // Set danish to "free" fallback mode
92  'test',
93  $this->‪buildSiteConfiguration(1, '/'),
94  [
95  $this->‪buildDefaultLanguageConfiguration('EN', '/'),
96  $this->‪buildLanguageConfiguration('DA', '/da/', [], 'free'),
97  $this->‪buildLanguageConfiguration('DE', '/de/', ['DA', 'EN']),
98  ]
99  );
100 
101  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(self::VALUE_PageId)->withLanguageId(self::VALUE_LanguageId));
102  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections();
103  self::assertThat($responseSections, (new HasRecordConstraint())
104  ->setTable(self::TABLE_Content)->setField('header')->setValues('[Translate to Dansk:] Regular Element #2'));
105 
106  self::assertThat($responseSections, (new StructureHasRecordConstraint())
107  ->setRecordIdentifier(self::TABLE_Content . ':' . $this->recordIds['localizedContentId'])->setRecordField(self::FIELD_ContentImage)
108  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('[Translate to Dansk:] This is Kasper', '[Translate to Dansk:] Taken at T3BOARD'));
109  }
110 
111  #[Test]
112  public function ‪localizeContent(): void
113  {
114  parent::localizeContent();
115  $this->assertCSVDataSet(__DIR__ . '/DataSet/localizeContent.csv');
116 
117  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(self::VALUE_PageId)->withLanguageId(self::VALUE_LanguageId));
118  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections();
119  self::assertThat($responseSections, (new HasRecordConstraint())
120  ->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #1', '[Translate to Dansk:] Regular Element #2'));
121 
122  self::assertThat($responseSections, (new StructureHasRecordConstraint())
123  ->setRecordIdentifier(self::TABLE_Content . ':' . self::VALUE_ContentIdLast)->setRecordField(self::FIELD_ContentImage)
124  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('[Translate to Dansk:] This is Kasper', '[Translate to Dansk:] Taken at T3BOARD'));
125  }
126 
127  #[Test]
128  public function ‪changeContentSorting(): void
129  {
130  parent::changeContentSorting();
131  $this->assertCSVDataSet(__DIR__ . '/DataSet/changeContentSorting.csv');
132 
133  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(self::VALUE_PageId));
134  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections();
135  self::assertThat($responseSections, (new HasRecordConstraint())
136  ->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #1', 'Regular Element #2'));
137  self::assertThat($responseSections, (new StructureHasRecordConstraint())
138  ->setRecordIdentifier(self::TABLE_Content . ':' . self::VALUE_ContentIdFirst)->setRecordField(self::FIELD_ContentImage)
139  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('Kasper', 'T3BOARD'));
140  self::assertThat($responseSections, (new StructureHasRecordConstraint())
141  ->setRecordIdentifier(self::TABLE_Content . ':' . self::VALUE_ContentIdLast)->setRecordField(self::FIELD_ContentImage)
142  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('This is Kasper', 'Taken at T3BOARD'));
143  }
144 
145  #[Test]
146  public function ‪moveContentToDifferentPage(): void
147  {
148  parent::moveContentToDifferentPage();
149  $this->assertCSVDataSet(__DIR__ . '/DataSet/moveContentToDifferentPage.csv');
150 
151  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(self::VALUE_PageId));
152  $responseSectionsSource = ResponseContent::fromString((string)$response->getBody())->getSections();
153  self::assertThat($responseSectionsSource, (new HasRecordConstraint())
154  ->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #1'));
155  self::assertThat($responseSectionsSource, (new StructureHasRecordConstraint())
156  ->setRecordIdentifier(self::TABLE_Content . ':' . self::VALUE_ContentIdFirst)->setRecordField(self::FIELD_ContentImage)
157  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('Kasper', 'T3BOARD'));
158  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(self::VALUE_PageIdTarget));
159  $responseSectionsTarget = ResponseContent::fromString((string)$response->getBody())->getSections();
160  self::assertThat($responseSectionsTarget, (new HasRecordConstraint())
161  ->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #2'));
162  self::assertThat($responseSectionsTarget, (new StructureHasRecordConstraint())
163  ->setRecordIdentifier(self::TABLE_Content . ':' . self::VALUE_ContentIdLast)->setRecordField(self::FIELD_ContentImage)
164  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('This is Kasper', 'Taken at T3BOARD'));
165  }
166 
167  #[Test]
169  {
170  parent::moveContentToDifferentPageAndChangeSorting();
171  $this->assertCSVDataSet(__DIR__ . '/DataSet/moveContentToDifferentPageNChangeSorting.csv');
172 
173  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(self::VALUE_PageIdTarget));
174  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections();
175  self::assertThat($responseSections, (new HasRecordConstraint())
176  ->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #1', 'Regular Element #2'));
177  self::assertThat($responseSections, (new StructureHasRecordConstraint())
178  ->setRecordIdentifier(self::TABLE_Content . ':' . self::VALUE_ContentIdFirst)->setRecordField(self::FIELD_ContentImage)
179  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('Kasper', 'T3BOARD'));
180  self::assertThat($responseSections, (new StructureHasRecordConstraint())
181  ->setRecordIdentifier(self::TABLE_Content . ':' . self::VALUE_ContentIdLast)->setRecordField(self::FIELD_ContentImage)
182  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('This is Kasper', 'Taken at T3BOARD'));
183  }
184 
185  #[Test]
186  public function ‪createContentWithFileReference(): void
187  {
188  parent::createContentWithFileReference();
189  $this->assertCSVDataSet(__DIR__ . '/DataSet/createContentWFileReference.csv');
190 
191  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(self::VALUE_PageId));
192  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections();
193  self::assertThat($responseSections, (new HasRecordConstraint())
194  ->setTable(self::TABLE_Content)->setField('header')->setValues('Testing #1'));
195  self::assertThat($responseSections, (new StructureHasRecordConstraint())
196  ->setRecordIdentifier(self::TABLE_Content . ':' . $this->recordIds['newContentId'])->setRecordField(self::FIELD_ContentImage)
197  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('Image #1'));
198  }
199 
200  #[Test]
201  public function ‪modifyContentWithFileReference(): void
202  {
203  parent::modifyContentWithFileReference();
204  $this->assertCSVDataSet(__DIR__ . '/DataSet/modifyContentWFileReference.csv');
205 
206  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(self::VALUE_PageId));
207  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections();
208  self::assertThat($responseSections, (new HasRecordConstraint())
209  ->setTable(self::TABLE_Content)->setField('header')->setValues('Testing #1'));
210  self::assertThat($responseSections, (new StructureHasRecordConstraint())
211  ->setRecordIdentifier(self::TABLE_Content . ':' . self::VALUE_ContentIdLast)->setRecordField(self::FIELD_ContentImage)
212  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('Taken at T3BOARD', 'Image #1'));
213  }
214 
215  #[Test]
216  public function ‪modifyContentAndAddFileReference(): void
217  {
218  parent::modifyContentAndAddFileReference();
219  $this->assertCSVDataSet(__DIR__ . '/DataSet/modifyContentNAddFileReference.csv');
220 
221  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(self::VALUE_PageId));
222  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections();
223  self::assertThat($responseSections, (new StructureHasRecordConstraint())
224  ->setRecordIdentifier(self::TABLE_Content . ':' . self::VALUE_ContentIdLast)->setRecordField(self::FIELD_ContentImage)
225  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('Taken at T3BOARD', 'This is Kasper', 'Image #3'));
226  }
227 
228  #[Test]
230  {
231  parent::modifyContentAndDeleteFileReference();
232  $this->assertCSVDataSet(__DIR__ . '/DataSet/modifyContentNDeleteFileReference.csv');
233 
234  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(self::VALUE_PageId));
235  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections();
236  self::assertThat($responseSections, (new StructureHasRecordConstraint())
237  ->setRecordIdentifier(self::TABLE_Content . ':' . self::VALUE_ContentIdLast)->setRecordField(self::FIELD_ContentImage)
238  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('This is Kasper'));
239  self::assertThat($responseSections, (new StructureDoesNotHaveRecordConstraint())
240  ->setRecordIdentifier(self::TABLE_Content . ':' . self::VALUE_ContentIdLast)->setRecordField(self::FIELD_ContentImage)
241  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('Taken at T3BOARD'));
242  }
243 
244  #[Test]
246  {
247  parent::modifyContentAndDeleteAllFileReference();
248  $this->assertCSVDataSet(__DIR__ . '/DataSet/modifyContentNDeleteAllFileReference.csv');
249 
250  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(self::VALUE_PageId));
251  $responseSections = ResponseContent::fromString((string)$response->getBody())->getSections();
252  self::assertThat($responseSections, (new StructureDoesNotHaveRecordConstraint())
253  ->setRecordIdentifier(self::TABLE_Content . ':' . self::VALUE_ContentIdLast)->setRecordField(self::FIELD_ContentImage)
254  ->setTable(self::TABLE_FileReference)->setField('title')->setValues('Taken at T3BOARD', 'This is Kasper'));
255  }
256 
257  #[Test]
259  {
260  parent::createContentWithFileReferenceAndDeleteFileReference();
261  $this->assertCSVDataSet(__DIR__ . '/DataSet/createContentWFileReferenceNDeleteFileReference.csv');
262  // No FE test: Create and delete scenarios have FE coverage, this test is only about DB state.
263  }
264 
265  #[Test]
266  public function ‪creatingFileIsDenied(): void
267  {
268  $this->expectedErrorLogEntries = 1;
269  $this->actionService->createNewRecord('sys_file', 0, [
270  'storage' => 1,
271  'name' => 'any.file',
272  'extension' => 'file',
273  'identifer' => '/any.file',
274  'mime_type' => 'text/plain',
275  'sha1' => 'this-is-not-a-hash-value',
276  ]);
277  $this->assertCSVDataSet(__DIR__ . '/DataSet/sysFileUnchanged.csv');
278  }
279 
280  #[Test]
281  public function ‪modifyingFileIsDenied(): void
282  {
283  $this->expectedErrorLogEntries = 1;
284  $this->actionService->modifyRecord('sys_file', 21, [
285  'storage' => 1,
286  'name' => 'any.file',
287  'extension' => 'file',
288  'identifer' => '/any.file',
289  'mime_type' => 'text/plain',
290  'sha1' => 'this-is-not-a-hash-value',
291  ]);
292  $this->assertCSVDataSet(__DIR__ . '/DataSet/sysFileUnchanged.csv');
293  }
294 
295  #[Test]
297  {
298  $this->expectedErrorLogEntries = 1;
299  $this->actionService->modifyRecord('sys_file_reference', 127, [
300  'uid_local' => 9,
301  ]);
302  $this->assertCSVDataSet(__DIR__ . '/DataSet/sysFileUnchanged.csv');
303  }
304 
305  #[Test]
307  {
308  $this->expectedErrorLogEntries = 1;
309  $this->actionService->modifyRecord('sys_file_metadata', 21, [
310  'file' => 9,
311  ]);
312  $this->assertCSVDataSet(__DIR__ . '/DataSet/sysFileUnchanged.csv');
313  }
314 }
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\createContentWithFileReference
‪createContentWithFileReference()
Definition: ActionTest.php:186
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildLanguageConfiguration
‪buildLanguageConfiguration(string $identifier, string $base, array $fallbackIdentifiers=[], string $fallbackType=null)
Definition: SiteBasedTestTrait.php:108
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\moveContentToDifferentPageAndChangeSorting
‪moveContentToDifferentPageAndChangeSorting()
Definition: ActionTest.php:168
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\modifyingFileIsDenied
‪modifyingFileIsDenied()
Definition: ActionTest.php:281
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\localizeContent
‪localizeContent()
Definition: ActionTest.php:112
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:88
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\modifyContentWithFileReference
‪modifyContentWithFileReference()
Definition: ActionTest.php:201
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\modifyContent
‪modifyContent()
Definition: ActionTest.php:39
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\modifyContentAndDeleteFileReference
‪modifyContentAndDeleteFileReference()
Definition: ActionTest.php:229
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\usingLegacyStorageFileInFileMetadataIsDenied
‪usingLegacyStorageFileInFileMetadataIsDenied()
Definition: ActionTest.php:306
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\modifyContentAndAddFileReference
‪modifyContentAndAddFileReference()
Definition: ActionTest.php:216
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\changeContentSorting
‪changeContentSorting()
Definition: ActionTest.php:128
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\verifyCleanReferenceIndex
‪verifyCleanReferenceIndex()
Definition: ActionTest.php:32
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\AbstractActionTestCase
Definition: AbstractActionTestCase.php:24
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\usingLegacyStorageFileInFileReferenceIsDenied
‪usingLegacyStorageFileInFileReferenceIsDenied()
Definition: ActionTest.php:296
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\creatingFileIsDenied
‪creatingFileIsDenied()
Definition: ActionTest.php:266
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest
Definition: ActionTest.php:30
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\modifyContentAndDeleteAllFileReference
‪modifyContentAndDeleteAllFileReference()
Definition: ActionTest.php:245
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:98
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\moveContentToDifferentPage
‪moveContentToDifferentPage()
Definition: ActionTest.php:146
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\copyContent
‪copyContent()
Definition: ActionTest.php:68
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\copyContentToLanguage
‪copyContentToLanguage()
Definition: ActionTest.php:83
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\deleteContent
‪deleteContent()
Definition: ActionTest.php:54
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify
Definition: ActionTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\DataScenarios\FAL\Modify\ActionTest\createContentWithFileReferenceAndDeleteFileReference
‪createContentWithFileReferenceAndDeleteFileReference()
Definition: ActionTest.php:258