You are here

function UserCancelTestCase::testUserCancelWithoutPermission in Drupal 7

Attempt to cancel account without permission.

File

modules/user/user.test, line 876
Tests for user.module.

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));
  $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.');
}