public function ConfigInstallWebTest::testPreExistingConfigInstall in Drupal 8
Same name and namespace in other branches
- 9 core/modules/config/tests/src/Functional/ConfigInstallWebTest.php \Drupal\Tests\config\Functional\ConfigInstallWebTest::testPreExistingConfigInstall()
Tests pre-existing configuration detection.
File
- core/
modules/ config/ tests/ src/ Functional/ ConfigInstallWebTest.php, line 131
Class
- ConfigInstallWebTest
- Tests installation and removal of configuration objects in install, disable and uninstall functionality.
Namespace
Drupal\Tests\config\FunctionalCode
public function testPreExistingConfigInstall() {
$this
->drupalLogin($this->adminUser);
// Try to install config_install_fail_test and config_test. Doing this
// will install the config_test module first because it is a dependency of
// config_install_fail_test.
// @see \Drupal\system\Form\ModulesListForm::submitForm()
$this
->drupalPostForm('admin/modules', [
'modules[config_test][enable]' => TRUE,
'modules[config_install_fail_test][enable]' => TRUE,
], t('Install'));
$this
->assertRaw('Unable to install Configuration install fail test, <em class="placeholder">config_test.dynamic.dotted.default</em> already exists in active configuration.');
// Uninstall the config_test module to test the confirm form.
$this
->drupalPostForm('admin/modules/uninstall', [
'uninstall[config_test]' => TRUE,
], t('Uninstall'));
$this
->drupalPostForm(NULL, [], t('Uninstall'));
// Try to install config_install_fail_test without selecting config_test.
// The user is shown a confirm form because the config_test module is a
// dependency.
// @see \Drupal\system\Form\ModulesListConfirmForm::submitForm()
$this
->drupalPostForm('admin/modules', [
'modules[config_install_fail_test][enable]' => TRUE,
], t('Install'));
$this
->drupalPostForm(NULL, [], t('Continue'));
$this
->assertRaw('Unable to install Configuration install fail test, <em class="placeholder">config_test.dynamic.dotted.default</em> already exists in active configuration.');
// Test that collection configuration clashes during a module install are
// reported correctly.
\Drupal::service('module_installer')
->install([
'language',
]);
$this
->rebuildContainer();
ConfigurableLanguage::createFromLangcode('fr')
->save();
\Drupal::languageManager()
->getLanguageConfigOverride('fr', 'config_test.dynamic.dotted.default')
->set('label', 'Je suis Charlie')
->save();
$this
->drupalPostForm('admin/modules', [
'modules[config_install_fail_test][enable]' => TRUE,
], t('Install'));
$this
->assertRaw('Unable to install Configuration install fail test, <em class="placeholder">config_test.dynamic.dotted.default, language/fr/config_test.dynamic.dotted.default</em> already exist in active configuration.');
// Test installing a theme through the UI that has existing configuration.
// This relies on the fact the config_test has been installed and created
// the config_test.dynamic.dotted.default configuration and the translation
// override created still exists.
$this
->drupalGet('admin/appearance');
$url = $this
->xpath("//a[contains(@href,'config_clash_test_theme') and contains(@href,'/install?')]/@href")[0];
$this
->drupalGet($this
->getAbsoluteUrl($url
->getText()));
$this
->assertRaw('Unable to install config_clash_test_theme, <em class="placeholder">config_test.dynamic.dotted.default, language/fr/config_test.dynamic.dotted.default</em> already exist in active configuration.');
// Test installing a theme through the API that has existing configuration.
try {
\Drupal::service('theme_installer')
->install([
'config_clash_test_theme',
]);
$this
->fail('Expected PreExistingConfigException not thrown.');
} catch (PreExistingConfigException $e) {
$this
->assertEquals('config_clash_test_theme', $e
->getExtension());
$this
->assertEquals([
StorageInterface::DEFAULT_COLLECTION => [
'config_test.dynamic.dotted.default',
],
'language.fr' => [
'config_test.dynamic.dotted.default',
],
], $e
->getConfigObjects());
$this
->assertEquals('Configuration objects (config_test.dynamic.dotted.default, language/fr/config_test.dynamic.dotted.default) provided by config_clash_test_theme already exist in active configuration', $e
->getMessage());
}
}