protected function FunctionalTestSetupTrait::prepareSettings in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::prepareSettings()
- 9 core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php \Drupal\Core\Test\FunctionalTestSetupTrait::prepareSettings()
Prepares site settings and services before installation.
4 calls to FunctionalTestSetupTrait::prepareSettings()
- BrowserTestBase::installDrupal in core/
tests/ Drupal/ Tests/ BrowserTestBase.php - Installs Drupal into the test site.
- InstallerPerformanceTest::prepareSettings in core/
tests/ Drupal/ FunctionalTests/ Installer/ InstallerPerformanceTest.php - Prepares site settings and services before installation.
- TestSiteInstallCommand::installDrupal in core/
tests/ Drupal/ TestSite/ Commands/ TestSiteInstallCommand.php - Installs Drupal into the test site.
- UpdatePathTestBase::prepareSettings in core/
tests/ Drupal/ FunctionalTests/ Update/ UpdatePathTestBase.php - Add settings that are missed since the installer isn't run.
3 methods override FunctionalTestSetupTrait::prepareSettings()
- InstallerPerformanceTest::prepareSettings in core/
tests/ Drupal/ FunctionalTests/ Installer/ InstallerPerformanceTest.php - Prepares site settings and services before installation.
- MaintenanceThemeUpdateRegistryTest::prepareSettings in core/
modules/ system/ tests/ src/ Functional/ Theme/ MaintenanceThemeUpdateRegistryTest.php - Prepares site settings and services before installation.
- UpdatePathTestBase::prepareSettings in core/
tests/ Drupal/ FunctionalTests/ Update/ UpdatePathTestBase.php - Add settings that are missed since the installer isn't run.
File
- core/
lib/ Drupal/ Core/ Test/ FunctionalTestSetupTrait.php, line 64
Class
- FunctionalTestSetupTrait
- Defines a trait for shared functional test setup functionality.
Namespace
Drupal\Core\TestCode
protected function prepareSettings() {
// Prepare installer settings that are not install_drupal() parameters.
// Copy and prepare an actual settings.php, so as to resemble a regular
// installation.
// Not using File API; a potential error must trigger a PHP warning.
$directory = DRUPAL_ROOT . '/' . $this->siteDirectory;
copy(DRUPAL_ROOT . '/sites/default/default.settings.php', $directory . '/settings.php');
// The public file system path is created during installation. Additionally,
// during tests:
// - The temporary directory is set and created by install_base_system().
// - The private file directory is created post install by
// FunctionalTestSetupTrait::initConfig().
// @see system_requirements()
// @see TestBase::prepareEnvironment()
// @see install_base_system()
// @see \Drupal\Core\Test\FunctionalTestSetupTrait::initConfig()
$settings['settings']['file_public_path'] = (object) [
'value' => $this->publicFilesDirectory,
'required' => TRUE,
];
$settings['settings']['file_private_path'] = (object) [
'value' => $this->privateFilesDirectory,
'required' => TRUE,
];
$settings['settings']['file_temp_path'] = (object) [
'value' => $this->tempFilesDirectory,
'required' => TRUE,
];
// Save the original site directory path, so that extensions in the
// site-specific directory can still be discovered in the test site
// environment.
// @see \Drupal\Core\Extension\ExtensionDiscovery::scan()
$settings['settings']['test_parent_site'] = (object) [
'value' => $this->originalSite,
'required' => TRUE,
];
$settings['settings']['apcu_ensure_unique_prefix'] = (object) [
'value' => $this->apcuEnsureUniquePrefix,
'required' => TRUE,
];
// Disable fetching of advisories during tests to avoid outbound calls. This
// cannot be set in ::initConfig() because it would not stop these calls
// during install. Tests that need to have the security advisories
// functionality enabled should override this method and unset this
// variable.
// @see \Drupal\Tests\system\Functional\SecurityAdvisories\SecurityAdvisoryTest::writeSettings()
$settings['config']['system.advisories']['enabled'] = (object) [
'value' => FALSE,
'required' => TRUE,
];
$this
->writeSettings($settings);
// Allow for test-specific overrides.
$settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php';
if (file_exists($settings_testing_file)) {
// Copy the testing-specific settings.php overrides in place.
copy($settings_testing_file, $directory . '/settings.testing.php');
// Add the name of the testing class to settings.php and include the
// testing specific overrides.
file_put_contents($directory . '/settings.php', "\n\$test_class = '" . static::class . "';\n" . 'include DRUPAL_ROOT . \'/\' . $site_path . \'/settings.testing.php\';' . "\n", FILE_APPEND);
}
$settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml';
if (!file_exists($settings_services_file)) {
// Otherwise, use the default services as a starting point for overrides.
$settings_services_file = DRUPAL_ROOT . '/sites/default/default.services.yml';
}
// Copy the testing-specific service overrides in place.
copy($settings_services_file, $directory . '/services.yml');
if ($this->strictConfigSchema) {
// Add a listener to validate configuration schema on save.
$yaml = new SymfonyYaml();
$content = file_get_contents($directory . '/services.yml');
$services = $yaml
->parse($content);
$services['services']['testing.config_schema_checker'] = [
'class' => ConfigSchemaChecker::class,
'arguments' => [
'@config.typed',
$this
->getConfigSchemaExclusions(),
],
'tags' => [
[
'name' => 'event_subscriber',
],
],
];
file_put_contents($directory . '/services.yml', $yaml
->dump($services));
}
// Since Drupal is bootstrapped already, install_begin_request() will not
// bootstrap again. Hence, we have to reload the newly written custom
// settings.php manually.
Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $this->classLoader);
}