function EnableDisableTest::assertSuccessfulDisableAndUninstall

Disables and uninstalls a module and asserts that it was done correctly.

Parameters

string $module: The name of the module to disable and uninstall.

1 call to EnableDisableTest::assertSuccessfulDisableAndUninstall()
EnableDisableTest::testEnableDisable in drupal/core/modules/system/lib/Drupal/system/Tests/Module/EnableDisableTest.php
Tests that all core modules can be enabled, disabled and uninstalled.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Module/EnableDisableTest.php, line 174
Definition of Drupal\system\Tests\Module\EnableDisableTest.

Class

EnableDisableTest
Tests functionality for enabling and disabling modules.

Namespace

Drupal\system\Tests\Module

Code

function assertSuccessfulDisableAndUninstall($module) {

  // Disable the module.
  $edit = array();
  $edit['modules[Core][' . $module . '][enable]'] = FALSE;
  $this
    ->drupalPost('admin/modules', $edit, t('Save configuration'));
  $this
    ->assertText(t('The configuration options have been saved.'), 'Modules status has been updated.');
  $this
    ->assertModules(array(
    $module,
  ), FALSE);

  // Check that the appropriate hook was fired and the appropriate log
  // message appears.
  $this
    ->assertText(t('hook_modules_disabled fired for @module', array(
    '@module' => $module,
  )));
  $this
    ->assertLogMessage('system', "%module module disabled.", array(
    '%module' => $module,
  ), WATCHDOG_INFO);

  //  Check that the module's database tables still exist.
  $this
    ->assertModuleTablesExist($module);

  //  Check that the module's config files still exist.
  $this
    ->assertModuleConfig($module);

  // Uninstall the module.
  $edit = array();
  $edit['uninstall[' . $module . ']'] = $module;
  $this
    ->drupalPost('admin/modules/uninstall', $edit, t('Uninstall'));
  $this
    ->drupalPost(NULL, NULL, t('Uninstall'));
  $this
    ->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.');
  $this
    ->assertModules(array(
    $module,
  ), FALSE);

  // Check that the appropriate hook was fired and the appropriate log
  // message appears. (But don't check for the log message if the dblog
  // module was just uninstalled, since the {watchdog} table won't be there
  // anymore.)
  $this
    ->assertText(t('hook_modules_uninstalled fired for @module', array(
    '@module' => $module,
  )));
  if ($module != 'dblog') {
    $this
      ->assertLogMessage('system', "%module module uninstalled.", array(
      '%module' => $module,
    ), WATCHDOG_INFO);
  }

  // Check that the module's database tables no longer exist.
  $this
    ->assertModuleTablesDoNotExist($module);

  // Check that the module's config files no longer exist.
  $this
    ->assertNoModuleConfig($module);
}