You are here

public function LdapServerTest::modifyLdapEntry in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_test/LdapServerTest.class.php \LdapServerTest::modifyLdapEntry()

Modify attributes of ldap entry.

Parameters

string $dn: DN of entry.

array $attributes: should follow the structure of ldap_add functions entry array: http://us.php.net/manual/en/function.ldap-add.php $attributes["attribute1"] = "value"; $attributes["attribute2"][0] = "value1"; $attributes["attribute2"][1] = "value2";.

Return value

TRUE on success FALSE on error

Overrides LdapServer::modifyLdapEntry

File

ldap_test/LdapServerTest.class.php, line 425
Simpletest ldapServer class for testing without an actual ldap server.

Class

LdapServerTest

Code

public function modifyLdapEntry($dn, $attributes = NULL, $old_attributes = FALSE) {
  if (!$attributes) {
    $attributes = [];
  }
  $test_data = variable_get('ldap_test_server__' . $this->sid, []);
  if (!isset($test_data['entries'][$dn])) {
    return FALSE;
  }
  $ldap_entry = $test_data['entries'][$dn];
  foreach ($attributes as $key => $cur_val) {
    if ($cur_val == '') {
      unset($ldap_entry[$key]);
    }
    elseif (is_array($cur_val)) {
      foreach ($cur_val as $mv_key => $mv_cur_val) {
        if ($mv_cur_val == '') {
          unset($ldap_entry[$key][$mv_key]);
        }
        else {
          if (is_array($mv_cur_val)) {
            $ldap_entry[$key][$mv_key] = $mv_cur_val;
          }
          else {
            $ldap_entry[$key][$mv_key][] = $mv_cur_val;
          }
        }
      }
      unset($ldap_entry[$key]['count']);
      $ldap_entry[$key]['count'] = count($ldap_entry[$key]);
    }
    else {
      $ldap_entry[$key][0] = $cur_val;
      $ldap_entry[$key]['count'] = count($ldap_entry[$key]);
    }
  }
  $test_data['entries'][$dn] = $ldap_entry;
  $test_data['ldap'][$dn] = $ldap_entry;
  variable_set('ldap_test_server__' . $this->sid, $test_data);
  $this
    ->refreshFakeData();
  return TRUE;
}