You are here

protected function InstallerExistingConfigTestBase::prepareEnvironment in Drupal 8

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

1 call to InstallerExistingConfigTestBase::prepareEnvironment()
InstallerExistingConfigNoSystemSiteTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/InstallerExistingConfigNoSystemSiteTest.php
Prepares the current environment for running the test.
1 method overrides InstallerExistingConfigTestBase::prepareEnvironment()
InstallerExistingConfigNoSystemSiteTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/InstallerExistingConfigNoSystemSiteTest.php
Prepares the current environment for running the test.

File

core/tests/Drupal/FunctionalTests/Installer/InstallerExistingConfigTestBase.php, line 27

Class

InstallerExistingConfigTestBase
Provides a base class for testing installing from existing configuration.

Namespace

Drupal\FunctionalTests\Installer

Code

protected function prepareEnvironment() {
  parent::prepareEnvironment();
  $archiver = new ArchiveTar($this
    ->getConfigTarball(), 'gz');
  if ($this->profile === NULL) {
    $core_extension = Yaml::decode($archiver
      ->extractInString('core.extension.yml'));
    $this->profile = $core_extension['profile'];
  }

  // Create a profile for testing. We set core_version_requirement to '*' for
  // the test so that it does not need to be updated between major versions.
  $info = [
    'type' => 'profile',
    'core_version_requirement' => '*',
    'name' => 'Configuration installation test profile (' . $this->profile . ')',
  ];

  // File API functions are not available yet.
  $path = $this->siteDirectory . '/profiles/' . $this->profile;
  if ($this->existingSyncDirectory) {
    $config_sync_directory = $this->siteDirectory . '/config/sync';
    $this->settings['settings']['config_sync_directory'] = (object) [
      'value' => $config_sync_directory,
      'required' => TRUE,
    ];
  }
  else {

    // Put the sync directory inside the profile.
    $config_sync_directory = $path . '/config/sync';
  }
  mkdir($path, 0777, TRUE);
  file_put_contents("{$path}/{$this->profile}.info.yml", Yaml::encode($info));

  // Create config/sync directory and extract tarball contents to it.
  mkdir($config_sync_directory, 0777, TRUE);
  $files = [];
  $list = $archiver
    ->listContent();
  if (is_array($list)) {

    /** @var array $list */
    foreach ($list as $file) {
      $files[] = $file['filename'];
    }
    $archiver
      ->extractList($files, $config_sync_directory);
  }
}