1 user.test UserCancelTestCase::testUserBlock()

Disable account and keep all content.

File

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

Class

UserCancelTestCase
Test cancelling a user.

Code

function testUserBlock() {
  config_set('system.core', 'user_cancel_method', 'user_cancel_block');

  // Create a user.
  $web_user = $this->backdropCreateUser(array('cancel account'));
  $this->backdropLogin($web_user);

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

  // Attempt to cancel account.
  $this->backdropGet('user/' . $account->uid . '/edit');
  $this->backdropPost(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->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.');

  // Confirm account cancellation request.
  $this->backdropGet("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.');
}