function ConfigInstallWebTest::testPreExistingConfigInstall

Same name in other branches
  1. 8.9.x core/modules/config/tests/src/Functional/ConfigInstallWebTest.php \Drupal\Tests\config\Functional\ConfigInstallWebTest::testPreExistingConfigInstall()
  2. 10 core/modules/config/tests/src/Functional/ConfigInstallWebTest.php \Drupal\Tests\config\Functional\ConfigInstallWebTest::testPreExistingConfigInstall()
  3. 11.x 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 133

Class

ConfigInstallWebTest
Tests configuration objects before and after module install and uninstall.

Namespace

Drupal\Tests\config\Functional

Code

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->drupalGet('admin/modules');
    $this->submitForm([
        'modules[config_test][enable]' => TRUE,
        'modules[config_install_fail_test][enable]' => TRUE,
    ], 'Install');
    $this->assertSession()
        ->responseContains('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->drupalGet('admin/modules/uninstall');
    $this->submitForm([
        'uninstall[config_test]' => TRUE,
    ], 'Uninstall');
    $this->submitForm([], '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->drupalGet('admin/modules');
    $this->submitForm([
        'modules[config_install_fail_test][enable]' => TRUE,
    ], 'Install');
    $this->submitForm([], 'Continue');
    $this->assertSession()
        ->responseContains('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->drupalGet('admin/modules');
    $this->submitForm([
        'modules[config_install_fail_test][enable]' => TRUE,
    ], 'Install');
    $this->assertSession()
        ->responseContains('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->assertSession()
        ->responseContains('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());
    }
}

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