TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
AcceptanceCoreEnvironment.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Core\Tests;
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use Codeception\Event\SuiteEvent;
19 use Codeception\Events;
20 use Codeception\Extension;
25 use TYPO3\CMS\Styleguide\TcaDataGenerator\Generator;
26 
33 class AcceptanceCoreEnvironment extends Extension
34 {
46  protected $coreExtensionsToLoad = [];
47 
65  protected $testExtensionsToLoad = [];
66 
93 
103 
126 
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',
138  'typo3/sysext/core/Tests/Acceptance/Fixtures/sys_category.xml',
139  'typo3/sysext/core/Tests/Acceptance/Fixtures/tx_extensionmanager_domain_model_extension.xml',
140  'typo3/sysext/core/Tests/Acceptance/Fixtures/tx_extensionmanager_domain_model_repository.xml',
141  ];
142 
146  public static $events = [
147  Events::SUITE_BEFORE => 'bootstrapTypo3Environment',
148  Events::TEST_AFTER => 'cleanupTypo3Environment'
149  ];
150 
160  public function bootstrapTypo3Environment(SuiteEvent $suiteEvent)
161  {
162  $testbase = new Testbase();
163  $testbase->enableDisplayErrors();
164  $testbase->defineBaseConstants();
165  $testbase->defineOriginalRootPath();
166  $testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/tests/acceptance');
167  $testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/transient');
168 
169  $instancePath = ORIGINAL_ROOT . 'typo3temp/var/tests/acceptance';
170 
171  $testbase->defineTypo3ModeBe();
172  $testbase->setTypo3TestingContext();
173  $testbase->removeOldInstanceIfExists($instancePath);
174  // Basic instance directory structure
175  $testbase->createDirectory($instancePath . '/fileadmin');
176  $testbase->createDirectory($instancePath . '/typo3temp/var/transient');
177  $testbase->createDirectory($instancePath . '/typo3temp/assets');
178  $testbase->createDirectory($instancePath . '/typo3conf/ext');
179  $testbase->createDirectory($instancePath . '/uploads');
180  // Additionally requested directories
181  foreach ($this->additionalFoldersToCreate as $directory) {
182  $testbase->createDirectory($instancePath . '/' . $directory);
183  }
184  $testbase->createLastRunTextfile($instancePath);
185  $testbase->setUpInstanceCoreLinks($instancePath);
186  // ext:styleguide is always loaded
187  $testExtensionsToLoad = array_merge(
188  [ 'typo3conf/ext/styleguide' ],
189  $this->testExtensionsToLoad
190  );
191  $testbase->linkTestExtensionsToInstance($instancePath, $testExtensionsToLoad);
192  $testbase->linkPathsInTestInstance($instancePath, $this->pathsToLinkInTestInstance);
193  $localConfiguration['DB'] = $testbase->getOriginalDatabaseSettingsFromEnvironmentOrLocalConfiguration();
194  $originalDatabaseName = $localConfiguration['DB']['Connections']['Default']['dbname'];
195  // Append the unique identifier to the base database name to end up with a single database per test case
196  $localConfiguration['DB']['Connections']['Default']['dbname'] = $originalDatabaseName . '_at';
197  $testbase->testDatabaseNameIsNotTooLong($originalDatabaseName, $localConfiguration);
198  // Set some hard coded base settings for the instance. Those could be overruled by
199  // $this->configurationToUseInTestInstance if needed again.
200  $localConfiguration['BE']['debug'] = true;
201  $localConfiguration['BE']['lockHashKeyWords'] = '';
202  $localConfiguration['BE']['installToolPassword'] = $this->getInstallToolPassword();
203  $localConfiguration['BE']['loginSecurityLevel'] = 'rsa';
204  $localConfiguration['SYS']['isInitialInstallationInProgress'] = false;
205  $localConfiguration['SYS']['isInitialDatabaseImportDone'] = true;
206  $localConfiguration['SYS']['displayErrors'] = false;
207  $localConfiguration['SYS']['debugExceptionHandler'] = '';
208  $localConfiguration['SYS']['trustedHostsPattern'] = 'localhost:8000';
209  $localConfiguration['SYS']['encryptionKey'] = 'iAmInvalid';
210  // @todo: This sql_mode should be enabled as soon as styleguide and dataHandler can cope with it
211  //$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\';';
212  $localConfiguration['SYS']['caching']['cacheConfigurations']['extbase_object']['backend'] = NullBackend::class;
213  $testbase->setUpLocalConfiguration($instancePath, $localConfiguration, $this->configurationToUseInTestInstance);
214  $defaultCoreExtensionsToLoad = [
215  'core',
216  'beuser',
217  'extbase',
218  'fluid',
219  'filelist',
220  'extensionmanager',
221  'lang',
222  'setup',
223  'rsaauth',
224  'saltedpasswords',
225  'backend',
226  'about',
227  'belog',
228  'install',
229  't3skin',
230  'frontend',
231  'recordlist',
232  'reports',
233  'sv',
234  'scheduler',
235  'tstemplate',
236  ];
237  $testbase->setUpPackageStates($instancePath, $defaultCoreExtensionsToLoad, $this->coreExtensionsToLoad, $testExtensionsToLoad);
238  $testbase->setUpBasicTypo3Bootstrap($instancePath);
239  $testbase->setUpTestDatabase($localConfiguration['DB']['Connections']['Default']['dbname'], $originalDatabaseName);
240  $testbase->loadExtensionTables();
241  $testbase->createDatabaseStructure();
242 
243  // Unset a closure or phpunit kicks in with a 'serialization of \Closure is not allowed'
244  // Alternative solution:
245  // unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys']['extbase']);
246  $suite = $suiteEvent->getSuite();
247  $suite->setBackupGlobals(false);
248 
249  foreach ($this->xmlDatabaseFixtures as $fixture) {
250  $testbase->importXmlDatabaseFixture(ORIGINAL_ROOT . $fixture);
251  }
252 
253  // styleguide generator uses DataHandler for some parts. DataHandler needs an initialized BE user
254  // with admin right and the live workspace.
255  Bootstrap::getInstance()->initializeBackendUser();
256  $GLOBALS['BE_USER']->user['admin'] = 1;
257  $GLOBALS['BE_USER']->user['uid'] = 1;
258  $GLOBALS['BE_USER']->workspace = 0;
259  Bootstrap::getInstance()->initializeLanguageObject();
260 
261  $styleguideGenerator = new Generator();
262  $styleguideGenerator->create();
263 
264  // @todo: Find out why that is needed to execute the first test successfully
265  $this->cleanupTypo3Environment();
266  }
267 
273  public function cleanupTypo3Environment()
274  {
275  // Reset uc db field of be_user "admin" to null to reduce
276  // possible side effects between single tests.
277  GeneralUtility::makeInstance(ConnectionPool::class)
278  ->getConnectionForTable('be_users')
279  ->update('be_users', ['uc' => null], ['uid' => 1]);
280  }
281 
289  protected function getInstallToolPassword(): string
290  {
291  $password = getenv('typo3InstallToolPassword');
292  if (!empty($password)) {
294  return $saltFactory->getHashedPassword($password);
295  } else {
296  return '$P$notnotnotnotnotnot.validvalidva';
297  }
298  }
299 }
static getSaltingInstance($saltedHash= '', $mode=TYPO3_MODE)
Definition: SaltFactory.php:83
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)