InstallerExistingConfigTestBase.php in Drupal 10
File
core/tests/Drupal/FunctionalTests/Installer/InstallerExistingConfigTestBase.php
View source
<?php
namespace Drupal\FunctionalTests\Installer;
use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Archiver\ArchiveTar;
use Drupal\Core\Database\Database;
use Drupal\Core\Installer\Form\SelectProfileForm;
abstract class InstallerExistingConfigTestBase extends InstallerTestBase {
protected $profile = NULL;
protected $existingSyncDirectory = FALSE;
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'];
}
$info = [
'type' => 'profile',
'core_version_requirement' => '*',
'name' => 'Configuration installation test profile (' . $this->profile . ')',
];
$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 {
$config_sync_directory = $path . '/config/sync';
}
mkdir($path, 0777, TRUE);
file_put_contents("{$path}/{$this->profile}.info.yml", Yaml::encode($info));
mkdir($config_sync_directory, 0777, TRUE);
$files = [];
$list = $archiver
->listContent();
if (is_array($list)) {
foreach ($list as $file) {
$files[] = $file['filename'];
}
$archiver
->extractList($files, $config_sync_directory);
}
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']);
file_put_contents($config_sync_directory . '/core.extension.yml', Yaml::encode($core_extension));
}
}
}
protected abstract function getConfigTarball();
protected function installParameters() {
$parameters = parent::installParameters();
unset($parameters['forms']['install_configure_form']['site_name']);
unset($parameters['forms']['install_configure_form']['site_mail']);
unset($parameters['forms']['install_configure_form']['enable_update_status_module']);
unset($parameters['forms']['install_configure_form']['enable_update_status_emails']);
return $parameters;
}
public function testConfigSync() {
$change_list = $this
->configImporter()
->getStorageComparer()
->getChangelist();
$expected = [
'create' => [],
'update' => [
'system.mail',
],
'delete' => [],
'rename' => [],
];
$this
->assertEquals($expected, $change_list);
}
protected function setUpProfile() {
if ($this->existingSyncDirectory) {
$edit = [
'profile' => SelectProfileForm::CONFIG_INSTALL_PROFILE_KEY,
];
$this
->submitForm($edit, $this->translations['Save and continue']);
}
else {
parent::setUpProfile();
}
}
}