You are here

public function UserRegistrationPasswordTestCase::testLoginWithUrpLinkWhileBlocked in User registration password 7

Implements testLoginWithUrpLinkWhileBlocked().

File

tests/user_registrationpassword.test, line 188
Functionality tests for user_registrationpassword.module.

Class

UserRegistrationPasswordTestCase
Class UserRegistrationPasswordTestCase.

Code

public function testLoginWithUrpLinkWhileBlocked() {

  // Allow registration by site visitors without administrator
  // approval and set password during registration.
  variable_set('user_register', USER_REGISTER_VISITORS);

  // Disable e-mail verification.
  variable_set('user_email_verification', FALSE);

  // Prevent standard notification email to administrators and to user.
  variable_set('user_mail_register_pending_approval_notify', FALSE);

  // Set the registration variable to 2, register with pass, but require
  // confirmation.
  variable_set('user_registrationpassword_registration', USER_REGISTRATIONPASSWORD_VERIFICATION_PASS);
  $timestamp = REQUEST_TIME + 5000;

  // Register a new account.
  $edit = array();
  $edit['name'] = $name = $this
    ->randomName();
  $edit['mail'] = $mail = $edit['name'] . '@example.com';
  $edit['pass[pass1]'] = $new_pass = $this
    ->randomName();
  $edit['pass[pass2]'] = $new_pass;
  $pass = $new_pass;
  $this
    ->drupalPost('user/register', $edit, t('Create new account'));
  $this
    ->assertText(t('A welcome message with further instructions has been sent to your e-mail address.'), t('User registered successfully.'));

  // Load the new user.
  $accounts = user_load_multiple(array(), array(
    'name' => $name,
    'mail' => $mail,
    'status' => 0,
  ));
  $account = reset($accounts);

  // Attempt to use the activation link.
  $this
    ->drupalGet("user/registrationpassword/{$account->uid}/{$timestamp}/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid));
  $this
    ->assertText(t('You have just used your one-time login link. Your account is now active and you are authenticated.'));

  // Logout the user.
  $this
    ->drupalLogout();

  // Block the user.
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer users',
  ));
  $this
    ->drupalLogin($admin_user);
  $this
    ->drupalGet('admin/people');
  $editblock = array();
  $editblock['operation'] = 'block';
  $editblock['accounts[' . $account->uid . ']'] = TRUE;
  $this
    ->drupalPost('admin/people', $editblock, t('Update'));

  // Logout the administrator.
  $this
    ->drupalLogout();

  // Load the new user.
  $accounts_blocked = user_load_multiple(array(), array(
    'name' => $name,
    'mail' => $mail,
    'status' => 0,
  ));
  $account_blocked = reset($accounts_blocked);

  // Confirm status is really blocked.
  $this
    ->assertEqual($account_blocked->status, 0, 'User blocked');

  // Then try to use the link.
  $this
    ->drupalGet("user/registrationpassword/{$account->uid}/{$timestamp}/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid));
  $this
    ->assertText(t('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.'));

  // Try to request a new activation e-mail.
  $edit2['name'] = $edit['name'];
  $this
    ->drupalPost('user/password', $edit2, t('E-mail new password'));
  $this
    ->assertText(t('Sorry, !name is not recognized as a user name or an e-mail address.', array(
    '!name' => $edit2['name'],
  )), t('Password rest form failed correctly.'));
}