Commit fb125851 authored by Dries's avatar Dries

- Patch #306027 by agentrickard, catch, dereine, Dave Reid, drewish, et al:...

- Patch #306027 by agentrickard, catch, dereine, Dave Reid, drewish, et al: automatically clean the {role_permission} table when modules are uninstalled.
parent 8eb8dcc8
......@@ -77,3 +77,33 @@ class ModuleUnitTest extends DrupalWebTestCase {
$this->assertIdentical($expected_values, module_list(FALSE, TRUE), t('@condition: module_list() returns correctly sorted results', array('@condition' => $condition)));
}
}
/**
* Unit tests for module uninstallation and related hooks.
*/
class ModuleUninstallTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => t('Module uninstallation'),
'description' => t('Checks module uninstallation'),
'group' => t('Module'),
);
}
function setUp() {
parent::setUp('module_test', 'user');
}
/**
* Tests the hook_modules_uninstalled() of the user module.
*/
function testUserPermsUninstalled() {
// Uninstalls the module_test module, so hook_modules_uninstalled()
// is executed.
drupal_uninstall_modules(array('module_test'));
// Are the perms defined by module_test removed from {role_permission}.
$count = db_query("SELECT COUNT(rid) FROM {role_permission} WHERE permission = :perm", array(':perm' => 'module_test perm'))->fetchField();
$this->assertEqual(0, $count, t('Permissions were all removed.'));
}
}
; $Id$
name = "Module test"
description = "Support module for module system testing."
package = Testing
version = VERSION
core = 7.x
files[] = module_test.module
hidden = TRUE
<?php
// $Id$
/**
* Implement hook_perm().
*/
function module_test_perm() {
return array(
'module_test perm' => t('example perm for module_test module'),
);
}
......@@ -149,6 +149,12 @@ class EnableDisableTestCase extends ModuleTestCase {
$this->assertModules(array('aggregator'), FALSE);
$this->assertTableCount('aggregator', FALSE);
$this->assertLogMessage('system', "%module module uninstalled.", array('%module' => 'aggregator'), WATCHDOG_INFO);
// Reinstall (and enable) aggregator module.
$edit = array();
$edit['modules[Core][aggregator][enable]'] = 'aggregator';
$this->drupalPost('admin/build/modules', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
}
}
......
......@@ -945,3 +945,18 @@ function user_modules_installed($modules) {
}
}
}
/**
* Implement hook_modules_uninstalled().
*/
function user_modules_uninstalled($modules) {
$permissions = array();
foreach ($modules as $module) {
$permissions = array_merge($permissions, array_keys(module_invoke($module, 'perm')));
}
if (!empty($permissions)) {
db_delete('role_permission')
->condition('permission', $permissions, 'IN')
->execute();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment