You are here

function UserCancelTestCase::testUserBlock in Drupal 7

Disable account and keep all content.

File

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

Class

UserCancelTestCase
Test cancelling a user.

Code

function testUserBlock() {
  variable_set('user_cancel_method', 'user_cancel_block');

  // Create a user.
  $web_user = $this
    ->drupalCreateUser(array(
    'cancel account',
  ));
  $this
    ->drupalLogin($web_user);

  // Load real user object.
  $account = user_load($web_user->uid, TRUE);

  // Attempt to cancel account.
  $this
    ->drupalGet('user/' . $account->uid . '/edit');
  $this
    ->drupalPost(NULL, NULL, t('Cancel account'));
  $this
    ->assertText(t('Are you sure you want to cancel your account?'), 'Confirmation form to cancel account displayed.');
  $this
    ->assertText(t('Your account will be blocked and you will no longer be able to log in. All of your content will remain attributed to your user name.'), 'Informs that all content will be remain as is.');
  $this
    ->assertNoText(t('Select the method to cancel the account above.'), 'Does not allow user to select account cancellation method.');

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

  // Confirm account cancellation request.
  $this
    ->drupalGet("user/{$account->uid}/cancel/confirm/{$timestamp}/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid));
  $account = user_load($account->uid, TRUE);
  $this
    ->assertTrue($account->status == 0, 'User has been blocked.');

  // 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.");
}