[TASK] Use Environment API instead of PATH_site in impexp
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Tests / Functional / Import / PagesAndTtContentWithImagesInEmptyDatabaseTest.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 PagesAndTtContentWithImagesInEmptyDatabaseTest extends AbstractImportExportTestCase
26 {
27 /**
28 * @test
29 */
30 public function importPagesAndRelatedTtContentWithImagesOnCaseSensitiveFilesystems()
31 {
32 $subject = GeneralUtility::makeInstance(Import::class);
33 $subject->init();
34
35 if (!$this->isCaseSensitiveFilesystem()) {
36 $this->markTestSkipped('Test not available on case insensitive filesystems.');
37 }
38
39 $subject->loadFile(
40 __DIR__ . '/../Fixtures/XmlImports/pages-and-ttcontent-with-image.xml',
41 1
42 );
43 $subject->importData(0);
44
45 $this->testFilesToDelete[] = Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg';
46
47 $this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importPagesAndRelatedTtContentWithImagesOnCaseSensitiveFilesystems.csv');
48
49 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image2.jpg', Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg');
50 }
51
52 /**
53 * @test
54 */
55 public function importPagesAndRelatedTtContentWithImagesOnCaseInsensitiveFilesystems()
56 {
57 $subject = GeneralUtility::makeInstance(Import::class);
58 $subject->init();
59
60 if ($this->isCaseSensitiveFilesystem()) {
61 $this->markTestSkipped('Test not available on case sensitive filesystems.');
62 }
63
64 $subject->loadFile(
65 __DIR__ . '/../Fixtures/XmlImports/pages-and-ttcontent-with-image.xml',
66 1
67 );
68 $subject->importData(0);
69
70 $this->testFilesToDelete[] = Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg';
71
72 $this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importPagesAndRelatedTtContentWithImagesOnCaseInsensitiveFilesystems.csv');
73
74 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image2.jpg', Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg');
75 }
76
77 /**
78 * @test
79 */
80 public function importPagesAndRelatedTtContentWithImagesButWithoutStorageOnCaseSensitiveFilesystems()
81 {
82 $subject = GeneralUtility::makeInstance(Import::class);
83 $subject->init();
84
85 if (!$this->isCaseSensitiveFilesystem()) {
86 $this->markTestSkipped('Test not available on case insensitive filesystems.');
87 }
88
89 $subject->loadFile(
90 __DIR__ . '/../Fixtures/XmlImports/pages-and-ttcontent-with-image-without-storage.xml',
91 1
92 );
93 $subject->importData(0);
94
95 $this->testFilesToDelete[] = Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg';
96
97 $this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importPagesAndRelatedTtContentWithImagesButWithoutStorageOnCaseSensitiveFilesystems.csv');
98
99 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image2.jpg', Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg');
100 }
101
102 /**
103 * @test
104 */
105 public function importPagesAndRelatedTtContentWithImagesButWithoutStorageOnCaseInsensitiveFilesystems()
106 {
107 $subject = GeneralUtility::makeInstance(Import::class);
108 $subject->init();
109
110 if ($this->isCaseSensitiveFilesystem()) {
111 $this->markTestSkipped('Test not available on case sensitive filesystems.');
112 }
113
114 $subject->loadFile(
115 __DIR__ . '/../Fixtures/XmlImports/pages-and-ttcontent-with-image-without-storage.xml',
116 1
117 );
118 $subject->importData(0);
119
120 $this->testFilesToDelete[] = Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg';
121
122 $this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importPagesAndRelatedTtContentWithImagesButWithoutStorageOnCaseInsensitiveFilesystems.csv');
123
124 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image2.jpg', Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg');
125 }
126
127 /**
128 * @test
129 */
130 public function importPagesAndRelatedTtContentWithImagesWithSpacesInPath()
131 {
132 $subject = GeneralUtility::makeInstance(Import::class);
133 $subject->init();
134
135 $subject->loadFile(
136 __DIR__ . '/../Fixtures/XmlImports/pages-and-ttcontent-with-image-with-spaces-in-path.xml',
137 1
138 );
139 $subject->importData(0);
140
141 $this->testFilesToDelete[] = Environment::getPublicPath() . '/fileadmin/user_upload/folder_with_spaces/typo3_image2.jpg';
142 $this->testFilesToDelete[] = Environment::getPublicPath() . '/fileadmin/user_upload/folder_with_spaces/typo3_image3.jpg';
143
144 $this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importPagesAndRelatedTtContentWithImagesWithSpacesInPath.csv');
145
146 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image2.jpg', Environment::getPublicPath() . '/fileadmin/user_upload/folder_with_spaces/typo3_image2.jpg');
147 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image3.jpg', Environment::getPublicPath() . '/fileadmin/user_upload/folder_with_spaces/typo3_image3.jpg');
148 }
149
150 /**
151 * @test
152 */
153 public function importPagesAndRelatedTtContentWithImagesButNotIncluded()
154 {
155 $subject = GeneralUtility::makeInstance(Import::class);
156 $subject->init();
157
158 $subject->loadFile(
159 // Files are parallel to the fixture .xml file in a folder - impexp tests for /../ not allowed in path, so we set an absolute path here
160 Environment::getPublicPath() . '/typo3/sysext/impexp/Tests/Functional/Fixtures/XmlImports/pages-and-ttcontent-with-image-but-not-included.xml',
161 1
162 );
163 $subject->importData(0);
164
165 $this->testFilesToDelete[] = Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg';
166
167 $this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importPagesAndRelatedTtContentWithImagesButNotIncluded.csv');
168
169 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image2.jpg', Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg');
170 }
171
172 /**
173 * @test
174 * @group not-mssql
175 */
176 public function importPagesAndRelatedTtContentWithImageWithForcedUids()
177 {
178 $subject = GeneralUtility::makeInstance(Import::class);
179 $subject->init();
180
181 $subject->loadFile(
182 __DIR__ . '/../Fixtures/XmlImports/pages-and-ttcontent-with-image-with-forced-uids.xml',
183 1
184 );
185 $subject->force_all_UIDS = true;
186 $subject->importData(0);
187
188 $this->testFilesToDelete[] = Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg';
189
190 $this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importPagesAndRelatedTtContentWithImageWithForcedUids.csv');
191
192 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image2.jpg', Environment::getPublicPath() . '/fileadmin/user_upload/typo3_image2.jpg');
193
194 $expectedErrors = [
195 'Forcing uids of sys_file records is not supported! They will be imported as new records!'
196 ];
197 $errors = $subject->errorLog;
198 $this->assertSame($expectedErrors, $errors);
199 }
200 }