2 namespace TYPO3\CMS\Core\Tests
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
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\Core\Database\ConnectionPool
;
23 use TYPO3\CMS\Core\Utility\GeneralUtility
;
24 use TYPO3\CMS\Styleguide\TcaDataGenerator\Generator
;
27 * This codeception extension creates a full TYPO3 instance within
28 * typo3temp. Own acceptance test suites may extend from this class
29 * and change the properties. This can be used to not copy the whole
30 * bootstrapTypo3Environment() method but reuse it instead.
32 class AcceptanceCoreEnvironment
extends Extension
36 * Additional core extensions to load.
38 * To be used in own acceptance test suites.
40 * If a test suite needs additional core extensions, for instance as a dependency of
41 * an extension that is tested, those core extension names can be noted here and will
46 protected $coreExtensionsToLoad = [];
49 * Array of test/fixture extensions paths that should be loaded for a test.
51 * To be used in own acceptance test suites.
53 * Given path is expected to be relative to your document root, example:
56 * 'typo3conf/ext/some_extension/Tests/Functional/Fixtures/Extensions/test_extension',
57 * 'typo3conf/ext/base_extension',
60 * Extensions in this array are linked to the test instance, loaded
61 * and their ext_tables.sql will be applied.
65 protected $testExtensionsToLoad = [];
68 * Array of test/fixture folder or file paths that should be linked for a test.
70 * To be used in own acceptance test suites.
73 * 'link-source' => 'link-destination'
76 * Given paths are expected to be relative to the test instance root.
77 * The array keys are the source paths and the array values are the destination
81 * 'typo3/sysext/impext/Tests/Functional/Fixtures/Folders/fileadmin/user_upload' =>
82 * 'fileadmin/user_upload',
83 * 'typo3conf/ext/my_own_ext/Tests/Functional/Fixtures/Folders/uploads/tx_myownext' =>
84 * 'uploads/tx_myownext'
87 * To be able to link from my_own_ext the extension path needs also to be registered in
88 * property $testExtensionsToLoad
92 protected $pathsToLinkInTestInstance = [];
95 * This configuration array is merged with TYPO3_CONF_VARS
96 * that are set in default configuration and factory configuration
98 * To be used in own acceptance test suites.
102 protected $configurationToUseInTestInstance = [];
105 * Array of folders that should be created inside the test instance document root.
107 * To be used in own acceptance test suites.
109 * Per default the following folder are created
116 * To create additional folders add the paths to this array. Given paths are expected to be
117 * relative to the test instance root and have to begin with a slash. Example:
120 * 'fileadmin/user_upload'
125 protected $additionalFoldersToCreate = [];
128 * XML database fixtures to be loaded into database.
130 * Given paths are expected to be relative to your document root.
134 protected $xmlDatabaseFixtures = [
135 'typo3/sysext/core/Tests/Acceptance/Fixtures/be_users.xml',
136 'typo3/sysext/core/Tests/Acceptance/Fixtures/be_sessions.xml',
137 'typo3/sysext/core/Tests/Acceptance/Fixtures/be_groups.xml',
141 * Events to listen to
143 public static $events = [
144 Events
::SUITE_BEFORE
=> 'bootstrapTypo3Environment',
145 Events
::TEST_AFTER
=> 'cleanupTypo3Environment'
149 * Handle SUITE_BEFORE event.
151 * Create a full standalone TYPO3 instance within typo3temp/var/tests/acceptance,
152 * create a database and create database schema.
154 * @param SuiteEvent $suiteEvent
157 public function bootstrapTypo3Environment(SuiteEvent
$suiteEvent)
159 $testbase = new Testbase();
160 $testbase->enableDisplayErrors();
161 $testbase->defineBaseConstants();
162 $testbase->defineOriginalRootPath();
163 $testbase->createDirectory(ORIGINAL_ROOT
. 'typo3temp/var/tests/acceptance');
164 $testbase->createDirectory(ORIGINAL_ROOT
. 'typo3temp/var/transient');
166 $instancePath = ORIGINAL_ROOT
. 'typo3temp/var/tests/acceptance';
168 $testbase->defineTypo3ModeBe();
169 $testbase->setTypo3TestingContext();
170 $testbase->removeOldInstanceIfExists($instancePath);
171 // Basic instance directory structure
172 $testbase->createDirectory($instancePath . '/fileadmin');
173 $testbase->createDirectory($instancePath . '/typo3temp/var/transient');
174 $testbase->createDirectory($instancePath . '/typo3temp/assets');
175 $testbase->createDirectory($instancePath . '/typo3conf/ext');
176 $testbase->createDirectory($instancePath . '/uploads');
177 // Additionally requested directories
178 foreach ($this->additionalFoldersToCreate
as $directory) {
179 $testbase->createDirectory($instancePath . '/' . $directory);
181 $testbase->createLastRunTextfile($instancePath);
182 $testbase->setUpInstanceCoreLinks($instancePath);
183 // ext:styleguide is always loaded
184 $testExtensionsToLoad = array_merge(
185 [ 'typo3conf/ext/styleguide' ],
186 $this->testExtensionsToLoad
188 $testbase->linkTestExtensionsToInstance($instancePath, $testExtensionsToLoad);
189 $testbase->linkPathsInTestInstance($instancePath, $this->pathsToLinkInTestInstance
);
190 $localConfiguration = $testbase->getOriginalDatabaseSettingsFromEnvironmentOrLocalConfiguration();
191 $originalDatabaseName = $localConfiguration['DB']['Connections']['Default']['dbname'];
192 // Append the unique identifier to the base database name to end up with a single database per test case
193 $localConfiguration['DB']['Connections']['Default']['dbname'] = $originalDatabaseName . '_at';
194 $testbase->testDatabaseNameIsNotTooLong($originalDatabaseName, $localConfiguration);
195 // Set some hard coded base settings for the instance. Those could be overruled by
196 // $this->configurationToUseInTestInstance if needed again.
197 $localConfiguration['BE']['debug'] = true;
198 $localConfiguration['BE']['lockHashKeyWords'] = '';
199 $localConfiguration['BE']['installToolPassword'] = '$P$notnotnotnotnotnot.validvalidva';
200 $localConfiguration['SYS']['isInitialInstallationInProgress'] = false;
201 $localConfiguration['SYS']['isInitialDatabaseImportDone'] = true;
202 $localConfiguration['SYS']['displayErrors'] = false;
203 $localConfiguration['SYS']['debugExceptionHandler'] = '';
204 $localConfiguration['SYS']['trustedHostsPattern'] = 'localhost:8000';
205 $localConfiguration['SYS']['encryptionKey'] = 'iAmInvalid';
206 // @todo: This sql_mode should be enabled as soon as styleguide and dataHandler can cope with it
207 //$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\';';
208 $localConfiguration['SYS']['caching']['cacheConfigurations']['extbase_object']['backend'] = NullBackend
::class;
209 $testbase->setUpLocalConfiguration($instancePath, $localConfiguration, $this->configurationToUseInTestInstance
);
210 $defaultCoreExtensionsToLoad = [
230 $testbase->setUpPackageStates($instancePath, $defaultCoreExtensionsToLoad, $this->coreExtensionsToLoad
, $testExtensionsToLoad);
231 $testbase->setUpBasicTypo3Bootstrap($instancePath);
232 $testbase->setUpTestDatabase($localConfiguration['DB']['Connections']['Default']['dbname'], $originalDatabaseName);
233 $testbase->loadExtensionTables();
234 $testbase->createDatabaseStructure();
236 // Unset a closure or phpunit kicks in with a 'serialization of \Closure is not allowed'
237 // Alternative solution:
238 // unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys']['extbase']);
239 $suite = $suiteEvent->getSuite();
240 $suite->setBackupGlobals(false);
242 foreach ($this->xmlDatabaseFixtures
as $fixture) {
243 $testbase->importXmlDatabaseFixture(ORIGINAL_ROOT
. $fixture);
246 // styleguide generator uses DataHandler for some parts. DataHandler needs an initialized BE user
247 // with admin right and the live workspace.
248 Bootstrap
::getInstance()->initializeBackendUser();
249 $GLOBALS['BE_USER']->user
['admin'] = 1;
250 $GLOBALS['BE_USER']->user
['uid'] = 1;
251 $GLOBALS['BE_USER']->workspace
= 0;
252 Bootstrap
::getInstance()->initializeLanguageObject();
254 $styleguideGenerator = new Generator();
255 $styleguideGenerator->create();
259 * Method executed after each test
263 public function cleanupTypo3Environment()
265 // Reset uc db field of be_user "admin" to null to reduce
266 // possible side effects between single tests.
267 GeneralUtility
::makeInstance(ConnectionPool
::class)
268 ->getConnectionForTable('be_users')
269 ->update('be_users', ['uc' => null], ['uid' => 1]);