You are here

public function ConfigImportUITest::testExtensionValidation in Zircon Profile 8

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

Tests config importer cannot uninstall extensions which are depended on.

See also

\Drupal\Core\EventSubscriber\ConfigImportSubscriber

File

core/modules/config/src/Tests/ConfigImportUITest.php, line 490
Contains \Drupal\config\Tests\ConfigImportUITest.

Class

ConfigImportUITest
Tests the user interface for importing/exporting configuration.

Namespace

Drupal\config\Tests

Code

public function testExtensionValidation() {
  \Drupal::service('module_installer')
    ->install([
    'node',
  ]);
  \Drupal::service('theme_handler')
    ->install([
    'bartik',
  ]);
  $this
    ->rebuildContainer();
  $sync = $this->container
    ->get('config.storage.sync');
  $this
    ->copyConfig($this->container
    ->get('config.storage'), $sync);
  $core = $sync
    ->read('core.extension');

  // Node depends on text.
  unset($core['module']['text']);
  $module_data = system_rebuild_module_data();
  $this
    ->assertTrue(isset($module_data['node']->requires['text']), 'The Node module depends on the Text module.');

  // Bartik depends on classy.
  unset($core['theme']['classy']);
  $theme_data = \Drupal::service('theme_handler')
    ->rebuildThemeData();
  $this
    ->assertTrue(isset($theme_data['bartik']->requires['classy']), 'The Bartik theme depends on the Classy theme.');

  // This module does not exist.
  $core['module']['does_not_exist'] = 0;

  // This theme does not exist.
  $core['theme']['does_not_exist'] = 0;
  $sync
    ->write('core.extension', $core);
  $this
    ->drupalPostForm('admin/config/development/configuration', array(), t('Import all'));
  $this
    ->assertText('The configuration cannot be imported because it failed validation for the following reasons:');
  $this
    ->assertText('Unable to uninstall the Text module since the Node module is installed.');
  $this
    ->assertText('Unable to uninstall the Classy theme since the Bartik theme is installed.');
  $this
    ->assertText('Unable to install the does_not_exist module since it does not exist.');
  $this
    ->assertText('Unable to install the does_not_exist theme since it does not exist.');
}