[TASK] Use Environment API instead of PATH_site in impexp
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Tests / Functional / Import / PagesAndTtContentWithImagesInFilledDatabaseTest.php
1 <?php
2 namespace TYPO3\CMS\Impexp\Tests\Functional\Import;
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
17 use TYPO3\CMS\Core\Core\Environment;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Impexp\Import;
20 use TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase;
21
22 /**
23 * Test case
24 */
25 class PagesAndTtContentWithImagesInFilledDatabaseTest extends AbstractImportExportTestCase
26 {
27 /**
28 * @var array
29 */
30 protected $additionalFoldersToCreate = [
31 '/fileadmin/user_upload'
32 ];
33
34 /**
35 * @var array
36 */
37 protected $pathsToProvideInTestInstance = [
38 'typo3/sysext/impexp/Tests/Functional/Fixtures/Folders/fileadmin/user_upload/typo3_image2.jpg' => 'fileadmin/user_upload/typo3_image2.jpg',
39 ];
40
41 /**
42 * @test
43 */
44 public function importPagesAndRelatedTtContentWithDifferentImageToExistingData()
45 {
46 $subject = GeneralUtility::makeInstance(Import::class);
47 $subject->init();
48
49 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/pages.xml');
50 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/tt_content-with-image.xml');
51 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/sys_language.xml');
52 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/sys_file.xml');
53 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/sys_file_metadata.xml');
54 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/sys_file_reference.xml');
55 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/sys_file_storage.xml');
56
57 $subject->loadFile(
58 __DIR__ . '/../Fixtures/XmlImports/pages-and-ttcontent-with-existing-different-image.xml',
59 1
60 );
61 $subject->importData(0);
62
63 $this->testFilesToDelete[] = Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg';
64 $this->testFilesToDelete[] = Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2_01.jpg';
65
66 $this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importPagesAndRelatedTtContentWithDifferentImageToExistingData.csv');
67
68 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image2.jpg', Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg');
69 $this->assertFileEquals(__DIR__ . '/../Fixtures/FileAssertions/typo3_image2_01.jpg', Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2_01.jpg');
70 }
71
72 /**
73 * @test
74 */
75 public function importPagesAndRelatedTtContentWithSameImageToExistingData()
76 {
77 $subject = GeneralUtility::makeInstance(Import::class);
78 $subject->init();
79
80 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/pages.xml');
81 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/tt_content-with-image.xml');
82 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/sys_language.xml');
83 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/sys_file.xml');
84 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/sys_file_metadata.xml');
85 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/sys_file_reference.xml');
86 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/sys_file_storage.xml');
87
88 $subject->loadFile(
89 __DIR__ . '/../Fixtures/XmlImports/pages-and-ttcontent-with-existing-same-image.xml',
90 1
91 );
92 $subject->importData(0);
93
94 $this->testFilesToDelete[] = Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg';
95
96 $this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importPagesAndRelatedTtContentWithSameImageToExistingData.csv');
97
98 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image2.jpg', Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg');
99 }
100
101 /**
102 * This test checks multiple remapping does not occur - issue #67188
103 * Scenario:
104 * - Have a local sys_file:1 entry to some image
105 * - Have an import file with 3 tt_content, first element pointing to sys_file:1
106 * image "used-1.jpg" (different from locally existing one), and the other two pointing to
107 * sys_file:2 "used-2.jpg" (also not existing locally)
108 * Upon import, the following is expected:
109 * - sys_file:1 from import file becomes sys_file:2 locally
110 * - sys_file:2 from import file becomes sys_file:3 locally
111 * - content element:1 should reference sys_file:2
112 * - content element:2 & 3 should reference sys_file:3
113 * The issue from #67188 is that tt_content:1 was first mapped to sys_file:2
114 * and when tt_content:2 and tt_content:3 were processed, tt_content:1 image
115 * reference was mapped a second time to the not correct relation sys_file:3,
116 * ending up in mixed sys_file_reference entries.
117 * This test verifies first content element still points to the image used-1.jpg
118 * while the other two point to point to image used-2.jpg
119 * Note the internal handler mixes up insert orders resulting in former tt_content:1
120 * ending up as tt_content:3 and 2/3 ending up as 2/1 uid-wise ... making this issue
121 * even harder to grasp.
122 *
123 * @test
124 */
125 public function importPagesAndTtContentWithRemappingNewSysFileEntries()
126 {
127 $subject = GeneralUtility::makeInstance(Import::class);
128 $subject->init();
129
130 // Have a single sys_file entry with uid 1
131 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/sys_file_single_image.xml');
132 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/sys_file_storage.xml');
133
134 // Import file with sys_file:1 and sys_file:2, where sys_file:1 has one connected
135 // content element, and sys_file:2 has two connected content elements.
136 $subject->loadFile(
137 __DIR__ . '/../Fixtures/XmlImports/pages-and-ttcontent-with-two-images.xml',
138 1
139 );
140 $subject->importData(0);
141
142 $this->testFilesToDelete[] = Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg';
143 $this->testFilesToDelete[] = Environment::getPublicPath() . '/fileadmin/user_upload/used-1.jpg';
144 $this->testFilesToDelete[] = Environment::getPublicPath() . '/fileadmin/user_upload/used-2.jpg';
145
146 // Expect mapping is updated: one content element should still reference new sys_file:2,
147 // two others should reference new sys_file:3
148 $this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importPagesAndTtContentWithRemappingNewSysFileEntries.csv');
149 }
150 }