You are here

public function UninstallTest::testFailedInstallStatus in Drupal 10

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

Tests that a module which fails to install can still be uninstalled.

File

core/modules/system/tests/src/Functional/Module/UninstallTest.php, line 174

Class

UninstallTest
Tests the uninstallation of modules.

Namespace

Drupal\Tests\system\Functional\Module

Code

public function testFailedInstallStatus() {
  $account = $this
    ->drupalCreateUser([
    'administer modules',
  ]);
  $this
    ->drupalLogin($account);
  $message = 'Exception thrown when installing module_installer_config_test with an invalid configuration file.';
  try {
    $this->container
      ->get('module_installer')
      ->install([
      'module_installer_config_test',
    ]);
    $this
      ->fail($message);
  } catch (EntityMalformedException $e) {

    // Expected exception; just continue testing.
  }

  // Even though the module failed to install properly, its configuration
  // status is "enabled" and should still be available to uninstall.
  $this
    ->drupalGet('admin/modules/uninstall');
  $this
    ->assertSession()
    ->pageTextContains('Module installer config test');
  $edit['uninstall[module_installer_config_test]'] = TRUE;
  $this
    ->drupalGet('admin/modules/uninstall');
  $this
    ->submitForm($edit, 'Uninstall');
  $this
    ->submitForm([], 'Uninstall');
  $this
    ->assertSession()
    ->pageTextContains('The selected modules have been uninstalled.');
  $this
    ->assertSession()
    ->pageTextNotContains('Module installer config test');
}