My custom module happens to create some data based on a new user being created and expects to be given a chance to remove that data via hook_user(). However, it appears that the simpletest module does not ever call the hook_user() when removing a user.
simpletest.module delete code:
while (sizeof($this->_cleanupUsers) > 0) {
$uid = array_pop($this->_cleanupUsers);
db_query('DELETE FROM {users} WHERE uid = %d', $uid);
db_query('DELETE FROM {users_roles} WHERE uid = %d', $uid);
db_query('DELETE FROM {authmap} WHERE uid = %d', $uid);
}
As compared to user.module user delete code:
if (arg(2) == 'delete') {
if ($edit['confirm']) {
db_query('DELETE FROM {users} WHERE uid = %d', $account->uid);
db_query('DELETE FROM {sessions} WHERE uid = %d', $account->uid);
db_query('DELETE FROM {users_roles} WHERE uid = %d', $account->uid);
db_query('DELETE FROM {authmap} WHERE uid = %d', $account->uid);
watchdog('user', t('Deleted user: %name %email.', array('%name' => theme('placeholder', $account->name), '%email' => theme('placeholder', '<'. $account->mail .'>'))), WATCHDOG_NOTICE);
drupal_set_message(t('The account has been deleted.'));
module_invoke_all('user', 'delete', $edit, $account);
drupal_goto('admin/user');
}
It would be great if the simpletest module could actually call user.module's code so that there is no duplication (and therefore potential for falling out of sync) of code. But, given the 'confirm' page, I'm not entirely sure what the best way to go about this would be.
I'm happy to help code a solution if others have good ideas about how best to go about it.
Cheers,
Justin
Comments
Comment #1
Thomas Ilsche commentedThe problem I see is that we do not have an $edit array available, even worse would be if a hook_user uses arg(0)! This is really bad, I wonder how other modules that require automatic deletion of users do this, any ideas?
I have commited a patch that at least deleted the sessions.
Comment #2
Rok Žlender commentedThis was fixed in changes to tearDown function in drpal_test_case.php.