/**
  * Handle SUITE_BEFORE event.
  *
  * Create a full standalone TYPO3 instance within typo3temp/var/tests/acceptance,
  * create a database and create database schema.
  *
  * @param SuiteEvent $suiteEvent
  * @throws Exception
  */
 public function bootstrapTypo3Environment(SuiteEvent $suiteEvent)
 {
     $testbase = new Testbase();
     $testbase->enableDisplayErrors();
     $testbase->defineBaseConstants();
     $testbase->defineOriginalRootPath();
     $testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/tests/acceptance');
     $testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/transient');
     $instancePath = ORIGINAL_ROOT . 'typo3temp/var/tests/acceptance';
     $testbase->defineTypo3ModeBe();
     $testbase->setTypo3TestingContext();
     $testbase->removeOldInstanceIfExists($instancePath);
     // Basic instance directory structure
     $testbase->createDirectory($instancePath . '/fileadmin');
     $testbase->createDirectory($instancePath . '/typo3temp/var/transient');
     $testbase->createDirectory($instancePath . '/typo3temp/assets');
     $testbase->createDirectory($instancePath . '/typo3conf/ext');
     $testbase->createDirectory($instancePath . '/uploads');
     // Additionally requested directories
     foreach ($this->additionalFoldersToCreate as $directory) {
         $testbase->createDirectory($instancePath . '/' . $directory);
     }
     $testbase->createLastRunTextfile($instancePath);
     $testbase->setUpInstanceCoreLinks($instancePath);
     // ext:styleguide is always loaded
     $testExtensionsToLoad = array_merge(['typo3conf/ext/styleguide'], $this->testExtensionsToLoad);
     $testbase->linkTestExtensionsToInstance($instancePath, $testExtensionsToLoad);
     $testbase->linkPathsInTestInstance($instancePath, $this->pathsToLinkInTestInstance);
     $localConfiguration = $testbase->getOriginalDatabaseSettingsFromEnvironmentOrLocalConfiguration();
     $originalDatabaseName = $localConfiguration['DB']['Connections']['Default']['dbname'];
     // Append the unique identifier to the base database name to end up with a single database per test case
     $localConfiguration['DB']['Connections']['Default']['dbname'] = $originalDatabaseName . '_at';
     $testbase->testDatabaseNameIsNotTooLong($originalDatabaseName, $localConfiguration);
     // Set some hard coded base settings for the instance. Those could be overruled by
     // $this->configurationToUseInTestInstance if needed again.
     $localConfiguration['BE']['debug'] = true;
     $localConfiguration['BE']['lockHashKeyWords'] = '';
     $localConfiguration['BE']['installToolPassword'] = '******';
     $localConfiguration['SYS']['isInitialInstallationInProgress'] = false;
     $localConfiguration['SYS']['isInitialDatabaseImportDone'] = true;
     $localConfiguration['SYS']['displayErrors'] = false;
     $localConfiguration['SYS']['debugExceptionHandler'] = '';
     $localConfiguration['SYS']['trustedHostsPattern'] = 'localhost:8000';
     $localConfiguration['SYS']['encryptionKey'] = 'iAmInvalid';
     // @todo: This sql_mode should be enabled as soon as styleguide and dataHandler can cope with it
     //$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\';';
     $localConfiguration['SYS']['caching']['cacheConfigurations']['extbase_object']['backend'] = NullBackend::class;
     $testbase->setUpLocalConfiguration($instancePath, $localConfiguration, $this->configurationToUseInTestInstance);
     $defaultCoreExtensionsToLoad = ['core', 'extbase', 'fluid', 'filelist', 'extensionmanager', 'lang', 'setup', 'rsaauth', 'saltedpasswords', 'backend', 'belog', 'install', 't3skin', 'frontend', 'recordlist', 'reports', 'sv', 'scheduler'];
     $testbase->setUpPackageStates($instancePath, $defaultCoreExtensionsToLoad, $this->coreExtensionsToLoad, $testExtensionsToLoad);
     $testbase->setUpBasicTypo3Bootstrap($instancePath);
     $testbase->setUpTestDatabase($localConfiguration['DB']['Connections']['Default']['dbname'], $originalDatabaseName);
     $testbase->loadExtensionTables();
     $testbase->createDatabaseStructure();
     // Unset a closure or phpunit kicks in with a 'serialization of \Closure is not allowed'
     // Alternative solution:
     // unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys']['extbase']);
     $suite = $suiteEvent->getSuite();
     $suite->setBackupGlobals(false);
     foreach ($this->xmlDatabaseFixtures as $fixture) {
         $testbase->importXmlDatabaseFixture(ORIGINAL_ROOT . $fixture);
     }
     // styleguide generator uses DataHandler for some parts. DataHandler needs an initialized BE user
     // with admin right and the live workspace.
     Bootstrap::getInstance()->initializeBackendUser();
     $GLOBALS['BE_USER']->user['admin'] = 1;
     $GLOBALS['BE_USER']->user['uid'] = 1;
     $GLOBALS['BE_USER']->workspace = 0;
     Bootstrap::getInstance()->initializeLanguageObject();
     $styleguideGenerator = new Generator();
     $styleguideGenerator->create();
 }
Exemple #2
0
 /**
  * Set up creates a test instance and database.
  *
  * This method should be called with parent::setUp() in your test cases!
  *
  * @return void
  */
 protected function setUp()
 {
     if (!defined('ORIGINAL_ROOT')) {
         $this->markTestSkipped('Functional tests must be called through phpunit on CLI');
     }
     // Use a 7 char long hash of class name as identifier
     $this->identifier = substr(sha1(get_class($this)), 0, 7);
     $this->instancePath = ORIGINAL_ROOT . 'typo3temp/var/tests/functional-' . $this->identifier;
     $testbase = new Testbase();
     $testbase->defineTypo3ModeBe();
     $testbase->setTypo3TestingContext();
     if ($testbase->recentTestInstanceExists($this->instancePath)) {
         // Reusing an existing instance. This typically happens for the second, third, ... test
         // in a test case, so environment is set up only once per test case.
         $testbase->setUpBasicTypo3Bootstrap($this->instancePath);
         $testbase->initializeTestDatabaseAndTruncateTables();
         $testbase->loadExtensionTables();
     } else {
         $testbase->removeOldInstanceIfExists($this->instancePath);
         // Basic instance directory structure
         $testbase->createDirectory($this->instancePath . '/fileadmin');
         $testbase->createDirectory($this->instancePath . '/typo3temp/var/transient');
         $testbase->createDirectory($this->instancePath . '/typo3temp/assets');
         $testbase->createDirectory($this->instancePath . '/typo3conf/ext');
         $testbase->createDirectory($this->instancePath . '/uploads');
         // Additionally requested directories
         foreach ($this->additionalFoldersToCreate as $directory) {
             $testbase->createDirectory($this->instancePath . '/' . $directory);
         }
         $testbase->createLastRunTextfile($this->instancePath);
         $testbase->setUpInstanceCoreLinks($this->instancePath);
         $testbase->linkTestExtensionsToInstance($this->instancePath, $this->testExtensionsToLoad);
         $testbase->linkPathsInTestInstance($this->instancePath, $this->pathsToLinkInTestInstance);
         $localConfiguration['DB'] = $testbase->getOriginalDatabaseSettingsFromEnvironmentOrLocalConfiguration();
         $originalDatabaseName = $localConfiguration['DB']['Connections']['Default']['dbname'];
         // Append the unique identifier to the base database name to end up with a single database per test case
         $localConfiguration['DB']['Connections']['Default']['dbname'] = $originalDatabaseName . '_ft' . $this->identifier;
         $testbase->testDatabaseNameIsNotTooLong($originalDatabaseName, $localConfiguration);
         // Set some hard coded base settings for the instance. Those could be overruled by
         // $this->configurationToUseInTestInstance if needed again.
         $localConfiguration['SYS']['isInitialInstallationInProgress'] = false;
         $localConfiguration['SYS']['isInitialDatabaseImportDone'] = true;
         $localConfiguration['SYS']['displayErrors'] = '1';
         $localConfiguration['SYS']['debugExceptionHandler'] = '';
         $localConfiguration['SYS']['trustedHostsPattern'] = '.*';
         // @todo: This should be moved over to DB/Connections/Default/initCommands
         $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\';';
         $localConfiguration['SYS']['caching']['cacheConfigurations']['extbase_object']['backend'] = NullBackend::class;
         $testbase->setUpLocalConfiguration($this->instancePath, $localConfiguration, $this->configurationToUseInTestInstance);
         $defaultCoreExtensionsToLoad = ['core', 'backend', 'frontend', 'lang', 'extbase', 'install'];
         $testbase->setUpPackageStates($this->instancePath, $defaultCoreExtensionsToLoad, $this->coreExtensionsToLoad, $this->testExtensionsToLoad);
         $testbase->setUpBasicTypo3Bootstrap($this->instancePath);
         $testbase->setUpTestDatabase($localConfiguration['DB']['Connections']['Default']['dbname'], $originalDatabaseName);
         $testbase->loadExtensionTables();
         $testbase->createDatabaseStructure();
     }
 }