function InstallerConfigDirectoryTestBase::prepareEnvironment

Overrides FunctionalTestSetupTrait::prepareEnvironment

3 calls to InstallerConfigDirectoryTestBase::prepareEnvironment()
InstallerExistingConfigExistingSettingsTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/InstallerExistingConfigExistingSettingsTest.php
Partially configures a preexisting settings.php file before invoking the interactive installer.
InstallerExistingConfigNoSystemSiteTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/InstallerExistingConfigNoSystemSiteTest.php
Prepares the current environment for running the test.
InstallerExistingConfigSyncDirectoryMultilingualTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/InstallerExistingConfigSyncDirectoryMultilingualTest.php
Prepares the current environment for running the test.
3 methods override InstallerConfigDirectoryTestBase::prepareEnvironment()
InstallerExistingConfigExistingSettingsTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/InstallerExistingConfigExistingSettingsTest.php
Partially configures a preexisting settings.php file before invoking the interactive installer.
InstallerExistingConfigNoSystemSiteTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/InstallerExistingConfigNoSystemSiteTest.php
Prepares the current environment for running the test.
InstallerExistingConfigSyncDirectoryMultilingualTest::prepareEnvironment in core/tests/Drupal/FunctionalTests/Installer/InstallerExistingConfigSyncDirectoryMultilingualTest.php
Prepares the current environment for running the test.

File

core/tests/Drupal/FunctionalTests/Installer/InstallerConfigDirectoryTestBase.php, line 60

Class

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

Namespace

Drupal\FunctionalTests\Installer

Code

protected function prepareEnvironment() {
    parent::prepareEnvironment();
    if ($this->profile === NULL) {
        $core_extension_location = $this->getConfigLocation() . '/core.extension.yml';
        $core_extension = Yaml::decode(file_get_contents($core_extension_location));
        $this->profile = $core_extension['profile'];
    }
    if ($this->profile !== FALSE) {
        // 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;
        // 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));
    }
    else {
        // If we have no profile we must use an existing sync directory.
        $this->existingSyncDirectory = TRUE;
        $config_sync_directory = $this->siteDirectory . '/config/sync';
    }
    if ($this->existingSyncDirectory) {
        $config_sync_directory = $this->siteDirectory . '/config/sync';
        $this->settings['settings']['config_sync_directory'] = (object) [
            'value' => $config_sync_directory,
            'required' => TRUE,
        ];
    }
    // Create config/sync directory and extract tarball contents to it.
    mkdir($config_sync_directory, 0777, TRUE);
    $this->copyDirectory($this->getConfigLocation(), $config_sync_directory);
    // Add the module that is providing the database driver to the list of
    // modules that can not be uninstalled in the core.extension configuration.
    if (file_exists($config_sync_directory . '/core.extension.yml')) {
        $core_extension = Yaml::decode(file_get_contents($config_sync_directory . '/core.extension.yml'));
        $module = Database::getConnection()->getProvider();
        if ($module !== 'core') {
            $core_extension['module'][$module] = 0;
            $core_extension['module'] = module_config_sort($core_extension['module']);
        }
        if ($this->profile === FALSE && array_key_exists('profile', $core_extension)) {
            // Remove the profile.
            unset($core_extension['module'][$core_extension['profile']]);
            unset($core_extension['profile']);
            // Set a default theme to the first theme that will be installed as this
            // can not be retrieved from the profile.
            $this->defaultTheme = array_key_first($core_extension['theme']);
        }
        file_put_contents($config_sync_directory . '/core.extension.yml', Yaml::encode($core_extension));
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.