[BUGFIX] Fix wrong enforcement of pid 0 for rootLevel = -1 in impexp
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Tests / Functional / Import / GroupFileAndFileReferenceItem / ImportInEmptyDatabaseTest.php
1 <?php
2 namespace TYPO3\CMS\Impexp\Tests\Functional\Import\GroupFileAndFileReferenceItem;
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 require_once __DIR__ . '/../AbstractImportTestCase.php';
18
19 /**
20 * Functional test for the ImportExport
21 */
22 class ImportInEmptyDatabaseTest extends \TYPO3\CMS\Impexp\Tests\Functional\Import\AbstractImportTestCase {
23
24 /**
25 * @var array
26 */
27 protected $additionalFoldersToCreate = array(
28 '/uploads/tx_impexpgroupfiles'
29 );
30
31 /**
32 * @var array
33 */
34 protected $testExtensionsToLoad = array(
35 'typo3/sysext/impexp/Tests/Functional/Fixtures/Extensions/impexp_group_files'
36 );
37
38 /**
39 * @var string
40 */
41 protected $assertionDataSetDirectory = 'typo3/sysext/impexp/Tests/Functional/Import/GroupFileAndFileReferenceItem/DataSet/Assertion/';
42
43 /**
44 * @test
45 */
46 public function importGroupFileAndFileReferenceItem() {
47
48 $this->import->loadFile(__DIR__ . '/../../Fixtures/ImportExportXml/impexp-group-file-and-file_reference-item.xml', 1);
49 $this->import->importData(0);
50
51 $this->testFilesToDelete[] = PATH_site . 'fileadmin/user_upload/typo3_image5.jpg';
52 $this->testFilesToDelete[] = PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg';
53
54 $this->assertAssertionDataSet('importGroupFileAndFileReferenceItem');
55
56 $this->assertFileEquals(__DIR__ . '/../../Fixtures/Folders/fileadmin/user_upload/typo3_image5.jpg', PATH_site . 'fileadmin/user_upload/typo3_image5.jpg');
57 $this->assertFileEquals(__DIR__ . '/../../Fixtures/Folders/uploads/tx_impexpgroupfiles/typo3_image4.jpg', PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg');
58 }
59
60 /**
61 * @test
62 */
63 public function importGroupFileAndFileReferenceItemWithRootLevelOnlyAllowed() {
64
65 $GLOBALS['TCA']['tx_impexpgroupfiles_item']['ctrl']['rootLevel'] = 1;
66
67 $this->import->loadFile(__DIR__ . '/../../Fixtures/ImportExportXml/impexp-group-file-and-file_reference-item.xml', 1);
68 $this->import->importData(0);
69
70 $this->testFilesToDelete[] = PATH_site . 'fileadmin/user_upload/typo3_image5.jpg';
71 $this->testFilesToDelete[] = PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg';
72
73 $this->assertAssertionDataSet('importGroupFileAndFileReferenceItemWithRootLevelOnlyAllowed');
74
75 $this->assertFileEquals(__DIR__ . '/../../Fixtures/Folders/fileadmin/user_upload/typo3_image5.jpg', PATH_site . 'fileadmin/user_upload/typo3_image5.jpg');
76 $this->assertFileEquals(__DIR__ . '/../../Fixtures/Folders/uploads/tx_impexpgroupfiles/typo3_image4.jpg', PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg');
77 }
78
79 /**
80 * @test
81 */
82 public function importGroupFileAndFileReferenceItemWithRootLevelNotAllowed() {
83
84 $GLOBALS['TCA']['tx_impexpgroupfiles_item']['ctrl']['rootLevel'] = 0;
85
86 $this->import->loadFile(__DIR__ . '/ImportExportXml/impexp-group-file-and-file_reference-item-on-pid-zero.xml', 1);
87 $this->import->importData(0);
88
89 $this->testFilesToDelete[] = PATH_site . 'fileadmin/user_upload/typo3_image5.jpg';
90
91 $this->assertAssertionDataSet('importGroupFileAndFileReferenceItemWithRootLevelNotAllowed');
92
93 $this->assertFileEquals(__DIR__ . '/../../Fixtures/Folders/fileadmin/user_upload/typo3_image5.jpg', PATH_site . 'fileadmin/user_upload/typo3_image5.jpg');
94 $this->assertFileNotExists(PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg');
95
96 $expectedErrors = array(
97 'Error: Record type tx_impexpgroupfiles_item is not allowed on pid 0'
98 );
99 $errors = $this->import->errorLog;
100 $this->assertSame($expectedErrors, $errors);
101 }
102
103 /**
104 * @test
105 */
106 public function importGroupFileAndFileReferenceItemWithRootLevelAndPagesAllowed() {
107
108 $GLOBALS['TCA']['tx_impexpgroupfiles_item']['ctrl']['rootLevel'] = -1;
109
110 $this->import->loadFile(__DIR__ . '/../../Fixtures/ImportExportXml/impexp-group-file-and-file_reference-item.xml', 1);
111 $this->import->importData(0);
112
113
114 $this->testFilesToDelete[] = PATH_site . 'fileadmin/user_upload/typo3_image5.jpg';
115 $this->testFilesToDelete[] = PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg';
116
117 $this->assertAssertionDataSet('importGroupFileAndFileReferenceItemWithRootLevelAndPagesAllowed');
118
119 $this->assertFileEquals(__DIR__ . '/../../Fixtures/Folders/fileadmin/user_upload/typo3_image5.jpg', PATH_site . 'fileadmin/user_upload/typo3_image5.jpg');
120 $this->assertFileEquals(__DIR__ . '/../../Fixtures/Folders/uploads/tx_impexpgroupfiles/typo3_image4.jpg', PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg');
121 }
122
123 /**
124 * @test
125 */
126 public function importGroupFileAndFileReferenceItemButImagesNotIncluded() {
127
128 $this->import->loadFile(PATH_site . 'typo3/sysext/impexp/Tests/Functional/Fixtures/ImportExportXml/impexp-group-file-and-file_reference-item-but-images-not-included.xml', 1);
129 $this->import->importData(0);
130
131 $this->testFilesToDelete[] = PATH_site . 'fileadmin/user_upload/typo3_image5.jpg';
132 $this->testFilesToDelete[] = PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg';
133
134 $this->assertAssertionDataSet('importGroupFileAndFileReferenceItem');
135
136 $this->assertFileEquals(__DIR__ . '/../../Fixtures/Folders/fileadmin/user_upload/typo3_image5.jpg', PATH_site . 'fileadmin/user_upload/typo3_image5.jpg');
137 $this->assertFileEquals(__DIR__ . '/../../Fixtures/Folders/uploads/tx_impexpgroupfiles/typo3_image4.jpg', PATH_site . 'uploads/tx_impexpgroupfiles/typo3_image4.jpg');
138 }
139
140 }