[BUGFIX] mssql: ext:impexp test fixes
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Tests / Functional / Export / GroupFileAndFileReferenceItemTest.php
1 <?php
2 namespace TYPO3\CMS\Impexp\Tests\Functional\Export;
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 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Impexp\Export;
20 use TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase;
21
22 /**
23 * Test case
24 */
25 class GroupFileAndFileReferenceItemTest extends AbstractImportExportTestCase
26 {
27 /**
28 * @var array
29 */
30 protected $testExtensionsToLoad = [
31 'typo3/sysext/impexp/Tests/Functional/Fixtures/Extensions/impexp_group_files'
32 ];
33
34 /**
35 * @var array
36 */
37 protected $pathsToLinkInTestInstance = [
38 'typo3/sysext/impexp/Tests/Functional/Fixtures/Folders/fileadmin/user_upload' => 'fileadmin/user_upload',
39 'typo3/sysext/impexp/Tests/Functional/Fixtures/Folders/uploads/tx_impexpgroupfiles' => 'uploads/tx_impexpgroupfiles'
40 ];
41
42 protected function setUp()
43 {
44 parent::setUp();
45
46 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/pages.xml');
47 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/sys_file.xml');
48 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/sys_file_storage.xml');
49 $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/tx_impexpgroupfiles_item.xml');
50 }
51
52 /**
53 * @test
54 */
55 public function exportGroupFileAndFileReferenceItem()
56 {
57 $subject = GeneralUtility::makeInstance(Export::class);
58 $subject->init();
59
60 $this->compileExportGroupFileAndFileReferenceItem($subject);
61
62 $out = $subject->compileMemoryToFileContent('xml');
63
64 $this->assertXmlStringEqualsXmlFile(
65 __DIR__ . '/../Fixtures/XmlExports/' . $this->databasePlatform . '/impexp-group-file-and-file_reference-item.xml',
66 $out
67 );
68 }
69
70 /**
71 * @test
72 */
73 public function exportGroupFileAndFileReferenceItemButImagesNotIncluded()
74 {
75 $subject = GeneralUtility::makeInstance(Export::class);
76 $subject->init();
77
78 $subject->setSaveFilesOutsideExportFile(true);
79
80 $this->compileExportGroupFileAndFileReferenceItem($subject);
81
82 $out = $subject->compileMemoryToFileContent('xml');
83
84 $this->assertXmlStringEqualsXmlFile(
85 __DIR__ . '/../Fixtures/XmlExports/' . $this->databasePlatform . '/impexp-group-file-and-file_reference-item-but-images-not-included.xml',
86 $out
87 );
88
89 $temporaryFilesDirectory = $subject->getTemporaryFilesPathForExport();
90 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/uploads/tx_impexpgroupfiles/typo3_image4.jpg', $temporaryFilesDirectory . 'e1c5c4e1e34e19e2facb438752e06c3f');
91 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image5.jpg', $temporaryFilesDirectory . 'c3511df85d21bc578faf71c6a19eeb3ff44af370');
92 }
93
94 /**
95 * Add default set of records to export
96 *
97 * @param $subject Export
98 */
99 protected function compileExportGroupFileAndFileReferenceItem(Export $subject)
100 {
101 $subject->setRecordTypesIncludeFields(
102 [
103 'pages' => [
104 'title',
105 'deleted',
106 'doktype',
107 'hidden',
108 'perms_everybody'
109 ],
110 'sys_file' => [
111 'storage',
112 'type',
113 'metadata',
114 'extension',
115 'identifier',
116 'identifier_hash',
117 'folder_hash',
118 'mime_type',
119 'name',
120 'sha1',
121 'size',
122 'creation_date',
123 'modification_date',
124 ],
125 'sys_file_storage' => [
126 'name',
127 'description',
128 'driver',
129 'configuration',
130 'is_default',
131 'is_browsable',
132 'is_public',
133 'is_writable',
134 'is_online'
135 ],
136 'tx_impexpgroupfiles_item' => [
137 'title',
138 'deleted',
139 'hidden',
140 'images',
141 'image_references'
142 ],
143
144 ]
145 );
146
147 $subject->relOnlyTables = [
148 'sys_file',
149 'sys_file_storage'
150 ];
151
152 $subject->export_addRecord('pages', BackendUtility::getRecord('pages', 1));
153 $subject->export_addRecord('tx_impexpgroupfiles_item', BackendUtility::getRecord('tx_impexpgroupfiles_item', 1));
154
155 $this->setPageTree($subject, 1, 0);
156
157 // After adding ALL records we set relations:
158 for ($a = 0; $a < 10; $a++) {
159 $addR = $subject->export_addDBRelations($a);
160 if (empty($addR)) {
161 break;
162 }
163 }
164
165 // hacky, but the timestamp will change on every clone, so set the file
166 // modification timestamp to the asserted value
167 $success = @touch(PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg', 1393866824);
168 if (!$success) {
169 $this->markTestSkipped('Could not set file modification timestamp for a fixture binary file. This is required for running the test successful.');
170 }
171
172 $subject->export_addFilesFromRelations();
173 $subject->export_addFilesFromSysFilesRecords();
174 }
175 }