Error message

You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).

function UserCancelTestCase::testUserCancelWithoutPermission

Attempt to cancel account without permission.

File

modules/user/user.test, line 983

Class

UserCancelTestCase
Test cancelling a user.

Code

function testUserCancelWithoutPermission() {
 variable_set ('user_cancel_method', 'user_cancel_reassign');
 // Create a user.
 $account = $this->drupalCreateUser (array());
 $this->drupalLogin ($account);
 // Load real user object.
 $account = user_load ($account->uid, TRUE);
 // Create a node.
 $node = $this->drupalCreateNode (array(
 'uid' => $account->uid,
 ));
 // Attempt to cancel account.
 $this->drupalGet ('user/' . $account->uid . '/edit');
 $this->assertNoRaw (t ('Cancel account'), 'No cancel account button displayed.');
 // Attempt bogus account cancellation request confirmation.
 $timestamp = $account->login;
 $this->drupalGet ("user/{$account->uid}/cancel/confirm/{$timestamp}/" . user_pass_rehash ($account->pass , $timestamp, $account->login, $account->uid, $account->mail));
 $this->assertResponse (403, 'Bogus cancelling request rejected.');
 $account = user_load ($account->uid);
 $this->assertTrue ($account->status == 1, 'User account was not canceled.');
 // Confirm user's content has not been altered.
 $test_node = node_load ($node->nid, NULL, TRUE);
 $this->assertTrue ($test_node->uid == $account->uid && $test_node->status == 1, 'Node of the user has not been altered.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.