You are here

public function LdapTestCase::removeUserFromGroup in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_test/LdapTestCase.class.php \LdapTestCase::removeUserFromGroup()
1 call to LdapTestCase::removeUserFromGroup()
LdapAuthorizationBasicTests::testSimpleStuff in ldap_authorization/tests/BasicTests.test
Test install, api functions, and simple authorizations granted on logon.

File

ldap_test/LdapTestCase.class.php, line 158

Class

LdapTestCase

Code

public function removeUserFromGroup(&$test_data, $user_dn, $group_dn, $domain = "dc=hogwarts,dc=edu") {
  $filter = "(&(objectClass=group)(member={$user_dn}))";
  if (!empty($test_data['search_results'][$filter][$domain]) && in_array($group_dn, $test_data['search_results'][$filter][$domain])) {
    $test_data['search_results'][$filter][$domain] = array_diff($test_data['search_results'][$filter][$domain], [
      $group_dn,
    ]);
    $test_data['search_results'][$filter][$domain]['count'] = count($test_data['search_results'][$filter][$domain] - 1);
  }
  if (!empty($test_data['users'][$user_dn]['attr']['memberof']) && in_array($group_dn, $test_data['users'][$user_dn]['attr']['memberof'])) {
    $test_data['users'][$user_dn]['attr']['memberof'] = array_diff($test_data['users'][$user_dn]['attr']['memberof'], [
      $group_dn,
    ]);
    $test_data['users'][$user_dn]['attr']['memberof']['count'] = count($test_data['users'][$user_dn]['attr']['memberof'] - 1);
  }
  if (!empty($test_data['ldap'][$user_dn]['memberof']) && in_array($group_dn, $test_data['ldap'][$user_dn]['memberof'])) {
    $test_data['ldap'][$user_dn]['memberof'] = array_diff($test_data['ldap'][$user_dn]['memberof'], [
      $group_dn,
    ]);
    $test_data['ldap'][$user_dn]['memberof']['count'] = count($test_data['ldap'][$user_dn]['memberof']) - 1;
  }
  if (!empty($test_data['groups'][$group_dn]['attr']['member']) && in_array($group_dn, $test_data['groups'][$group_dn]['attr']['member'])) {
    $members = array_diff($test_data['groups'][$group_dn]['attr']['member'], [
      $group_dn,
    ]);
    $test_data['groups'][$group_dn]['attr']['member'] = $members;
    $test_data['groups'][$group_dn]['attr']['member'][$i]['count'] = count($members - 1);
  }
}