function FunctionalTestSetupTrait::prepareEnvironment

Same name in other branches
  1. 9 core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::prepareEnvironment()
  2. 8.9.x core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::prepareEnvironment()
  3. 10 core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::prepareEnvironment()

Prepares the current environment for running the test.

Also sets up new resources for the testing environment, such as the public filesystem and configuration directories.

31 calls to FunctionalTestSetupTrait::prepareEnvironment()
BrowserTestBase::setUp in core/tests/Drupal/Tests/BrowserTestBase.php
ConfigInstallProfileUnmetDependenciesTest::prepareEnvironment in core/modules/config/tests/src/Functional/ConfigInstallProfileUnmetDependenciesTest.php
Prepares the current environment for running the test.
DistributionProfileExistingSettingsTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php
Prepares the current environment for running the test.
DistributionProfileTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTest.php
Prepares the current environment for running the test.
DistributionProfileTranslationQueryTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTranslationQueryTest.php
Prepares the current environment for running the test.

... See full list

29 methods override FunctionalTestSetupTrait::prepareEnvironment()
ConfigInstallProfileUnmetDependenciesTest::prepareEnvironment in core/modules/config/tests/src/Functional/ConfigInstallProfileUnmetDependenciesTest.php
Prepares the current environment for running the test.
DistributionProfileExistingSettingsTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php
Prepares the current environment for running the test.
DistributionProfileTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTest.php
Prepares the current environment for running the test.
DistributionProfileTranslationQueryTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTranslationQueryTest.php
Prepares the current environment for running the test.
DistributionProfileTranslationTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTranslationTest.php
Prepares the current environment for running the test.

... See full list

File

core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php, line 655

Class

FunctionalTestSetupTrait
Defines a trait for shared functional test setup functionality.

Namespace

Drupal\Core\Test

Code

protected function prepareEnvironment() {
    // Bootstrap Drupal so we can use Drupal's built in functions.
    $this->classLoader = (require __DIR__ . '/../../../../../autoload.php');
    $request = Request::createFromGlobals();
    $kernel = TestRunnerKernel::createFromRequest($request, $this->classLoader);
    $kernel->boot();
    $kernel->preHandle($request);
    $this->prepareDatabasePrefix();
    $this->originalSite = $kernel->findSitePath($request);
    // Create test directory ahead of installation so fatal errors and debug
    // information can be logged during installation process.
    \Drupal::service('file_system')->prepareDirectory($this->siteDirectory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
    // Prepare filesystem directory paths.
    $this->publicFilesDirectory = $this->siteDirectory . '/files';
    $this->privateFilesDirectory = $this->siteDirectory . '/private';
    $this->tempFilesDirectory = $this->siteDirectory . '/temp';
    $this->translationFilesDirectory = $this->siteDirectory . '/translations';
    // Ensure the configImporter is refreshed for each test.
    $this->configImporter = NULL;
    // Unregister all custom stream wrappers of the parent site.
    $wrappers = \Drupal::service('stream_wrapper_manager')->getWrappers(StreamWrapperInterface::ALL);
    foreach ($wrappers as $scheme => $info) {
        stream_wrapper_unregister($scheme);
    }
    // Reset statics.
    drupal_static_reset();
    $this->container = NULL;
    // Unset globals.
    unset($GLOBALS['config']);
    unset($GLOBALS['conf']);
    // Log fatal errors.
    ini_set('log_errors', 1);
    ini_set('error_log', DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log');
    // Change the database prefix.
    $this->changeDatabasePrefix();
    // After preparing the environment and changing the database prefix, we are
    // in a valid test environment.
    drupal_valid_test_ua($this->databasePrefix);
    // Reset settings.
    new Settings([
        // For performance, simply use the database prefix as hash salt.
'hash_salt' => $this->databasePrefix,
    ]);
    Environment::setTimeLimit($this->timeLimit);
    // Save and clean the shutdown callbacks array because it is static cached
    // and will be changed by the test run. Otherwise it will contain callbacks
    // from both environments and the testing environment will try to call the
    // handlers defined by the original one.
    $callbacks =& drupal_register_shutdown_function();
    $this->originalShutdownCallbacks = $callbacks;
    $callbacks = [];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.