You are here

public function UninstallTest::testFailedInstallStatus in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Module/UninstallTest.php \Drupal\Tests\system\Functional\Module\UninstallTest::testFailedInstallStatus()
  2. 10 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 150

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
    ->assertText('Module installer config test');
  $edit['uninstall[module_installer_config_test]'] = TRUE;
  $this
    ->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
  $this
    ->drupalPostForm(NULL, NULL, t('Uninstall'));
  $this
    ->assertText(t('The selected modules have been uninstalled.'));
  $this
    ->assertNoText('Module installer config test');
}