You are here

function UserRegistrationTestCase::testRegistrationWithEmailVerification in Drupal 7

File

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

Class

UserRegistrationTestCase
@file Tests for user.module.

Code

function testRegistrationWithEmailVerification() {

  // Require e-mail verification.
  variable_set('user_email_verification', TRUE);

  // Set registration to administrator only.
  variable_set('user_register', USER_REGISTER_ADMINISTRATORS_ONLY);
  $this
    ->drupalGet('user/register');
  $this
    ->assertResponse(403, 'Registration page is inaccessible when only administrators can create accounts.');

  // Allow registration by site visitors without administrator approval.
  variable_set('user_register', USER_REGISTER_VISITORS);
  $edit = array();
  $edit['name'] = $name = $this
    ->randomName();
  $edit['mail'] = $mail = $edit['name'] . '@example.com';
  $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.'), 'User registered successfully.');
  $accounts = user_load_multiple(array(), array(
    'name' => $name,
    'mail' => $mail,
  ));
  $new_user = reset($accounts);
  $this
    ->assertTrue($new_user->status, 'New account is active after registration.');

  // Allow registration by site visitors, but require administrator approval.
  variable_set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
  $edit = array();
  $edit['name'] = $name = $this
    ->randomName();
  $edit['mail'] = $mail = $edit['name'] . '@example.com';
  $this
    ->drupalPost('user/register', $edit, t('Create new account'));
  $accounts = user_load_multiple(array(), array(
    'name' => $name,
    'mail' => $mail,
  ));
  $new_user = reset($accounts);
  $this
    ->assertFalse($new_user->status, 'New account is blocked until approved by an administrator.');
}