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