diff --git a/modules/user/user.pages.inc b/modules/user/user.pages.inc index 4c4a02971adb146c78575ac556d5c58d609f6b2b..e069f7fd73b64531e45d47eb33c1cdd9c8229cbc 100644 --- a/modules/user/user.pages.inc +++ b/modules/user/user.pages.inc @@ -302,13 +302,19 @@ function user_profile_form_submit($form, &$form_state) { // Remove unneeded values. form_state_values_clean($form_state); + // Before updating the account entity, keep an unchanged copy for use with + // user_save() later. This is necessary for modules implementing the user + // hooks to be able to react on changes by comparing the values of $account + // and $edit. + $account_unchanged = clone $account; + entity_form_submit_build_entity('user', $account, $form, $form_state); // Populate $edit with the properties of $account, which have been edited on // this form by taking over all values, which appear in the form values too. $edit = array_intersect_key((array) $account, $form_state['values']); - user_save($account, $edit, $category); + user_save($account_unchanged, $edit, $category); $form_state['values']['uid'] = $account->uid; if ($category == 'account' && !empty($edit['pass'])) { diff --git a/modules/user/user.test b/modules/user/user.test index 0fa3749afaadbfadb20f326e4cb6f337d0fc90d9..cbde24b713e6f106d08a0625c996daa01211e652 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -1084,6 +1084,26 @@ class UserAdminTestCase extends DrupalWebTestCase { $this->drupalPost('admin/people', $edit, t('Update')); $account = user_load($user_c->uid, TRUE); $this->assertEqual($account->status, 0, 'User C blocked'); + + // Test unblocking of a user from /admin/people page and sending of activation mail + $editunblock = array(); + $editunblock['operation'] = 'unblock'; + $editunblock['accounts[' . $account->uid . ']'] = TRUE; + $this->drupalPost('admin/people', $editunblock, t('Update')); + $account = user_load($user_c->uid, TRUE); + $this->assertEqual($account->status, 1, 'User C unblocked'); + $this->assertMail("to", $account->mail, "Activation mail sent to user C"); + + // Test blocking and unblocking another user from /user/[uid]/edit form and sending of activation mail + $user_d = $this->drupalCreateUser(array()); + $account1 = user_load($user_d->uid, TRUE); + $this->drupalPost('user/' . $account1->uid . '/edit', array('status' => 0), t('Save')); + $account1 = user_load($user_d->uid, TRUE); + $this->assertEqual($account1->status, 0, 'User D blocked'); + $this->drupalPost('user/' . $account1->uid . '/edit', array('status' => TRUE), t('Save')); + $account1 = user_load($user_d->uid, TRUE); + $this->assertEqual($account1->status, 1, 'User D unblocked'); + $this->assertMail("to", $account1->mail, "Activation mail sent to user D"); } }