Chris@0: siteDirectory; Chris@0: copy(DRUPAL_ROOT . '/sites/default/default.settings.php', $directory . '/settings.php'); Chris@0: Chris@0: // The public file system path is created during installation. Additionally, Chris@0: // during tests: Chris@0: // - The temporary directory is set and created by install_base_system(). Chris@0: // - The private file directory is created post install by Chris@0: // FunctionalTestSetupTrait::initConfig(). Chris@0: // @see system_requirements() Chris@0: // @see TestBase::prepareEnvironment() Chris@0: // @see install_base_system() Chris@0: // @see \Drupal\Core\Test\FunctionalTestSetupTrait::initConfig() Chris@0: $settings['settings']['file_public_path'] = (object) [ Chris@0: 'value' => $this->publicFilesDirectory, Chris@0: 'required' => TRUE, Chris@0: ]; Chris@0: $settings['settings']['file_private_path'] = (object) [ Chris@0: 'value' => $this->privateFilesDirectory, Chris@0: 'required' => TRUE, Chris@0: ]; Chris@0: // Save the original site directory path, so that extensions in the Chris@0: // site-specific directory can still be discovered in the test site Chris@0: // environment. Chris@0: // @see \Drupal\Core\Extension\ExtensionDiscovery::scan() Chris@0: $settings['settings']['test_parent_site'] = (object) [ Chris@0: 'value' => $this->originalSite, Chris@0: 'required' => TRUE, Chris@0: ]; Chris@0: // Add the parent profile's search path to the child site's search paths. Chris@0: // @see \Drupal\Core\Extension\ExtensionDiscovery::getProfileDirectories() Chris@0: $settings['conf']['simpletest.settings']['parent_profile'] = (object) [ Chris@0: 'value' => $this->originalProfile, Chris@0: 'required' => TRUE, Chris@0: ]; Chris@14: $settings['settings']['apcu_ensure_unique_prefix'] = (object) [ Chris@14: 'value' => $this->apcuEnsureUniquePrefix, Chris@14: 'required' => TRUE, Chris@14: ]; Chris@0: $this->writeSettings($settings); Chris@0: // Allow for test-specific overrides. Chris@0: $settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php'; Chris@0: if (file_exists($settings_testing_file)) { Chris@0: // Copy the testing-specific settings.php overrides in place. Chris@0: copy($settings_testing_file, $directory . '/settings.testing.php'); Chris@0: // Add the name of the testing class to settings.php and include the Chris@0: // testing specific overrides. Chris@0: file_put_contents($directory . '/settings.php', "\n\$test_class = '" . get_class($this) . "';\n" . 'include DRUPAL_ROOT . \'/\' . $site_path . \'/settings.testing.php\';' . "\n", FILE_APPEND); Chris@0: } Chris@0: $settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml'; Chris@0: if (!file_exists($settings_services_file)) { Chris@0: // Otherwise, use the default services as a starting point for overrides. Chris@0: $settings_services_file = DRUPAL_ROOT . '/sites/default/default.services.yml'; Chris@0: } Chris@0: // Copy the testing-specific service overrides in place. Chris@0: copy($settings_services_file, $directory . '/services.yml'); Chris@0: if ($this->strictConfigSchema) { Chris@0: // Add a listener to validate configuration schema on save. Chris@0: $yaml = new SymfonyYaml(); Chris@0: $content = file_get_contents($directory . '/services.yml'); Chris@0: $services = $yaml->parse($content); Chris@0: $services['services']['simpletest.config_schema_checker'] = [ Chris@0: 'class' => ConfigSchemaChecker::class, Chris@0: 'arguments' => ['@config.typed', $this->getConfigSchemaExclusions()], Chris@0: 'tags' => [['name' => 'event_subscriber']], Chris@0: ]; Chris@0: file_put_contents($directory . '/services.yml', $yaml->dump($services)); Chris@0: } Chris@0: // Since Drupal is bootstrapped already, install_begin_request() will not Chris@0: // bootstrap again. Hence, we have to reload the newly written custom Chris@0: // settings.php manually. Chris@0: Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $this->classLoader); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Rewrites the settings.php file of the test site. Chris@0: * Chris@0: * @param array $settings Chris@0: * An array of settings to write out, in the format expected by Chris@0: * drupal_rewrite_settings(). Chris@0: * Chris@0: * @see drupal_rewrite_settings() Chris@0: */ Chris@0: protected function writeSettings(array $settings) { Chris@0: include_once DRUPAL_ROOT . '/core/includes/install.inc'; Chris@0: $filename = $this->siteDirectory . '/settings.php'; Chris@0: // system_requirements() removes write permissions from settings.php Chris@0: // whenever it is invoked. Chris@0: // Not using File API; a potential error must trigger a PHP warning. Chris@0: chmod($filename, 0666); Chris@0: drupal_rewrite_settings($settings, $filename); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Changes parameters in the services.yml file. Chris@0: * Chris@0: * @param string $name Chris@0: * The name of the parameter. Chris@0: * @param string $value Chris@0: * The value of the parameter. Chris@0: */ Chris@0: protected function setContainerParameter($name, $value) { Chris@0: $filename = $this->siteDirectory . '/services.yml'; Chris@0: chmod($filename, 0666); Chris@0: Chris@0: $services = Yaml::decode(file_get_contents($filename)); Chris@0: $services['parameters'][$name] = $value; Chris@0: file_put_contents($filename, Yaml::encode($services)); Chris@0: Chris@0: // Ensure that the cache is deleted for the yaml file loader. Chris@0: $file_cache = FileCacheFactory::get('container_yaml_loader'); Chris@0: $file_cache->delete($filename); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Rebuilds \Drupal::getContainer(). Chris@0: * Chris@0: * Use this to update the test process's kernel with a new service container. Chris@0: * For example, when the list of enabled modules is changed via the internal Chris@0: * browser the test process's kernel has a service container with an out of Chris@0: * date module list. Chris@0: * Chris@0: * @see TestBase::prepareEnvironment() Chris@0: * @see TestBase::restoreEnvironment() Chris@0: * Chris@0: * @todo Fix https://www.drupal.org/node/2021959 so that module enable/disable Chris@0: * changes are immediately reflected in \Drupal::getContainer(). Until then, Chris@0: * tests can invoke this workaround when requiring services from newly Chris@0: * enabled modules to be immediately available in the same request. Chris@0: */ Chris@0: protected function rebuildContainer() { Chris@0: // Rebuild the kernel and bring it back to a fully bootstrapped state. Chris@0: $this->container = $this->kernel->rebuildContainer(); Chris@0: Chris@0: // Make sure the url generator has a request object, otherwise calls to Chris@0: // $this->drupalGet() will fail. Chris@0: $this->prepareRequestForGenerator(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Resets all data structures after having enabled new modules. Chris@0: * Chris@0: * This method is called by FunctionalTestSetupTrait::rebuildAll() after Chris@0: * enabling the requested modules. It must be called again when additional Chris@0: * modules are enabled later. Chris@0: * Chris@0: * @see \Drupal\Core\Test\FunctionalTestSetupTrait::rebuildAll() Chris@0: * @see \Drupal\Tests\BrowserTestBase::installDrupal() Chris@0: * @see \Drupal\simpletest\WebTestBase::setUp() Chris@0: */ Chris@0: protected function resetAll() { Chris@0: // Clear all database and static caches and rebuild data structures. Chris@0: drupal_flush_all_caches(); Chris@0: $this->container = \Drupal::getContainer(); Chris@0: Chris@0: // Reset static variables and reload permissions. Chris@0: $this->refreshVariables(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates a mock request and sets it on the generator. Chris@0: * Chris@0: * This is used to manipulate how the generator generates paths during tests. Chris@0: * It also ensures that calls to $this->drupalGet() will work when running Chris@0: * from run-tests.sh because the url generator no longer looks at the global Chris@0: * variables that are set there but relies on getting this information from a Chris@0: * request object. Chris@0: * Chris@0: * @param bool $clean_urls Chris@0: * Whether to mock the request using clean urls. Chris@0: * @param array $override_server_vars Chris@0: * An array of server variables to override. Chris@0: * Chris@0: * @return \Symfony\Component\HttpFoundation\Request Chris@0: * The mocked request object. Chris@0: */ Chris@0: protected function prepareRequestForGenerator($clean_urls = TRUE, $override_server_vars = []) { Chris@0: $request = Request::createFromGlobals(); Chris@0: $server = $request->server->all(); Chris@0: if (basename($server['SCRIPT_FILENAME']) != basename($server['SCRIPT_NAME'])) { Chris@0: // We need this for when the test is executed by run-tests.sh. Chris@0: // @todo Remove this once run-tests.sh has been converted to use a Request Chris@0: // object. Chris@0: $cwd = getcwd(); Chris@0: $server['SCRIPT_FILENAME'] = $cwd . '/' . basename($server['SCRIPT_NAME']); Chris@0: $base_path = rtrim($server['REQUEST_URI'], '/'); Chris@0: } Chris@0: else { Chris@0: $base_path = $request->getBasePath(); Chris@0: } Chris@0: if ($clean_urls) { Chris@0: $request_path = $base_path ? $base_path . '/user' : 'user'; Chris@0: } Chris@0: else { Chris@0: $request_path = $base_path ? $base_path . '/index.php/user' : '/index.php/user'; Chris@0: } Chris@0: $server = array_merge($server, $override_server_vars); Chris@0: Chris@0: $request = Request::create($request_path, 'GET', [], [], [], $server); Chris@0: // Ensure the request time is REQUEST_TIME to ensure that API calls Chris@0: // in the test use the right timestamp. Chris@0: $request->server->set('REQUEST_TIME', REQUEST_TIME); Chris@0: $this->container->get('request_stack')->push($request); Chris@0: Chris@0: // The request context is normally set by the router_listener from within Chris@0: // its KernelEvents::REQUEST listener. In the simpletest parent site this Chris@0: // event is not fired, therefore it is necessary to updated the request Chris@0: // context manually here. Chris@0: $this->container->get('router.request_context')->fromRequest($request); Chris@0: Chris@0: return $request; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Execute the non-interactive installer. Chris@0: * Chris@0: * @see install_drupal() Chris@0: */ Chris@0: protected function doInstall() { Chris@0: require_once DRUPAL_ROOT . '/core/includes/install.core.inc'; Chris@0: install_drupal($this->classLoader, $this->installParameters()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Initialize settings created during install. Chris@0: */ Chris@0: protected function initSettings() { Chris@0: Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $this->classLoader); Chris@0: foreach ($GLOBALS['config_directories'] as $type => $path) { Chris@0: $this->configDirectories[$type] = $path; Chris@0: } Chris@0: Chris@0: // After writing settings.php, the installer removes write permissions Chris@0: // from the site directory. To allow drupal_generate_test_ua() to write Chris@0: // a file containing the private key for drupal_valid_test_ua(), the site Chris@0: // directory has to be writable. Chris@0: // TestBase::restoreEnvironment() will delete the entire site directory. Chris@0: // Not using File API; a potential error must trigger a PHP warning. Chris@0: chmod(DRUPAL_ROOT . '/' . $this->siteDirectory, 0777); Chris@0: Chris@0: // During tests, cacheable responses should get the debugging cacheability Chris@0: // headers by default. Chris@0: $this->setContainerParameter('http.response.debug_cacheability_headers', TRUE); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Initialize various configurations post-installation. Chris@0: * Chris@0: * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Chris@0: * The container. Chris@0: */ Chris@0: protected function initConfig(ContainerInterface $container) { Chris@0: $config = $container->get('config.factory'); Chris@0: Chris@0: // Manually create the private directory. Chris@18: \Drupal::service('file_system')->prepareDirectory($this->privateFilesDirectory, FileSystemInterface::CREATE_DIRECTORY); Chris@0: Chris@0: // Manually configure the test mail collector implementation to prevent Chris@0: // tests from sending out emails and collect them in state instead. Chris@0: // While this should be enforced via settings.php prior to installation, Chris@0: // some tests expect to be able to test mail system implementations. Chris@0: $config->getEditable('system.mail') Chris@0: ->set('interface.default', 'test_mail_collector') Chris@0: ->save(); Chris@0: Chris@0: // By default, verbosely display all errors and disable all production Chris@0: // environment optimizations for all tests to avoid needless overhead and Chris@0: // ensure a sane default experience for test authors. Chris@0: // @see https://www.drupal.org/node/2259167 Chris@0: $config->getEditable('system.logging') Chris@0: ->set('error_level', 'verbose') Chris@0: ->save(); Chris@0: $config->getEditable('system.performance') Chris@0: ->set('css.preprocess', FALSE) Chris@0: ->set('js.preprocess', FALSE) Chris@0: ->save(); Chris@0: Chris@0: // Set an explicit time zone to not rely on the system one, which may vary Chris@0: // from setup to setup. The Australia/Sydney time zone is chosen so all Chris@0: // tests are run using an edge case scenario (UTC10 and DST). This choice Chris@0: // is made to prevent time zone related regressions and reduce the Chris@0: // fragility of the testing system in general. Chris@0: $config->getEditable('system.date') Chris@0: ->set('timezone.default', 'Australia/Sydney') Chris@0: ->save(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Initializes user 1 for the site to be installed. Chris@0: */ Chris@0: protected function initUserSession() { Chris@0: $password = $this->randomMachineName(); Chris@0: // Define information about the user 1 account. Chris@0: $this->rootUser = new UserSession([ Chris@0: 'uid' => 1, Chris@0: 'name' => 'admin', Chris@0: 'mail' => 'admin@example.com', Chris@0: 'pass_raw' => $password, Chris@0: 'passRaw' => $password, Chris@0: 'timezone' => date_default_timezone_get(), Chris@0: ]); Chris@0: Chris@0: // The child site derives its session name from the database prefix when Chris@0: // running web tests. Chris@0: $this->generateSessionName($this->databasePrefix); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Initializes the kernel after installation. Chris@0: * Chris@0: * @param \Symfony\Component\HttpFoundation\Request $request Chris@0: * Request object. Chris@0: * Chris@0: * @return \Symfony\Component\DependencyInjection\ContainerInterface Chris@0: * The container. Chris@0: */ Chris@0: protected function initKernel(Request $request) { Chris@0: $this->kernel = DrupalKernel::createFromRequest($request, $this->classLoader, 'prod', TRUE); Chris@18: Chris@0: // Force the container to be built from scratch instead of loaded from the Chris@0: // disk. This forces us to not accidentally load the parent site. Chris@18: $this->kernel->invalidateContainer(); Chris@18: Chris@18: $this->kernel->prepareLegacyRequest($request); Chris@18: return \Drupal::getContainer(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Install modules defined by `static::$modules`. Chris@0: * Chris@0: * To install test modules outside of the testing environment, add Chris@0: * @code Chris@0: * $settings['extension_discovery_scan_tests'] = TRUE; Chris@0: * @endcode Chris@0: * to your settings.php. Chris@0: * Chris@0: * @param \Symfony\Component\DependencyInjection\ContainerInterface $container Chris@0: * The container. Chris@0: */ Chris@0: protected function installModulesFromClassProperty(ContainerInterface $container) { Chris@0: $class = get_class($this); Chris@0: $modules = []; Chris@0: while ($class) { Chris@0: if (property_exists($class, 'modules')) { Chris@0: $modules = array_merge($modules, $class::$modules); Chris@0: } Chris@0: $class = get_parent_class($class); Chris@0: } Chris@0: if ($modules) { Chris@0: $modules = array_unique($modules); Chris@0: try { Chris@0: $success = $container->get('module_installer')->install($modules, TRUE); Chris@17: $this->assertTrue($success, new FormattableMarkup('Enabled modules: %modules', ['%modules' => implode(', ', $modules)])); Chris@0: } Chris@0: catch (MissingDependencyException $e) { Chris@0: // The exception message has all the details. Chris@0: $this->fail($e->getMessage()); Chris@0: } Chris@18: // The container was already rebuilt by the ModuleInstaller. Chris@18: $this->container = \Drupal::getContainer(); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Resets and rebuilds the environment after setup. Chris@0: */ Chris@0: protected function rebuildAll() { Chris@0: // Reset/rebuild all data structures after enabling the modules, primarily Chris@0: // to synchronize all data structures and caches between the test runner and Chris@0: // the child site. Chris@0: // @see \Drupal\Core\DrupalKernel::bootCode() Chris@0: // @todo Test-specific setUp() methods may set up further fixtures; find a Chris@0: // way to execute this after setUp() is done, or to eliminate it entirely. Chris@0: $this->resetAll(); Chris@0: $this->kernel->prepareLegacyRequest(\Drupal::request()); Chris@0: Chris@0: // Explicitly call register() again on the container registered in \Drupal. Chris@0: // @todo This should already be called through Chris@0: // DrupalKernel::prepareLegacyRequest() -> DrupalKernel::boot() but that Chris@0: // appears to be calling a different container. Chris@0: $this->container->get('stream_wrapper_manager')->register(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the parameters that will be used when Simpletest installs Drupal. Chris@0: * Chris@0: * @see install_drupal() Chris@0: * @see install_state_defaults() Chris@0: * Chris@0: * @return array Chris@0: * Array of parameters for use in install_drupal(). Chris@0: */ Chris@0: protected function installParameters() { Chris@0: $connection_info = Database::getConnectionInfo(); Chris@0: $driver = $connection_info['default']['driver']; Chris@0: $connection_info['default']['prefix'] = $connection_info['default']['prefix']['default']; Chris@0: unset($connection_info['default']['driver']); Chris@0: unset($connection_info['default']['namespace']); Chris@0: unset($connection_info['default']['pdo']); Chris@0: unset($connection_info['default']['init_commands']); Chris@0: // Remove database connection info that is not used by SQLite. Chris@0: if ($driver === 'sqlite') { Chris@0: unset($connection_info['default']['username']); Chris@0: unset($connection_info['default']['password']); Chris@0: unset($connection_info['default']['host']); Chris@0: unset($connection_info['default']['port']); Chris@0: } Chris@0: $parameters = [ Chris@0: 'interactive' => FALSE, Chris@0: 'parameters' => [ Chris@0: 'profile' => $this->profile, Chris@0: 'langcode' => 'en', Chris@0: ], Chris@0: 'forms' => [ Chris@0: 'install_settings_form' => [ Chris@0: 'driver' => $driver, Chris@0: $driver => $connection_info['default'], Chris@0: ], Chris@0: 'install_configure_form' => [ Chris@0: 'site_name' => 'Drupal', Chris@0: 'site_mail' => 'simpletest@example.com', Chris@0: 'account' => [ Chris@0: 'name' => $this->rootUser->name, Chris@0: 'mail' => $this->rootUser->getEmail(), Chris@0: 'pass' => [ Chris@0: 'pass1' => isset($this->rootUser->pass_raw) ? $this->rootUser->pass_raw : $this->rootUser->passRaw, Chris@0: 'pass2' => isset($this->rootUser->pass_raw) ? $this->rootUser->pass_raw : $this->rootUser->passRaw, Chris@0: ], Chris@0: ], Chris@0: // form_type_checkboxes_value() requires NULL instead of FALSE values Chris@0: // for programmatic form submissions to disable a checkbox. Chris@0: 'enable_update_status_module' => NULL, Chris@0: 'enable_update_status_emails' => NULL, Chris@0: ], Chris@0: ], Chris@0: ]; Chris@0: Chris@0: // If we only have one db driver available, we cannot set the driver. Chris@0: include_once DRUPAL_ROOT . '/core/includes/install.inc'; Chris@0: if (count($this->getDatabaseTypes()) == 1) { Chris@0: unset($parameters['forms']['install_settings_form']['driver']); Chris@0: } Chris@0: return $parameters; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets up the base URL based upon the environment variable. Chris@0: * Chris@0: * @throws \Exception Chris@0: * Thrown when no SIMPLETEST_BASE_URL environment variable is provided. Chris@0: */ Chris@0: protected function setupBaseUrl() { Chris@0: global $base_url; Chris@0: Chris@0: // Get and set the domain of the environment we are running our test Chris@0: // coverage against. Chris@0: $base_url = getenv('SIMPLETEST_BASE_URL'); Chris@0: if (!$base_url) { Chris@0: throw new \Exception( Chris@0: 'You must provide a SIMPLETEST_BASE_URL environment variable to run some PHPUnit based functional tests.' Chris@0: ); Chris@0: } Chris@0: Chris@0: // Setup $_SERVER variable. Chris@0: $parsed_url = parse_url($base_url); Chris@0: $host = $parsed_url['host'] . (isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''); Chris@0: $path = isset($parsed_url['path']) ? rtrim(rtrim($parsed_url['path']), '/') : ''; Chris@0: $port = isset($parsed_url['port']) ? $parsed_url['port'] : 80; Chris@0: Chris@0: $this->baseUrl = $base_url; Chris@0: Chris@0: // If the passed URL schema is 'https' then setup the $_SERVER variables Chris@0: // properly so that testing will run under HTTPS. Chris@0: if ($parsed_url['scheme'] === 'https') { Chris@0: $_SERVER['HTTPS'] = 'on'; Chris@0: } Chris@0: $_SERVER['HTTP_HOST'] = $host; Chris@0: $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; Chris@0: $_SERVER['SERVER_ADDR'] = '127.0.0.1'; Chris@0: $_SERVER['SERVER_PORT'] = $port; Chris@0: $_SERVER['SERVER_SOFTWARE'] = NULL; Chris@0: $_SERVER['SERVER_NAME'] = 'localhost'; Chris@0: $_SERVER['REQUEST_URI'] = $path . '/'; Chris@0: $_SERVER['REQUEST_METHOD'] = 'GET'; Chris@0: $_SERVER['SCRIPT_NAME'] = $path . '/index.php'; Chris@0: $_SERVER['SCRIPT_FILENAME'] = $path . '/index.php'; Chris@0: $_SERVER['PHP_SELF'] = $path . '/index.php'; Chris@0: $_SERVER['HTTP_USER_AGENT'] = 'Drupal command line'; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Prepares the current environment for running the test. Chris@0: * Chris@0: * Also sets up new resources for the testing environment, such as the public Chris@0: * filesystem and configuration directories. Chris@0: * Chris@0: * This method is private as it must only be called once by Chris@0: * BrowserTestBase::setUp() (multiple invocations for the same test would have Chris@0: * unpredictable consequences) and it must not be callable or overridable by Chris@0: * test classes. Chris@0: */ Chris@0: protected function prepareEnvironment() { Chris@0: // Bootstrap Drupal so we can use Drupal's built in functions. Chris@0: $this->classLoader = require __DIR__ . '/../../../../../autoload.php'; Chris@0: $request = Request::createFromGlobals(); Chris@0: $kernel = TestRunnerKernel::createFromRequest($request, $this->classLoader); Chris@0: // TestRunnerKernel expects the working directory to be DRUPAL_ROOT. Chris@0: chdir(DRUPAL_ROOT); Chris@0: $kernel->prepareLegacyRequest($request); Chris@0: $this->prepareDatabasePrefix(); Chris@0: Chris@0: $this->originalSite = $kernel->findSitePath($request); Chris@0: Chris@0: // Create test directory ahead of installation so fatal errors and debug Chris@0: // information can be logged during installation process. Chris@18: \Drupal::service('file_system')->prepareDirectory($this->siteDirectory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS); Chris@0: Chris@0: // Prepare filesystem directory paths. Chris@0: $this->publicFilesDirectory = $this->siteDirectory . '/files'; Chris@0: $this->privateFilesDirectory = $this->siteDirectory . '/private'; Chris@0: $this->tempFilesDirectory = $this->siteDirectory . '/temp'; Chris@0: $this->translationFilesDirectory = $this->siteDirectory . '/translations'; Chris@0: Chris@0: // Ensure the configImporter is refreshed for each test. Chris@0: $this->configImporter = NULL; Chris@0: Chris@0: // Unregister all custom stream wrappers of the parent site. Chris@0: $wrappers = \Drupal::service('stream_wrapper_manager')->getWrappers(StreamWrapperInterface::ALL); Chris@0: foreach ($wrappers as $scheme => $info) { Chris@0: stream_wrapper_unregister($scheme); Chris@0: } Chris@0: Chris@0: // Reset statics. Chris@0: drupal_static_reset(); Chris@0: Chris@0: $this->container = NULL; Chris@0: Chris@0: // Unset globals. Chris@0: unset($GLOBALS['config_directories']); Chris@0: unset($GLOBALS['config']); Chris@0: unset($GLOBALS['conf']); Chris@0: Chris@0: // Log fatal errors. Chris@0: ini_set('log_errors', 1); Chris@0: ini_set('error_log', DRUPAL_ROOT . '/' . $this->siteDirectory . '/error.log'); Chris@0: Chris@0: // Change the database prefix. Chris@0: $this->changeDatabasePrefix(); Chris@0: Chris@0: // After preparing the environment and changing the database prefix, we are Chris@0: // in a valid test environment. Chris@0: drupal_valid_test_ua($this->databasePrefix); Chris@0: Chris@0: // Reset settings. Chris@0: new Settings([ Chris@0: // For performance, simply use the database prefix as hash salt. Chris@0: 'hash_salt' => $this->databasePrefix, Chris@0: ]); Chris@0: Chris@18: Environment::setTimeLimit($this->timeLimit); Chris@0: Chris@0: // Save and clean the shutdown callbacks array because it is static cached Chris@0: // and will be changed by the test run. Otherwise it will contain callbacks Chris@0: // from both environments and the testing environment will try to call the Chris@0: // handlers defined by the original one. Chris@0: $callbacks = &drupal_register_shutdown_function(); Chris@0: $this->originalShutdownCallbacks = $callbacks; Chris@0: $callbacks = []; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns all supported database driver installer objects. Chris@0: * Chris@0: * This wraps drupal_get_database_types() for use without a current container. Chris@0: * Chris@0: * @return \Drupal\Core\Database\Install\Tasks[] Chris@0: * An array of available database driver installer objects. Chris@0: */ Chris@0: protected function getDatabaseTypes() { Chris@17: if (isset($this->originalContainer) && $this->originalContainer) { Chris@0: \Drupal::setContainer($this->originalContainer); Chris@0: } Chris@0: $database_types = drupal_get_database_types(); Chris@17: if (isset($this->originalContainer) && $this->originalContainer) { Chris@0: \Drupal::unsetContainer(); Chris@0: } Chris@0: return $database_types; Chris@0: } Chris@0: Chris@0: }