diff --git a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php index 70623bd..2f18b3b 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php @@ -170,8 +170,11 @@ function testUserBlock() { $account = user_load($account->uid, TRUE); $this->assertTrue($account->status == 0, 'User has been blocked.'); - // Confirm user is logged out. - $this->assertNoText($account->name, 'Logged out.'); + // Confirm that we didn't break Batch API by destroying the session. + $this->assertNoText(t('No active batch.'), "Batch API wasn't interrupted by the account cancellation."); + + // Confirm that the confirmation message made it through to the end user. + $this->assertRaw(t('%name has been disabled.', array('%name' => $account->name)), "Confirmation message displayed to user."); } /** @@ -214,8 +217,11 @@ function testUserBlockUnpublish() { $test_node = node_revision_load($node->vid); $this->assertTrue($test_node->status == 0, 'Node revision of the user has been unpublished.'); - // Confirm user is logged out. - $this->assertNoText($account->name, 'Logged out.'); + // Confirm that we didn't break Batch API by destroying the session. + $this->assertNoText(t('No active batch.'), "Batch API wasn't interrupted by the account cancellation."); + + // Confirm that the confirmation message made it through to the end user. + $this->assertRaw(t('%name has been disabled.', array('%name' => $account->name)), "Confirmation message displayed to user."); } /** @@ -265,8 +271,11 @@ function testUserAnonymize() { $test_node = node_load($revision_node->nid, TRUE); $this->assertTrue(($test_node->uid != 0 && $test_node->status == 1), "Current revision of the user's node was not attributed to anonymous user."); - // Confirm that user is logged out. - $this->assertNoText($account->name, 'Logged out.'); + // Confirm that we didn't break Batch API by destroying the session. + $this->assertNoText(t('No active batch.'), "Batch API wasn't interrupted by the account cancellation."); + + // Confirm that the confirmation message made it through to the end user. + $this->assertRaw(t('%name has been deleted.', array('%name' => $account->name)), "Confirmation message displayed to user."); } /** @@ -329,8 +338,11 @@ function testUserDelete() { $this->assertTrue(node_load($revision_node->nid, TRUE), "Current revision of the user's node was not deleted."); $this->assertFalse(comment_load($comment->id()), 'Comment of the user has been deleted.'); - // Confirm that user is logged out. - $this->assertNoText($account->name, 'Logged out.'); + // Confirm that we didn't break Batch API by destroying the session. + $this->assertNoText(t('No active batch.'), "Batch API wasn't interrupted by the account cancellation."); + + // Confirm that the confirmation message made it through to the end user. + $this->assertRaw(t('%name has been deleted.', array('%name' => $account->name)), "Confirmation message displayed to user."); } /** diff --git a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php.rej b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php.rej new file mode 100644 index 0000000..f8a6a57 --- /dev/null +++ b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php.rej @@ -0,0 +1,15 @@ +diff a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php (rejected hunks) +@@ -331,8 +340,11 @@ class UserCancelTest extends WebTestBase { + $this->assertTrue(node_load($revision_node->nid, TRUE), "Current revision of the user's node was not deleted."); + $this->assertFalse(comment_load($comment->cid), 'Comment of the user has been deleted.'); + +- // Confirm that user is logged out. +- $this->assertNoText($account->name, 'Logged out.'); ++ // Confirm that we didn't break Batch API by destroying the session. ++ $this->assertNoText(t('No active batch.'), "Batch API wasn't interrupted by the account cancellation."); ++ ++ // Confirm that the confirmation message made it through to the end user. ++ $this->assertRaw(t('%name has been deleted.', array('%name' => $account->name)), "Confirmation message displayed to user."); + } + + /** diff --git a/core/modules/user/user.module b/core/modules/user/user.module index bdf5862..161d23c 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1590,6 +1590,14 @@ function user_cancel($edit, $uid, $method) { array('_user_cancel', array($edit, $account, $method)), ), ); + + // After cancelling account, ensure that user is logged out. + if ($account->uid == $user->uid) { + // Batch API stores data in the session, so use the finished operation to + // manipulate the current user's session id. + $batch['finished'] = '_user_cancel_session_regenerate'; + } + batch_set($batch); // Batch processing is either handled via Form API or has to be invoked @@ -1633,10 +1641,12 @@ function _user_cancel($edit, $account, $method) { break; } - // After cancelling account, ensure that user is logged out. + // After cancelling account, ensure that user is logged out. We can't destroy + // their session though, as we might have information in it, and we can't + // regenerate it because batch API uses the session ID, we will regenerate it + // in _user_cancel_session_regenerate(). if ($account->uid == $user->uid) { - // Destroy the current session, and reset $user to the anonymous user. - session_destroy(); + $user = drupal_anonymous_user(); } // Clear the cache for anonymous users. @@ -1644,6 +1654,17 @@ function _user_cancel($edit, $account, $method) { } /** + * Finished batch processing callback for cancelling a user account. + * + * @see user_cancel() + */ +function _user_cancel_session_regenerate() { + // Regenerate the users session instead of calling session_destroy() as we + // want to preserve any messages that might have been set. + drupal_session_regenerate(); +} + +/** * Delete a user. * * @param $uid