You are here

function EnableCoreModuleTest::testEnableCoreModules in SimpleTest 6

File

tests/modules_system.test, line 11

Class

EnableCoreModuleTest

Code

function testEnableCoreModules() {

  // Get a list of the modules to enable
  $modules_to_enable = array(
    'aggregator',
    'blog',
    'blogapi',
    'book',
    'color',
    'comment',
    'contact',
    'dblog',
    'forum',
    'help',
    'locale',
    'menu',
    'openid',
    'path',
    'php',
    'ping',
    'poll',
    'profile',
    'search',
    'statistics',
    'syslog',
    'taxonomy',
    'throttle',
    'tracker',
    'translation',
    'trigger',
    'update',
    'upload',
  );

  // Get a list of the currently enabled modules
  $enabled_modules = module_list(true, false);
  $web_user = $this
    ->drupalCreateUserRolePerm(array(
    'access administration pages',
    'administer site configuration',
  ));
  $this
    ->drupalLoginUser($web_user);
  $edit = array();

  // We temporarily disable any modules we're testing so that we can re-enable them for testing
  foreach ($modules_to_enable as $module) {
    if (module_exists($module)) {
      $this
        ->drupalModuleDisable($module);
    }
    $edit['status[' . $module . ']'] = $module;
  }
  $this
    ->drupalPost('admin/build/modules/list/confirm', $edit, 'Save configuration');
  $this
    ->assertWantedRaw(t('The configuration options have been saved.'), t('Ensure that the module status has been updated'));

  // Now, we check the tables for each module
  // We also refresh the module list and make sure the modules are enabled
  module_list(true, false);
  foreach ($modules_to_enable as $module) {
    $cur_schema = drupal_get_schema_unprocessed($module);
    $tables = is_array($cur_schema) ? array_keys($cur_schema) : array();
    foreach ($tables as $table) {
      $this
        ->assertTrue(db_table_exists($table), t('Make sure that the database table for the module exists'));
    }
    $this
      ->assertTrue(module_exists($module), t('Check to see that the module is actually enabled'));
  }

  // Disable/uninstall all the modules that have been installed by this process
  // We first need to refresh the module list
  include_once './includes/install.inc';
  foreach ($modules_to_enable as $module) {

    // We uninstall the modules that weren't already enabled
    if (!in_array($module, $enabled_modules)) {
      module_disable(array(
        $module,
      ));
      drupal_uninstall_module($module);
    }
  }
  drupal_clear_css_cache();
  drupal_clear_js_cache();
}