You are here

protected function DistributionProfileExistingSettingsTest::prepareEnvironment in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php \Drupal\FunctionalTests\Installer\DistributionProfileExistingSettingsTest::prepareEnvironment()
  2. 10 core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php \Drupal\FunctionalTests\Installer\DistributionProfileExistingSettingsTest::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.

Overrides FunctionalTestSetupTrait::prepareEnvironment

File

core/tests/Drupal/FunctionalTests/Installer/DistributionProfileExistingSettingsTest.php, line 33

Class

DistributionProfileExistingSettingsTest
Tests distribution profile support with existing settings.

Namespace

Drupal\FunctionalTests\Installer

Code

protected function prepareEnvironment() {
  parent::prepareEnvironment();
  $this->info = [
    'type' => 'profile',
    'core_version_requirement' => '*',
    'name' => 'Distribution profile',
    'distribution' => [
      'name' => 'My Distribution',
      'install' => [
        'theme' => 'bartik',
      ],
    ],
  ];

  // File API functions are not available yet.
  $path = $this->siteDirectory . '/profiles/mydistro';
  mkdir($path, 0777, TRUE);
  file_put_contents("{$path}/mydistro.info.yml", Yaml::encode($this->info));

  // Pre-configure hash salt.
  // Any string is valid, so simply use the class name of this test.
  $this->settings['settings']['hash_salt'] = (object) [
    'value' => __CLASS__,
    'required' => TRUE,
  ];

  // Pre-configure database credentials.
  $connection_info = Database::getConnectionInfo();
  unset($connection_info['default']['pdo']);
  unset($connection_info['default']['init_commands']);
  $this->settings['databases']['default'] = (object) [
    'value' => $connection_info,
    'required' => TRUE,
  ];

  // Use the kernel to find the site path because the site.path service should
  // not be available at this point in the install process.
  $site_path = DrupalKernel::findSitePath(Request::createFromGlobals());

  // Pre-configure config directories.
  $this->settings['settings']['config_sync_directory'] = (object) [
    'value' => $site_path . '/files/config_staging',
    'required' => TRUE,
  ];
  mkdir($this->settings['settings']['config_sync_directory']->value, 0777, TRUE);
}