You are here

public function DependencyTest::testUninstallDependents in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Module/DependencyTest.php \Drupal\Tests\system\Functional\Module\DependencyTest::testUninstallDependents()
  2. 9 core/modules/system/tests/src/Functional/Module/DependencyTest.php \Drupal\Tests\system\Functional\Module\DependencyTest::testUninstallDependents()

Tests attempting to uninstall a module that has installed dependents.

File

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

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
    ->drupalGet('admin/modules');
  $this
    ->submitForm($edit, 'Install');
  $this
    ->submitForm([], 'Continue');
  $this
    ->assertModules([
    'forum',
  ], TRUE);

  // Check that the comment module cannot be uninstalled.
  $this
    ->drupalGet('admin/modules/uninstall');
  $this
    ->assertSession()
    ->fieldDisabled('uninstall[comment]');

  // 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
    ->drupalGet('admin/modules/uninstall');
  $this
    ->submitForm($edit, 'Uninstall');
  $this
    ->submitForm([], 'Uninstall');
  $this
    ->assertSession()
    ->pageTextContains('The selected modules have been uninstalled.');

  // Uninstall comment module.
  $edit = [
    'uninstall[comment]' => 'comment',
  ];
  $this
    ->drupalGet('admin/modules/uninstall');
  $this
    ->submitForm($edit, 'Uninstall');
  $this
    ->submitForm([], 'Uninstall');
  $this
    ->assertSession()
    ->pageTextContains('The selected modules have been uninstalled.');
}