You are here

public function SimpleLdapUserRegistrationTestCase::testRegistrationWithEmailVerification in Simple LDAP 7.2

Same name and namespace in other branches
  1. 7 simple_ldap_user/simple_ldap_user.test \SimpleLdapUserRegistrationTestCase::testRegistrationWithEmailVerification()

Tests user registration with email verification.

File

simple_ldap_user/simple_ldap_user.test, line 669
Tests for Simple LDAP User module.

Class

SimpleLdapUserRegistrationTestCase

Code

public 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, t('Registration page is inaccessible when only administrators can create accounts.'));

  // Allow registration by site visitors without administrator approvial.
  variable_set('user_register', USER_REGISTER_VISITORS);
  $edit = $this
    ->formData($name, $mail);
  $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.'));
  $accounts = user_load_multiple(array(), array(
    'name' => $name,
    'mail' => $mail,
  ));
  $new_user = reset($accounts);
  $this
    ->assertTrue($new_user->status, t('New account is active after registration.'));
  $ldap_user = new SimpleLdapUser($name);
  $this
    ->assertTrue($ldap_user->exists, t('New account was provisioned to LDAP.'));

  // Cleanup.
  $ldap_user
    ->delete();

  // Allow registration by site visitors, but require administrator approval.
  variable_set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
  $edit = $this
    ->formData($name, $mail);
  $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, t('New account is blocked until approved by an administrator.'));
  $ldap_user = new SimpleLdapUser($name);
  $this
    ->assertTrue($ldap_user->exists, t('New account was provisioned to LDAP.'));

  // Cleanup.
  $ldap_user
    ->delete();
}