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