7e4722a3b14678f3703bf5599ee3776406a4c1fc
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Tests / Functional / Import / GroupFileAndFileReferenceItemTest.php
1 <?php
2 namespace TYPO3\CMS\Impexp\Tests\Functional\Import;
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\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Impexp\Import;
19 use TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase;
20
21 /**
22 * Test case
23 */
24 class GroupFileAndFileReferenceItemTest extends AbstractImportExportTestCase
25 {
26 /**
27 * @var array
28 */
29 protected $additionalFoldersToCreate = [
30 '/uploads/tx_impexpgroupfiles'
31 ];
32
33 /**
34 * @var array
35 */
36 protected $testExtensionsToLoad = [
37 'typo3/sysext/impexp/Tests/Functional/Fixtures/Extensions/impexp_group_files'
38 ];
39
40 /**
41 * @test
42 */
43 public function importGroupFileAndFileReferenceItem()
44 {
45 $subject = GeneralUtility::makeInstance(Import::class);
46 $subject->init();
47
48 $subject->loadFile(
49 __DIR__ . '/../Fixtures/XmlImports/impexp-group-file-and-file_reference-item.xml',
50 1
51 );
52 $subject->importData(0);
53
54 $this->testFilesToDelete[] = PATH_site . 'fileadmin/user_upload/typo3_image5.jpg';
55 $this->testFilesToDelete[] = PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg';
56
57 $this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importGroupFileAndFileReferenceItem.csv');
58
59 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image5.jpg', PATH_site . 'fileadmin/user_upload/typo3_image5.jpg');
60 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/uploads/tx_impexpgroupfiles/typo3_image4.jpg', PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg');
61 }
62
63 /**
64 * @test
65 */
66 public function importGroupFileAndFileReferenceItemWithRootLevelOnlyAllowed()
67 {
68 $GLOBALS['TCA']['tx_impexpgroupfiles_item']['ctrl']['rootLevel'] = 1;
69
70 $subject = GeneralUtility::makeInstance(Import::class);
71 $subject->init();
72
73 $subject->loadFile(
74 __DIR__ . '/../Fixtures/XmlImports/impexp-group-file-and-file_reference-item.xml',
75 1
76 );
77 $subject->importData(0);
78
79 $this->testFilesToDelete[] = PATH_site . 'fileadmin/user_upload/typo3_image5.jpg';
80 $this->testFilesToDelete[] = PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg';
81
82 $this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importGroupFileAndFileReferenceItemWithRootLevelOnlyAllowed.csv');
83
84 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image5.jpg', PATH_site . 'fileadmin/user_upload/typo3_image5.jpg');
85 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/uploads/tx_impexpgroupfiles/typo3_image4.jpg', PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg');
86 }
87
88 /**
89 * @test
90 */
91 public function importGroupFileAndFileReferenceItemWithRootLevelNotAllowed()
92 {
93 $GLOBALS['TCA']['tx_impexpgroupfiles_item']['ctrl']['rootLevel'] = 0;
94
95 $subject = GeneralUtility::makeInstance(Import::class);
96 $subject->init();
97
98 $subject->loadFile(
99 __DIR__ . '/../Fixtures/XmlImports/impexp-group-file-and-file_reference-item-on-pid-zero.xml',
100 1
101 );
102 $subject->importData(0);
103
104 $this->testFilesToDelete[] = PATH_site . 'fileadmin/user_upload/typo3_image5.jpg';
105
106 $this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importGroupFileAndFileReferenceItemWithRootLevelNotAllowed.csv');
107
108 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image5.jpg', PATH_site . 'fileadmin/user_upload/typo3_image5.jpg');
109 $this->assertFileNotExists(PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg');
110
111 $expectedErrors = [
112 'Error: Record type tx_impexpgroupfiles_item is not allowed on pid 0'
113 ];
114 $errors = $subject->errorLog;
115 $this->assertSame($expectedErrors, $errors);
116 }
117
118 /**
119 * @test
120 */
121 public function importGroupFileAndFileReferenceItemWithRootLevelAndPagesAllowed()
122 {
123 $GLOBALS['TCA']['tx_impexpgroupfiles_item']['ctrl']['rootLevel'] = -1;
124
125 $subject = GeneralUtility::makeInstance(Import::class);
126 $subject->init();
127
128 $subject->loadFile(
129 __DIR__ . '/../Fixtures/XmlImports/impexp-group-file-and-file_reference-item.xml',
130 1
131 );
132 $subject->importData(0);
133
134 $this->testFilesToDelete[] = PATH_site . 'fileadmin/user_upload/typo3_image5.jpg';
135 $this->testFilesToDelete[] = PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg';
136
137 $this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importGroupFileAndFileReferenceItemWithRootLevelAndPagesAllowed.csv');
138
139 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image5.jpg', PATH_site . 'fileadmin/user_upload/typo3_image5.jpg');
140 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/uploads/tx_impexpgroupfiles/typo3_image4.jpg', PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg');
141 }
142
143 /**
144 * @test
145 */
146 public function importGroupFileAndFileReferenceItemButImagesNotIncluded()
147 {
148 $subject = GeneralUtility::makeInstance(Import::class);
149 $subject->init();
150
151 $subject->loadFile(
152 __DIR__ . '/../Fixtures/XmlImports/impexp-group-file-and-file_reference-item.xml',
153 1
154 );
155 $subject->importData(0);
156
157 $this->testFilesToDelete[] = PATH_site . 'fileadmin/user_upload/typo3_image5.jpg';
158 $this->testFilesToDelete[] = PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg';
159
160 $this->assertCSVDataSet('EXT:impexp/Tests/Functional/Fixtures/DatabaseAssertions/importGroupFileAndFileReferenceItem.csv');
161
162 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/fileadmin/user_upload/typo3_image5.jpg', PATH_site . 'fileadmin/user_upload/typo3_image5.jpg');
163 $this->assertFileEquals(__DIR__ . '/../Fixtures/Folders/uploads/tx_impexpgroupfiles/typo3_image4.jpg', PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg');
164 }
165 }