function UninstallTest::testFailedInstallStatus

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Module/UninstallTest.php \Drupal\Tests\system\Functional\Module\UninstallTest::testFailedInstallStatus()
  2. 8.9.x core/modules/system/tests/src/Functional/Module/UninstallTest.php \Drupal\Tests\system\Functional\Module\UninstallTest::testFailedInstallStatus()
  3. 11.x 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 190

Class

UninstallTest
Tests the uninstallation of modules.

Namespace

Drupal\Tests\system\Functional\Module

Code

public function testFailedInstallStatus() : void {
    $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');
}

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