protected function BrowserTestBase::prepareEnvironment in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/simpletest/src/BrowserTestBase.php \Drupal\simpletest\BrowserTestBase::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.
This method is private as it must only be called once by BrowserTestBase::setUp() (multiple invocations for the same test would have unpredictable consequences) and it must not be callable or overridable by test classes.
1 call to BrowserTestBase::prepareEnvironment()
- BrowserTestBase::setUp in core/
modules/ simpletest/ src/ BrowserTestBase.php
File
- core/
modules/ simpletest/ src/ BrowserTestBase.php, line 1083 - Contains \Drupal\simpletest\BrowserTestBase.
Class
- BrowserTestBase
- Provides a test case for functional Drupal tests.
Namespace
Drupal\simpletestCode
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);
// TestRunnerKernel expects the working directory to be DRUPAL_ROOT.
chdir(DRUPAL_ROOT);
$kernel
->prepareLegacyRequest($request);
$this
->prepareDatabasePrefix();
$this->originalSiteDirectory = $kernel
->findSitePath($request);
// Create test directory ahead of installation so fatal errors and debug
// information can be logged during installation process.
file_prepare_directory($this->siteDirectory, FILE_CREATE_DIRECTORY | FILE_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();
// Ensure there is no service container.
$this->container = NULL;
\Drupal::unsetContainer();
// Unset globals.
unset($GLOBALS['config_directories']);
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(array(
// For performance, simply use the database prefix as hash salt.
'hash_salt' => $this->databasePrefix,
));
drupal_set_time_limit($this->timeLimit);
}