1 user.test UserCancelTestCase::testUserCancelInvalid()

Attempt invalid account cancellations.

File

core/modules/user/tests/user.test, line 761
Tests for user.module.

Class

UserCancelTestCase
Test cancelling a user.

Code

function testUserCancelInvalid() {
  config_set('system.core', 'user_cancel_method', 'user_cancel_reassign');

  // Create a user.
  $account = $this->backdropCreateUser(array('cancel account'));
  $this->backdropLogin($account);
  // Load real user object.
  $account = user_load($account->uid, TRUE);

  // Create a node.
  $node = $this->backdropCreateNode(array('uid' => $account->uid));

  // Attempt to cancel account.
  $this->backdropPost('user/' . $account->uid . '/edit', NULL, t('Cancel account'));

  // Confirm account cancellation.
  $timestamp = time();
  $this->backdropPost(NULL, NULL, t('Cancel account'));
  $this->assertText(t('A confirmation request to cancel your account has been sent to your email address.'), 'Account cancellation request mailed message displayed.');

  // Attempt bogus account cancellation request confirmation.
  $bogus_timestamp = $timestamp + 60;
  $this->backdropGet("user/$account->uid/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account->pass, $bogus_timestamp, $account->login, $account->uid, $account->mail));
  $this->assertText(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), 'Bogus cancelling request rejected.');
  $account = user_load($account->uid);
  $this->assertTrue($account->status == 1, 'User account was not canceled.');

  // Attempt expired account cancellation request confirmation.
  $bogus_timestamp = $timestamp - 86400 - 60;
  $this->backdropGet("user/$account->uid/cancel/confirm/$bogus_timestamp/" . user_pass_rehash($account->pass, $bogus_timestamp, $account->login, $account->uid, $account->mail));
  $this->assertText(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), 'Expired cancel account request rejected.');
  $accounts = user_load_multiple(array($account->uid), array('status' => 1));
  $this->assertTrue(reset($accounts), '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.');
}