You are here

public function SimpleLdapUserSyncTestCase::modifyLdap in Simple LDAP 7.2

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

Modifies the test user account in LDAP.

2 calls to SimpleLdapUserSyncTestCase::modifyLdap()
SimpleLdapUserSyncTestCase::testSyncOnHookUserLoad in simple_ldap_user/simple_ldap_user.test
Tests synchronization using hook_user_load().
SimpleLdapUserSyncTestCase::testSyncOnHookUserLogin in simple_ldap_user/simple_ldap_user.test
Tests data synchronization using hook_user_login().

File

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

Class

SimpleLdapUserSyncTestCase

Code

public function modifyLdap($suffix = '') {

  // Load configuration variables.
  $attribute_name = simple_ldap_user_variable_get('simple_ldap_user_attribute_name');
  $attribute_mail = simple_ldap_user_variable_get('simple_ldap_user_attribute_mail');

  // Load the LDAP Server.
  $server = SimpleLdapServer::singleton();

  // Search for the User account.
  $ldap_user = new SimpleLdapUser($this->ldapUser[0]->{$attribute_name}[0]);

  // Modify the mapped attributes.
  $attribute_map = simple_ldap_user_variable_get('simple_ldap_user_attribute_map');
  array_unshift($attribute_map, array(
    'drupal' => array(
      'mail',
    ),
    'ldap' => $attribute_mail,
  ));
  foreach ($attribute_map as $attribute) {
    if (count($attribute['drupal']) == 1) {
      $attributetype = $server->schema
        ->get('attributetypes', $attribute['ldap']);

      // A syntax type of 1.3.6.1.4.1.1466.115.121.1.27 is an integer.
      if (isset($attributetype['syntax']) && $attributetype['syntax'] == '1.3.6.1.4.1.1466.115.121.1.27') {
        if ($suffix) {
          $value = hexdec(substr(sha1($suffix), 0, 2));
        }
        else {
          $value = $this->ldapUser[0]->{$attribute['ldap']}[0];
        }
      }
      else {
        $value = $this->ldapUser[0]->{$attribute['ldap']}[0] . $suffix;
      }
      try {
        $server
          ->modify($ldap_user->dn, array(
          $attribute['ldap'] => $value,
        ), 'replace');
        $entry = $server
          ->entry($ldap_user->dn);
        $this
          ->assertEqual($value, $entry[0][$attribute['ldap']][0], t('Modified @attr LDAP attribute to :value.', array(
          '@attr' => $attribute['ldap'],
          ':value' => $value,
        )));
      } catch (SimpleLdapException $e) {
        $this
          ->error($e
          ->getMessage());
      }
    }
  }
}