You are here

public function SimpleLdapRoleDeleteDrupalRoleTestCase::testDeleteRole in Simple LDAP 7

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

Deletes a Drupal role, and checks LDAP.

File

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

Class

SimpleLdapRoleDeleteDrupalRoleTestCase

Code

public function testDeleteRole() {

  // Get module configurations.
  $attribute_name = simple_ldap_role_variable_get('simple_ldap_role_attribute_name');
  $attribute_member = simple_ldap_role_variable_get('simple_ldap_role_attribute_member');

  // Load/Create a drupal role with the same name as the test LDAP group.
  $drupal_role = user_role_load_by_name($this->ldapGroup->{$attribute_name}[0]);
  if (!$drupal_role) {
    $rid = $this
      ->drupalCreateRole(array(), $this->ldapGroup->{$attribute_name}[0]);
    $drupal_role = user_role_load($rid);
  }

  // Log in as user 1.
  $this
    ->drupalUser1Login();

  // Submit the role edit form.
  $this
    ->drupalPost('admin/people/permissions/roles/edit/' . $drupal_role->rid, array(), t('Delete role'));
  $this
    ->assertText('Are you sure you want to delete the role ' . $drupal_role->name, t('Proceed to step 2 of deleting a role.'));
  $this
    ->drupalPost('admin/people/permissions/roles/delete/' . $drupal_role->rid, array(), t('Delete'));
  $this
    ->assertText('The role has been deleted.', t('The Drupal role was deleted'));

  // Try to load the group from LDAP, and verify that it was deleted.
  $ldap_group = new SimpleLdapRole($this->ldapGroup->{$attribute_name}[0]);
  $this
    ->assertFalse($ldap_group->exists, t('The :dn test group was deleted from LDAP.', array(
    ':dn' => $ldap_group->dn,
  )));
}