You are here

public function SimpleLdapUserSyncTestCase::testSyncOnHookUserLogin in Simple LDAP 7.2

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

Tests data synchronization using hook_user_login().

File

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

Class

SimpleLdapUserSyncTestCase

Code

public function testSyncOnHookUserLogin() {

  // Set the sync trigger to hook_user_login
  variable_set('simple_ldap_user_sync', 'hook_user_login');

  // 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];

  // Log in with the test user, this should do the initial account sync
  // (tested elsewhere).
  $this
    ->drupalLogin($account);

  // Generate a random value to append.
  $suffix = $this
    ->randomName();

  // Drupal is the authoritative source, Change all of the mapped fields,
  // login, and verify synchronization.
  variable_set('simple_ldap_user_source', 'drupal');
  $this
    ->modifyLdap($suffix);
  $this
    ->drupalLogin($account);
  $this
    ->verifySync();

  // LDAP is the authoritative source. Change all of the mapped fields, login,
  // and verify synchronization.
  variable_set('simple_ldap_user_source', 'ldap');
  $this
    ->modifyLdap($suffix);
  $this
    ->drupalLogin($account);
  $this
    ->verifySync($suffix);

  // Clean up by removing the suffix from the LDAP entry, and resyncing.
  $this
    ->modifyLdap();
  $this
    ->drupalLogin($account);
  $this
    ->verifySync();
}