[TASK] Use Environment API instead of PATH_site in impexp
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Tests / Functional / Export / GroupFileAndFileReferenceItemInFlexFormTest.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 GroupFileAndFileReferenceItemInFlexFormTest 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 $subject->setRecordTypesIncludeFields(
62 [
63 'pages' => [
64 'title',
65 'deleted',
66 'doktype',
67 'hidden',
68 'perms_everybody'
69 ],
70 'sys_file' => [
71 'storage',
72 'type',
73 'metadata',
74 'extension',
75 'identifier',
76 'identifier_hash',
77 'folder_hash',
78 'mime_type',
79 'name',
80 'sha1',
81 'size',
82 'creation_date',
83 'modification_date',
84 ],
85 'sys_file_storage' => [
86 'name',
87 'description',
88 'driver',
89 'configuration',
90 'is_default',
91 'is_browsable',
92 'is_public',
93 'is_writable',
94 'is_online'
95 ],
96 'tx_impexpgroupfiles_item' => [
97 'title',
98 'deleted',
99 'hidden',
100 'images',
101 'image_references',
102 'flexform'
103 ],
104
105 ]
106 );
107
108 $subject->relOnlyTables = [
109 'sys_file',
110 'sys_file_storage'
111 ];
112
113 // @todo: Do not rely on BackendUtility::getRecord() in the test case itself
114 $subject->export_addRecord('pages', $this->forceStringsOnRowValues(BackendUtility::getRecord('pages', 2)));
115 $subject->export_addRecord('tx_impexpgroupfiles_item', $this->forceStringsOnRowValues(BackendUtility::getRecord('tx_impexpgroupfiles_item', 2)));
116
117 $this->setPageTree($subject, 2, 0);
118
119 // After adding ALL records we set relations:
120 for ($a = 0; $a < 10; $a++) {
121 $addR = $subject->export_addDBRelations($a);
122 if (empty($addR)) {
123 break;
124 }
125 }
126
127 // Hacky, but the timestamp will change on every clone, so set the file modification timestamp to the asserted value
128 $success = touch(Environment::getPublicPath() . '/uploads/tx_impexpgroupfiles/typo3_image4.jpg', 1393866824);
129 // Early fail if touching failed - indicates a broken functional test setup
130 $this->assertTrue($success, 'Could not set file modification timestamp for a fixture binary file.');
131
132 $subject->export_addFilesFromRelations();
133 $subject->export_addFilesFromSysFilesRecords();
134
135 $out = $subject->compileMemoryToFileContent('xml');
136
137 $this->assertXmlStringEqualsXmlFile(
138 __DIR__ . '/../Fixtures/XmlExports/impexp-group-file-and-file_reference-item-in-ff.xml',
139 $out
140 );
141 }
142 }