You are here

public function ConfigImportUITest::testExtensionValidation in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/config/tests/src/Functional/ConfigImportUITest.php \Drupal\Tests\config\Functional\ConfigImportUITest::testExtensionValidation()
  2. 9 core/modules/config/tests/src/Functional/ConfigImportUITest.php \Drupal\Tests\config\Functional\ConfigImportUITest::testExtensionValidation()

Tests config importer cannot uninstall extensions which are depended on.

See also

\Drupal\Core\EventSubscriber\ConfigImportSubscriber

File

core/modules/config/tests/src/Functional/ConfigImportUITest.php, line 504

Class

ConfigImportUITest
Tests the user interface for importing configuration.

Namespace

Drupal\Tests\config\Functional

Code

public function testExtensionValidation() {
  \Drupal::service('module_installer')
    ->install([
    'node',
  ]);
  \Drupal::service('theme_installer')
    ->install([
    'test_subtheme',
  ]);
  $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 = $this->container
    ->get('extension.list.module')
    ->getList();
  $this
    ->assertTrue(isset($module_data['node']->requires['text']), 'The Node module depends on the Text module.');
  unset($core['theme']['test_basetheme']);
  $theme_data = \Drupal::service('theme_handler')
    ->rebuildThemeData();
  $this
    ->assertTrue(isset($theme_data['test_subtheme']->requires['test_basetheme']), 'The Test Subtheme theme depends on the Test Basetheme 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
    ->drupalGet('admin/config/development/configuration');
  $this
    ->submitForm([], 'Import all');
  $this
    ->assertSession()
    ->pageTextContains('The configuration cannot be imported because it failed validation for the following reasons:');
  $this
    ->assertSession()
    ->pageTextContains('Unable to uninstall the Text module since the Node module is installed.');
  $this
    ->assertSession()
    ->pageTextContains('Unable to uninstall the Theme test base theme theme since the Theme test subtheme theme is installed.');
  $this
    ->assertSession()
    ->pageTextContains('Unable to install the does_not_exist module since it does not exist.');
  $this
    ->assertSession()
    ->pageTextContains('Unable to install the does_not_exist theme since it does not exist.');
}