1 user.test UserRegistrationTestCase::testRegistrationWithoutEmailVerification()

File

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

Class

UserRegistrationTestCase

Code

function testRegistrationWithoutEmailVerification() {
  $config = config('system.core');

  // Don't require email verification.
  $config->set('user_email_verification', FALSE)->save();

  // Allow registration by site visitors without administrator approval.
  $config->set('user_register', USER_REGISTER_VISITORS)->save();
  $edit = array();
  $edit['name'] = $name = $this->randomName();
  $edit['mail'] = $mail = $edit['name'] . '@example.com';
  $edit['pass'] = $new_pass = $this->randomName();
  $this->backdropPost('user/register', $edit, t('Create new account'));
  $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
  $new_user = reset($accounts);
  $this->assertText(t('Registration successful. You are now logged in.'), 'Users are logged in after registering.');
  $this->backdropLogout();

  // Allow registration by site visitors, but require administrator approval.
  $config->set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save();
  $edit = array();
  $edit['name'] = $name = $this->randomName();
  $edit['mail'] = $mail = $edit['name'] . '@example.com';
  $edit['pass'] = $pass = $this->randomName();
  $this->backdropPost('user/register', $edit, t('Create new account'));
  $this->assertText(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.'), 'Users are notified of pending approval');

  // Try to login before administrator approval.
  $auth = array(
    'name' => $name,
    'pass' => $pass,
  );
  $this->backdropPost('user/login', $auth, t('Log in'));
  $this->assertText(t('The account for @name has not been activated or is blocked.', array('@name' => $name)), 'User cannot login yet.');

  // Activate the new account.
  $accounts = user_load_multiple(array(), array('name' => $name, 'mail' => $mail));
  $new_user = reset($accounts);
  $admin_user = $this->backdropCreateUser(array('administer users'));
  $this->backdropLogin($admin_user);
  $edit = array(
    'status' => 1,
  );
  $this->backdropPost('user/' . $new_user->uid . '/edit', $edit, t('Save'));
  $this->backdropLogout();

  // Login after administrator approval.
  $this->backdropPost('user/login', $auth, t('Log in'));
  $this->assertText(t('Member for'), 'User can log in after administrator approval.');
}