View source
<?php
class EnableCoreModuleTest extends DrupalTestCase {
function get_info() {
return array(
'name' => t('Enable core modules'),
'desc' => 'Enables all core modules by POST - looks for error messages, confirms table creation, etc.',
'group' => 'Modules',
);
}
function testEnableCoreModules() {
$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',
);
$enabled_modules = module_list(true, false);
$web_user = $this
->drupalCreateUserRolePerm(array(
'access administration pages',
'administer site configuration',
));
$this
->drupalLoginUser($web_user);
$edit = array();
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'));
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'));
}
include_once './includes/install.inc';
foreach ($modules_to_enable as $module) {
if (!in_array($module, $enabled_modules)) {
module_disable(array(
$module,
));
drupal_uninstall_module($module);
}
}
drupal_clear_css_cache();
drupal_clear_js_cache();
}
}
class EnableModuleWithoutDependencyTest extends DrupalTestCase {
function get_info() {
return array(
'name' => t('Enable module without required dependencies'),
'desc' => 'Attempts to enable the forum module without enabling dependencies.',
'group' => 'Modules',
);
}
function testEnableWithoutDependency() {
$current_modules = module_list(true, false);
foreach ($current_modules as $module) {
if (!in_array($module, drupal_required_modules())) {
$this
->drupalModuleDisable($module);
}
}
$web_user = $this
->drupalCreateUserRolePerm(array(
'access administration pages',
'administer site configuration',
));
$this
->drupalLoginUser($web_user);
$edit = array(
'status[forum]' => 'forum',
);
$this
->drupalPost('admin/build/modules/list/confirm', $edit, 'Save configuration');
$this
->assertWantedRaw(t('Some required modules must be enabled'), t('Make sure the dependency error is shown'));
$this
->assertFalse(module_exists('forum'), t('Check to make sure that the module has not somehow become enabled'));
}
}
class DisableUninstallCoreModuleTest extends DrupalTestCase {
function get_info() {
return array(
'name' => t('Disable/uninstall core modules'),
'desc' => 'Disables and uninstalls core modules, ensures that that tables are properly deleted, no error messages are shown, etc.',
'group' => 'Modules',
);
}
function testDisableUninstallCoreModules() {
$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',
);
$enabled_modules = module_list(true, false);
foreach ($enabled_modules as $module) {
if (in_array($module, $modules_to_test)) {
unset($modules_to_test[array_search($module, $modules_to_test)]);
}
}
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);
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'));
}
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');
$this->_browser
->clickSubmit(t('Uninstall'));
$this
->assertWantedRaw(t('The selected modules have been uninstalled.'), 'Check to ensure that the modules have been removed');
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();
}
}