public function SimpleLdapUserAuthenticationWebTestCase::testGoodAuthentication in Simple LDAP 7
Same name and namespace in other branches
- 7.2 simple_ldap_user/simple_ldap_user.test \SimpleLdapUserAuthenticationWebTestCase::testGoodAuthentication()
Test user authentication.
File
- simple_ldap_user/
simple_ldap_user.test, line 368 - Tests for Simple LDAP User module.
Class
Code
public function testGoodAuthentication() {
// Load configuration variables.
$attribute_name = simple_ldap_user_variable_get('simple_ldap_user_attribute_name');
// Initialize a user account object.
$account = new stdClass();
$account->name = $this->ldapUser[0]->{$attribute_name}[0];
$account->pass_raw = $this->userPassword[0];
// Verify that the test user does not exist in Drupal.
$drupal_user = user_load_by_name($this->ldapUser[0]->{$attribute_name}[0]);
$this
->assertIdentical($drupal_user, FALSE, t('The test user does not exist in Drupal.'));
// Verify that the user can log in.
$this
->drupalLogin($account);
// Verify that the Drupal user was created during authentication.
$drupal_user = user_load_by_name($this->ldapUser[0]->{$attribute_name}[0]);
$this
->assertNotIdentical($drupal_user, FALSE, t('The test user was created in Drupal.'));
// Verify again that the user can log in, now that the account exists in
// both Drupal and LDAP.
$this
->drupalLogin($account);
// Create a new Drupal user that is not in LDAP.
$account = $this->drupalUser[0];
// Verify that the user does not exist in LDAP by random chance.
$ldap_user = new SimpleLdapUser($account->name);
$this
->assertFalse($ldap_user->exists, t('The user account does not exist in LDAP.'));
// Verify that the user cannot log in.
$this
->drupalNoLogin($account);
}