function DisableUninstallCoreModuleTest::testDisableUninstallCoreModules in SimpleTest 6
File
- tests/
modules_system.test, line 138
Class
Code
function testDisableUninstallCoreModules() {
// Get a list of the modules to test
$modules_to_test = 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);
// We don't want to test any modules that are already enabled, since that would involve a loss of data
foreach ($enabled_modules as $module) {
if (in_array($module, $modules_to_test)) {
unset($modules_to_test[array_search($module, $modules_to_test)]);
}
}
// Enable all the modules that are not already enabled
include_once './includes/install.inc';
module_enable($modules_to_test);
drupal_install_modules($modules_to_test);
$web_user = $this
->drupalCreateUserRolePerm(array(
'access administration pages',
'administer site configuration',
));
$this
->drupalLoginUser($web_user);
// Disable/uninstall the given modules: we keep every other module enabled
// We do this loop because for each level of dependency, we need one more request
while (count(array_diff(module_list(true, false), $enabled_modules)) > 0) {
$edit = array();
foreach ($modules_to_test as $module) {
$edit['status[' . $module . ']'] = 0;
}
foreach ($enabled_modules as $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, lets make sure the modules are truly disabled and then try to uninstall them
module_list(true, false);
$edit = array();
foreach ($modules_to_test as $module) {
$this
->assertFalse(module_exists($module), t('Make sure the module has been disabled'));
if (module_hook($module, 'uninstall')) {
$edit['uninstall[' . $module . ']'] = $module;
}
}
$this
->drupalPost('admin/build/modules/uninstall/confirm', $edit, 'Uninstall');
// We need to confirm this by clicking again
$this->_browser
->clickSubmit(t('Uninstall'));
$this
->assertWantedRaw(t('The selected modules have been uninstalled.'), 'Check to ensure that the modules have been removed');
// Now, we check the tables for each module
foreach ($modules_to_test as $module) {
$cur_schema = drupal_get_schema_unprocessed($module);
$tables = is_array($cur_schema) ? array_keys($cur_schema) : array();
foreach ($tables as $table) {
$this
->assertFalse(db_table_exists($table), t('Ensure that the database table has been properly removed'));
}
}
drupal_clear_css_cache();
drupal_clear_js_cache();
}