You are here

public function SimpleLdapRoleModifyLdapGroup::testModifyLdapGroup in Simple LDAP 7

Same name and namespace in other branches
  1. 7.2 simple_ldap_role/simple_ldap_role.test \SimpleLdapRoleModifyLdapGroup::testModifyLdapGroup()

Tests creating and modifying a group directly in LDAP.

File

simple_ldap_role/simple_ldap_role.test, line 382
Tests for Simple LDAP Role module.

Class

SimpleLdapRoleModifyLdapGroup

Code

public function testModifyLdapGroup() {

  // Load configuration variables.
  $role_basedn = simple_ldap_role_variable_get('simple_ldap_role_basedn');
  $role_objectclass = simple_ldap_role_variable_get('simple_ldap_role_objectclass');
  $role_attribute_name = simple_ldap_role_variable_get('simple_ldap_role_attribute_name');
  $role_attribute_member = simple_ldap_role_variable_get('simple_ldap_role_attribute_member');
  $role_attribute_member_format = simple_ldap_role_variable_get('simple_ldap_role_attribute_member_format');
  $role_attribute_member_default = simple_ldap_role_variable_get('simple_ldap_role_attribute_member_default');

  // Generate a new random role name.
  $new_role = $this
    ->randomName();

  // Generate a new LDAP object.
  $ldap_group = new SimpleLdapRole($new_role);
  $ldap_group
    ->addUser($this->ldapUser[0]);
  $ldap_group
    ->save();

  // Verify that the LDAP group exists.
  $this
    ->assertTrue($ldap_group->exists, t(':dn exists in LDAP', array(
    ':dn' => $ldap_group->dn,
  )));

  // Verify that the LDAP group does not exist in Drupal.
  $drupal_role = user_role_load_by_name($new_role);
  $this
    ->assertFalse($drupal_role, t('The :group LDAP group does not exist as a Drupal role.', array(
    ':group' => $new_role,
  )));

  // Run cron.
  $this
    ->cronRun();

  // Verify that the test LDAP group exists in Drupal.
  $drupal_role = user_role_load_by_name($new_role);
  $this
    ->assertTrue($drupal_role, t('The :group LDAP group exists as a Drupal role.', array(
    ':group' => $new_role,
  )));

  // Modify the LDAP object.
  $ldap_group->{$role_attribute_name} = $new_role . $new_role;
  $ldap_group
    ->save();

  // Verify that the original LDAP group does not exist.
  $ldap_group = new SimpleLdapRole($new_role);
  $this
    ->assertFalse($ldap_group->exists, t(':dn does not exist in LDAP', array(
    ':dn' => $ldap_group->dn,
  )));

  // Verify that the updated LDAP group exists.
  $ldap_group = new SimpleLdapRole($new_role . $new_role);
  $this
    ->assertTrue($ldap_group->exists, t(':dn exists in LDAP', array(
    ':dn' => $ldap_group->dn,
  )));

  // Run cron.
  $this
    ->cronRun();

  // Verify that the test LDAP group exists in Drupal.
  $drupal_role = user_role_load_by_name($new_role . $new_role);
  $this
    ->assertTrue($drupal_role, t('The :group LDAP group exists as a Drupal role.', array(
    ':group' => $new_role . $new_role,
  )));

  // Cleanup.
  $ldap_group
    ->delete();
}