You are here

public function ConfigInstallWebTest::testPreExistingConfigInstall in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/config/src/Tests/ConfigInstallWebTest.php \Drupal\config\Tests\ConfigInstallWebTest::testPreExistingConfigInstall()

Tests pre-existing configuration detection.

File

core/modules/config/src/Tests/ConfigInstallWebTest.php, line 123
Contains \Drupal\config\Tests\ConfigInstallWebTest.

Class

ConfigInstallWebTest
Tests installation and removal of configuration objects in install, disable and uninstall functionality.

Namespace

Drupal\config\Tests

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
    ->drupalPostForm('admin/modules', array(
    'modules[Testing][config_test][enable]' => TRUE,
    'modules[Testing][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', array(
    'uninstall[config_test]' => TRUE,
  ), t('Uninstall'));
  $this
    ->drupalPostForm(NULL, array(), 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', array(
    'modules[Testing][config_install_fail_test][enable]' => TRUE,
  ), t('Install'));
  $this
    ->drupalPostForm(NULL, array(), 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', array(
    'modules[Testing][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));
  $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_handler')
      ->install([
      'config_clash_test_theme',
    ]);
    $this
      ->fail('Expected PreExistingConfigException not thrown.');
  } catch (PreExistingConfigException $e) {
    $this
      ->assertEqual($e
      ->getExtension(), 'config_clash_test_theme');
    $this
      ->assertEqual($e
      ->getConfigObjects(), [
      StorageInterface::DEFAULT_COLLECTION => [
        'config_test.dynamic.dotted.default',
      ],
      'language.fr' => [
        'config_test.dynamic.dotted.default',
      ],
    ]);
    $this
      ->assertEqual($e
      ->getMessage(), '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');
  }
}