function DependencyTest::testUninstallDependents

Tests attempting to uninstall a module that has installed dependents.

File

core/modules/system/tests/src/Functional/Module/DependencyTest.php, line 196

Class

DependencyTest
Enable module without dependency enabled.

Namespace

Drupal\Tests\system\Functional\Module

Code

public function testUninstallDependents() {
  // Enable the forum module.
  $edit = [
    'modules[forum][enable]' => 'forum',
  ];
  $this->drupalPostForm('admin/modules', $edit, t('Install'));
  $this->drupalPostForm(NULL, [], t('Continue'));
  $this->assertModules([
    'forum',
  ], TRUE);
  // Check that the comment module cannot be uninstalled.
  $this->drupalGet('admin/modules/uninstall');
  $checkbox = $this->xpath('//input[@type="checkbox" and @name="uninstall[comment]" and @disabled="disabled"]');
  $this->assertCount(1, $checkbox, 'Checkbox for uninstalling the comment module is disabled.');
  // Delete any forum terms.
  $vid = $this->config('forum.settings')
    ->get('vocabulary');
  // Ensure taxonomy has been loaded into the test-runner after forum was
  // enabled.
  \Drupal::moduleHandler()->load('taxonomy');
  $storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
  $terms = $storage->loadByProperties([
    'vid' => $vid,
  ]);
  $storage->delete($terms);
  // Uninstall the forum module, and check that taxonomy now can also be
  // uninstalled.
  $edit = [
    'uninstall[forum]' => 'forum',
  ];
  $this->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
  $this->drupalPostForm(NULL, NULL, t('Uninstall'));
  $this->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.');
  // Uninstall comment module.
  $edit = [
    'uninstall[comment]' => 'comment',
  ];
  $this->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
  $this->drupalPostForm(NULL, NULL, t('Uninstall'));
  $this->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.');
}

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