3 namespace Drupal\FunctionalTests\Installer;
5 use Drupal\Component\Serialization\Yaml;
6 use Drupal\Core\Archiver\ArchiveTar;
7 use Drupal\Core\Installer\Form\SelectProfileForm;
10 * Provides a base class for testing installing from existing configuration.
12 abstract class InstallerExistingConfigTestBase extends InstallerTestBase {
15 * This is set by the profile in the core.extension extracted.
17 protected $profile = NULL;
22 protected $existingSyncDirectory = FALSE;
27 protected function prepareEnvironment() {
28 parent::prepareEnvironment();
29 $archiver = new ArchiveTar($this->getConfigTarball(), 'gz');
31 if ($this->profile === NULL) {
32 $core_extension = Yaml::decode($archiver->extractInString('core.extension.yml'));
33 $this->profile = $core_extension['profile'];
36 // Create a profile for testing.
39 'core' => \Drupal::CORE_COMPATIBILITY,
40 'name' => 'Configuration installation test profile (' . $this->profile . ')',
43 // File API functions are not available yet.
44 $path = $this->siteDirectory . '/profiles/' . $this->profile;
45 if ($this->existingSyncDirectory) {
46 $config_sync_directory = $this->siteDirectory . '/config/sync';
47 $this->settings['config_directories'][CONFIG_SYNC_DIRECTORY] = (object) [
48 'value' => $config_sync_directory,
53 // Put the sync directory inside the profile.
54 $config_sync_directory = $path . '/config/sync';
57 mkdir($path, 0777, TRUE);
58 file_put_contents("$path/{$this->profile}.info.yml", Yaml::encode($info));
60 // Create config/sync directory and extract tarball contents to it.
61 mkdir($config_sync_directory, 0777, TRUE);
63 $list = $archiver->listContent();
64 if (is_array($list)) {
65 /** @var array $list */
66 foreach ($list as $file) {
67 $files[] = $file['filename'];
69 $archiver->extractList($files, $config_sync_directory);
74 * Gets the filepath to the configuration tarball.
76 * The tarball will be extracted to the install profile's config/sync
77 * directory for testing.
80 * The filepath to the configuration tarball.
82 abstract protected function getConfigTarball();
87 protected function installParameters() {
88 $parameters = parent::installParameters();
90 // The options that change configuration are disabled when installing from
91 // existing configuration.
92 unset($parameters['forms']['install_configure_form']['site_name']);
93 unset($parameters['forms']['install_configure_form']['site_mail']);
94 unset($parameters['forms']['install_configure_form']['update_status_module']);
100 * Confirms that the installation installed the configuration correctly.
102 public function testConfigSync() {
103 // After installation there is no snapshot and nothing to import.
104 $change_list = $this->configImporter()->getStorageComparer()->getChangelist();
107 // The system.mail is changed configuration because the test system
108 // changes it to ensure that mails are not sent.
109 'update' => ['system.mail'],
113 $this->assertEqual($expected, $change_list);
117 * Installer step: Select installation profile.
119 protected function setUpProfile() {
120 if ($this->existingSyncDirectory) {
122 'profile' => SelectProfileForm::CONFIG_INSTALL_PROFILE_KEY,
124 $this->drupalPostForm(NULL, $edit, $this->translations['Save and continue']);
127 parent::setUpProfile();