public function SimpleLdapUserRegistrationTestCase::testRegistrationWithoutEmailVerification in Simple LDAP 7
Same name and namespace in other branches
- 7.2 simple_ldap_user/simple_ldap_user.test \SimpleLdapUserRegistrationTestCase::testRegistrationWithoutEmailVerification()
Tests user registration without requiring email verification.
File
- simple_ldap_user/
simple_ldap_user.test, line 711 - Tests for Simple LDAP User module.
Class
Code
public function testRegistrationWithoutEmailVerification() {
// Don't require e-mail verification.
variable_set('user_email_verification', FALSE);
// Allow registration by site visitors without administrator approval.
variable_set('user_register', USER_REGISTER_VISITORS);
$edit = $this
->formData($name, $mail);
// Try entering a mismatching password.
$edit['pass[pass1]'] = '99999.0';
$edit['pass[pass2]'] = '99999';
$this
->drupalPost('user/register', $edit, t('Create new account'));
$this
->assertText(t('The specified passwords do not match.'), t('Typing mismatched passwords displays an error message.'));
// Enter a correct password.
$edit['pass[pass1]'] = $new_pass = $this
->randomName();
$edit['pass[pass2]'] = $new_pass;
$this
->drupalPost('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.'), t('Users are logged in after registering.'));
$this
->drupalLogout();
$ldap_user = new SimpleLdapUser($name);
$this
->assertTrue($ldap_user->exists, t('New account has been 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);
$edit['pass[pass1]'] = $pass = $this
->randomName();
$edit['pass[pass2]'] = $pass;
$this
->drupalPost('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.'), t('Users are notified of pending approval'));
$ldap_user = new SimpleLdapUser($name);
$this
->assertTrue($ldap_user->exists, t('New account has been provisioned to LDAP.'));
// Try to login before administrator approval.
$auth = array(
'name' => $name,
'pass' => $pass,
);
$this
->drupalPost('user/login', $auth, t('Log in'));
$this
->assertText(t('The username @name has not been activated or is blocked.', array(
'@name' => $name,
)), t('User cannot login yet.'));
// Activate the new account.
$accounts = user_load_multiple(array(), array(
'name' => $name,
'mail' => $mail,
));
$new_user = reset($accounts);
$this
->drupalUser1Login();
$edit = array(
'status' => 1,
);
$this
->drupalPost('user/' . $new_user->uid . '/edit', $edit, t('Save'));
$this
->drupalLogout();
// Login after administrator approval.
$this
->drupalPost('user/login', $auth, t('Log in'));
$this
->assertText(t('Member for'), t('The user can log in after administrator approval.'));
// Cleanup.
$ldap_user
->delete();
}