[BUGFIX] Add filelist extension to factory default
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / AcceptanceCoreEnvironment.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests;
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 Codeception\Event\SuiteEvent;
18 use Codeception\Events;
19 use Codeception\Extension;
20 use TYPO3\CMS\Core\Cache\Backend\NullBackend;
21 use TYPO3\CMS\Core\Core\Bootstrap;
22 use TYPO3\CMS\Styleguide\TcaDataGenerator\Generator;
23
24 /**
25 * This codeception extension creates a full TYPO3 instance within
26 * typo3temp. Own acceptance test suites may extend from this class
27 * and change the properties. This can be used to not copy the whole
28 * bootstrapTypo3Environment() method but reuse it instead.
29 */
30 class AcceptanceCoreEnvironment extends Extension
31 {
32
33 /**
34 * Additional core extensions to load.
35 *
36 * To be used in own acceptance test suites.
37 *
38 * If a test suite needs additional core extensions, for instance as a dependency of
39 * an extension that is tested, those core extension names can be noted here and will
40 * be loaded.
41 *
42 * @var array
43 */
44 protected $coreExtensionsToLoad = [];
45
46 /**
47 * Array of test/fixture extensions paths that should be loaded for a test.
48 *
49 * To be used in own acceptance test suites.
50 *
51 * Given path is expected to be relative to your document root, example:
52 *
53 * array(
54 * 'typo3conf/ext/some_extension/Tests/Functional/Fixtures/Extensions/test_extension',
55 * 'typo3conf/ext/base_extension',
56 * );
57 *
58 * Extensions in this array are linked to the test instance, loaded
59 * and their ext_tables.sql will be applied.
60 *
61 * @var array
62 */
63 protected $testExtensionsToLoad = [];
64
65 /**
66 * Array of test/fixture folder or file paths that should be linked for a test.
67 *
68 * To be used in own acceptance test suites.
69 *
70 * array(
71 * 'link-source' => 'link-destination'
72 * );
73 *
74 * Given paths are expected to be relative to the test instance root.
75 * The array keys are the source paths and the array values are the destination
76 * paths, example:
77 *
78 * array(
79 * 'typo3/sysext/impext/Tests/Functional/Fixtures/Folders/fileadmin/user_upload' =>
80 * 'fileadmin/user_upload',
81 * 'typo3conf/ext/my_own_ext/Tests/Functional/Fixtures/Folders/uploads/tx_myownext' =>
82 * 'uploads/tx_myownext'
83 * );
84 *
85 * To be able to link from my_own_ext the extension path needs also to be registered in
86 * property $testExtensionsToLoad
87 *
88 * @var array
89 */
90 protected $pathsToLinkInTestInstance = [];
91
92 /**
93 * This configuration array is merged with TYPO3_CONF_VARS
94 * that are set in default configuration and factory configuration
95 *
96 * To be used in own acceptance test suites.
97 *
98 * @var array
99 */
100 protected $configurationToUseInTestInstance = [];
101
102 /**
103 * Array of folders that should be created inside the test instance document root.
104 *
105 * To be used in own acceptance test suites.
106 *
107 * Per default the following folder are created
108 * /fileadmin
109 * /typo3temp
110 * /typo3conf
111 * /typo3conf/ext
112 * /uploads
113 *
114 * To create additional folders add the paths to this array. Given paths are expected to be
115 * relative to the test instance root and have to begin with a slash. Example:
116 *
117 * array(
118 * 'fileadmin/user_upload'
119 * );
120 *
121 * @var array
122 */
123 protected $additionalFoldersToCreate = [];
124
125 /**
126 * XML database fixtures to be loaded into database.
127 *
128 * Given paths are expected to be relative to your document root.
129 *
130 * @var array
131 */
132 protected $xmlDatabaseFixtures = [
133 'typo3/sysext/core/Tests/Acceptance/Fixtures/be_users.xml',
134 'typo3/sysext/core/Tests/Acceptance/Fixtures/be_sessions.xml',
135 'typo3/sysext/core/Tests/Acceptance/Fixtures/be_groups.xml',
136 ];
137
138 /**
139 * Events to listen to
140 */
141 public static $events = [
142 Events::SUITE_BEFORE => 'bootstrapTypo3Environment',
143 ];
144
145 /**
146 * Handle SUITE_BEFORE event.
147 *
148 * Create a full standalone TYPO3 instance within typo3temp/var/tests/acceptance,
149 * create a database and create database schema.
150 *
151 * @param SuiteEvent $suiteEvent
152 * @throws Exception
153 */
154 public function bootstrapTypo3Environment(SuiteEvent $suiteEvent)
155 {
156 $testbase = new Testbase();
157 $testbase->enableDisplayErrors();
158 $testbase->defineBaseConstants();
159 $testbase->defineOriginalRootPath();
160 $testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/tests/acceptance');
161 $testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/transient');
162
163 $instancePath = ORIGINAL_ROOT . 'typo3temp/var/tests/acceptance';
164
165 $testbase->defineTypo3ModeBe();
166 $testbase->setTypo3TestingContext();
167 $testbase->removeOldInstanceIfExists($instancePath);
168 // Basic instance directory structure
169 $testbase->createDirectory($instancePath . '/fileadmin');
170 $testbase->createDirectory($instancePath . '/typo3temp/var/transient');
171 $testbase->createDirectory($instancePath . '/typo3temp/assets');
172 $testbase->createDirectory($instancePath . '/typo3conf/ext');
173 $testbase->createDirectory($instancePath . '/uploads');
174 // Additionally requested directories
175 foreach ($this->additionalFoldersToCreate as $directory) {
176 $testbase->createDirectory($instancePath . '/' . $directory);
177 }
178 $testbase->createLastRunTextfile($instancePath);
179 $testbase->setUpInstanceCoreLinks($instancePath);
180 // ext:styleguide is always loaded
181 $testExtensionsToLoad = array_merge(
182 [ 'typo3conf/ext/styleguide' ],
183 $this->testExtensionsToLoad
184 );
185 $testbase->linkTestExtensionsToInstance($instancePath, $testExtensionsToLoad);
186 $testbase->linkPathsInTestInstance($instancePath, $this->pathsToLinkInTestInstance);
187 $localConfiguration = $testbase->getOriginalDatabaseSettingsFromEnvironmentOrLocalConfiguration();
188 $originalDatabaseName = $localConfiguration['DB']['Connections']['Default']['dbname'];
189 // Append the unique identifier to the base database name to end up with a single database per test case
190 $localConfiguration['DB']['Connections']['Default']['dbname'] = $originalDatabaseName . '_at';
191 $testbase->testDatabaseNameIsNotTooLong($originalDatabaseName, $localConfiguration);
192 // Set some hard coded base settings for the instance. Those could be overruled by
193 // $this->configurationToUseInTestInstance if needed again.
194 $localConfiguration['BE']['debug'] = true;
195 $localConfiguration['BE']['lockHashKeyWords'] = '';
196 $localConfiguration['BE']['installToolPassword'] = '$P$notnotnotnotnotnot.validvalidva';
197 $localConfiguration['SYS']['isInitialInstallationInProgress'] = false;
198 $localConfiguration['SYS']['isInitialDatabaseImportDone'] = true;
199 $localConfiguration['SYS']['displayErrors'] = false;
200 $localConfiguration['SYS']['debugExceptionHandler'] = '';
201 $localConfiguration['SYS']['trustedHostsPattern'] = 'localhost:8000';
202 $localConfiguration['SYS']['encryptionKey'] = 'iAmInvalid';
203 // @todo: This sql_mode should be enabled as soon as styleguide and dataHandler can cope with it
204 //$localConfiguration['SYS']['setDBinit'] = 'SET SESSION sql_mode = \'STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY\';';
205 $localConfiguration['SYS']['caching']['cacheConfigurations']['extbase_object']['backend'] = NullBackend::class;
206 $testbase->setUpLocalConfiguration($instancePath, $localConfiguration, $this->configurationToUseInTestInstance);
207 $defaultCoreExtensionsToLoad = [
208 'core',
209 'extbase',
210 'fluid',
211 'filelist',
212 'extensionmanager',
213 'lang',
214 'setup',
215 'rsaauth',
216 'saltedpasswords',
217 'backend',
218 'belog',
219 'install',
220 't3skin',
221 'frontend',
222 'recordlist',
223 'reports',
224 'sv',
225 'scheduler'
226 ];
227 $testbase->setUpPackageStates($instancePath, $defaultCoreExtensionsToLoad, $this->coreExtensionsToLoad, $testExtensionsToLoad);
228 $testbase->setUpBasicTypo3Bootstrap($instancePath);
229 $testbase->setUpTestDatabase($localConfiguration['DB']['Connections']['Default']['dbname'], $originalDatabaseName);
230 $testbase->loadExtensionTables();
231 $testbase->createDatabaseStructure();
232
233 // Unset a closure or phpunit kicks in with a 'serialization of \Closure is not allowed'
234 // Alternative solution:
235 // unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys']['extbase']);
236 $suite = $suiteEvent->getSuite();
237 $suite->setBackupGlobals(false);
238
239 foreach ($this->xmlDatabaseFixtures as $fixture) {
240 $testbase->importXmlDatabaseFixture(ORIGINAL_ROOT . $fixture);
241 }
242
243 // styleguide generator uses DataHandler for some parts. DataHandler needs an initialized BE user
244 // with admin right and the live workspace.
245 Bootstrap::getInstance()->initializeBackendUser();
246 $GLOBALS['BE_USER']->user['admin'] = 1;
247 $GLOBALS['BE_USER']->user['uid'] = 1;
248 $GLOBALS['BE_USER']->workspace = 0;
249 Bootstrap::getInstance()->initializeLanguageObject();
250
251 $styleguideGenerator = new Generator();
252 $styleguideGenerator->create();
253 }
254 }