[BUGFIX] Fix functional tests for EXT:impexp on PostgreSQL
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Tests / Functional / Export / PagesAndTtContentWithImages / ExportTest.php
1 <?php
2 namespace TYPO3\CMS\Impexp\Tests\Functional\Export\PagesAndTtContentWithImages;
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\Backend\Utility\BackendUtility;
18
19 /**
20 * Functional test for the Export
21 */
22 class ExportTest extends \TYPO3\CMS\Impexp\Tests\Functional\Export\AbstractExportTestCase
23 {
24 /**
25 * @var array
26 */
27 protected $pathsToLinkInTestInstance = [
28 'typo3/sysext/impexp/Tests/Functional/Fixtures/Folders/fileadmin/user_upload' => 'fileadmin/user_upload'
29 ];
30
31 protected function setUp()
32 {
33 parent::setUp();
34
35 $this->importDataSet(__DIR__ . '/../../Fixtures/Database/pages.xml');
36 $this->importDataSet(__DIR__ . '/../../Fixtures/Database/tt_content-with-image.xml');
37 $this->importDataSet(__DIR__ . '/../../Fixtures/Database/sys_language.xml');
38 $this->importDataSet(__DIR__ . '/../../Fixtures/Database/sys_file_metadata.xml');
39 $this->importDataSet(__DIR__ . '/../../Fixtures/Database/sys_file_reference.xml');
40 $this->importDataSet(__DIR__ . '/../../Fixtures/Database/sys_file_storage.xml');
41 }
42
43 /**
44 * @test
45 */
46 public function exportPagesAndRelatedTtContentWithImages()
47 {
48 $this->importDataSet(__DIR__ . '/../../Fixtures/Database/sys_file.xml');
49
50 $this->compileExportPagesAndRelatedTtContentWithImages();
51
52 $out = $this->export->compileMemoryToFileContent('xml');
53
54 $errors = $this->export->printErrorLog();
55 $this->assertSame('', $errors);
56
57 $this->assertXmlStringEqualsXmlFile(
58 $this->getXmlFilePath('pages-and-ttcontent-with-image.xml'),
59 $out
60 );
61 }
62
63 /**
64 * @test
65 */
66 public function exportPagesAndRelatedTtContentWithImagesFromCorruptSysFileRecord()
67 {
68 $this->importDataSet(__DIR__ . '/../../Fixtures/Database/sys_file_corrupt.xml');
69
70 $this->compileExportPagesAndRelatedTtContentWithImages();
71
72 $out = $this->export->compileMemoryToFileContent('xml');
73
74 $expectedErrors = [
75 'File size of 1:/user_upload/typo3_image2.jpg is not up-to-date in index! File added with current size.',
76 'File sha1 hash of 1:/user_upload/typo3_image2.jpg is not up-to-date in index! File added on current sha1.'
77 ];
78 $errors = $this->export->errorLog;
79 $this->assertSame($expectedErrors, $errors);
80
81 $this->assertXmlStringEqualsXmlFile(
82 $this->getXmlFilePath('pages-and-ttcontent-with-corrupt-image.xml'),
83 $out
84 );
85 }
86
87 /**
88 * @test
89 */
90 public function exportPagesAndRelatedTtContentWithImagesButNotIncluded()
91 {
92 $this->importDataSet(__DIR__ . '/../../Fixtures/Database/sys_file.xml');
93
94 $this->export->setSaveFilesOutsideExportFile(true);
95
96 $this->compileExportPagesAndRelatedTtContentWithImages();
97
98 $out = $this->export->compileMemoryToFileContent('xml');
99
100 $this->assertXmlStringEqualsXmlFile(
101 $this->getXmlFilePath('pages-and-ttcontent-with-image-but-not-included.xml'),
102 $out
103 );
104
105 $temporaryFilesDirectory = $this->export->getTemporaryFilesPathForExport();
106 $this->assertFileEquals(__DIR__ . '/../../Fixtures/Folders/fileadmin/user_upload/typo3_image2.jpg', $temporaryFilesDirectory . 'da9acdf1e105784a57bbffec9520969578287797');
107 }
108
109 protected function compileExportPagesAndRelatedTtContentWithImages()
110 {
111 $this->export->setRecordTypesIncludeFields(
112 [
113 'pages' => [
114 'title',
115 'deleted',
116 'doktype',
117 'hidden',
118 'perms_everybody'
119 ],
120 'tt_content' => [
121 'CType',
122 'header',
123 'header_link',
124 'deleted',
125 'hidden',
126 'image',
127 't3ver_oid'
128 ],
129 'sys_language' => [
130 'uid',
131 'pid',
132 'hidden',
133 'title',
134 'flag'
135 ],
136 'sys_file_reference' => [
137 'uid_local',
138 'uid_foreign',
139 'tablenames',
140 'fieldname',
141 'sorting_foreign',
142 'table_local',
143 'title',
144 'description',
145 'alternative',
146 'link',
147 ],
148 'sys_file' => [
149 'storage',
150 'type',
151 'metadata',
152 'identifier',
153 'identifier_hash',
154 'folder_hash',
155 'mime_type',
156 'name',
157 'sha1',
158 'size',
159 'creation_date',
160 'modification_date',
161 ],
162 'sys_file_storage' => [
163 'name',
164 'description',
165 'driver',
166 'configuration',
167 'is_default',
168 'is_browsable',
169 'is_public',
170 'is_writable',
171 'is_online'
172 ],
173 'sys_file_metadata' => [
174 'title',
175 'width',
176 'height',
177 'description',
178 'alternative',
179 'file',
180 'sys_language_uid',
181 'l10n_parent'
182 ]
183 ]
184 );
185
186 $this->export->relOnlyTables = [
187 'sys_file',
188 'sys_file_metadata',
189 'sys_file_storage',
190 'sys_language'
191 ];
192
193 $this->export->export_addRecord('pages', BackendUtility::getRecord('pages', 1));
194 $this->export->export_addRecord('pages', BackendUtility::getRecord('pages', 2));
195 $this->export->export_addRecord('tt_content', BackendUtility::getRecord('tt_content', 1));
196 $this->export->export_addRecord('sys_language', BackendUtility::getRecord('sys_language', 1));
197 $this->export->export_addRecord('sys_file_reference', BackendUtility::getRecord('sys_file_reference', 1));
198
199 $this->setPageTree(1, 1);
200
201 // After adding ALL records we set relations:
202 for ($a = 0; $a < 10; $a++) {
203 $addR = $this->export->export_addDBRelations($a);
204 if (empty($addR)) {
205 break;
206 }
207 }
208
209 $this->export->export_addFilesFromRelations();
210 $this->export->export_addFilesFromSysFilesRecords();
211 }
212 }