You are here

protected function WebTestBase::prepareSettings in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/WebTestBase.php \Drupal\simpletest\WebTestBase::prepareSettings()

Prepares site settings and services before installation.

2 calls to WebTestBase::prepareSettings()
UpdatePathTestBase::prepareSettings in core/modules/system/src/Tests/Update/UpdatePathTestBase.php
Add settings that are missed since the installer isn't run.
WebTestBase::setUp in core/modules/simpletest/src/WebTestBase.php
Sets up a Drupal site for running functional and integration tests.
1 method overrides WebTestBase::prepareSettings()
UpdatePathTestBase::prepareSettings in core/modules/system/src/Tests/Update/UpdatePathTestBase.php
Add settings that are missed since the installer isn't run.

File

core/modules/simpletest/src/WebTestBase.php, line 721
Contains \Drupal\simpletest\WebTestBase.

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

Code

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');

  // All file system paths are created by System module during installation.
  // @see system_requirements()
  // @see TestBase::prepareEnvironment()
  $settings['settings']['file_public_path'] = (object) [
    'value' => $this->publicFilesDirectory,
    'required' => TRUE,
  ];
  $settings['settings']['file_private_path'] = (object) [
    'value' => $this->privateFilesDirectory,
    '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,
  ];

  // Add the parent profile's search path to the child site's search paths.
  // @see \Drupal\Core\Extension\ExtensionDiscovery::getProfileDirectories()
  $settings['conf']['simpletest.settings']['parent_profile'] = (object) [
    'value' => $this->originalProfile,
    'required' => TRUE,
  ];
  $settings['settings']['apcu_ensure_unique_prefix'] = (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 = '" . get_class($this) . "';\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 \Symfony\Component\Yaml\Yaml();
    $content = file_get_contents($directory . '/services.yml');
    $services = $yaml
      ->parse($content);
    $services['services']['simpletest.config_schema_checker'] = [
      'class' => 'Drupal\\Core\\Config\\Testing\\ConfigSchemaChecker',
      '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);
}