public function SimpleLdapRoleUpdateDrupalRoleTestCase::testUpdateRole in Simple LDAP 7
Same name and namespace in other branches
- 7.2 simple_ldap_role/simple_ldap_role.test \SimpleLdapRoleUpdateDrupalRoleTestCase::testUpdateRole()
Updates a Drupal role, and verifies LDAP.
File
- simple_ldap_role/
simple_ldap_role.test, line 170 - Tests for Simple LDAP Role module.
Class
Code
public function testUpdateRole() {
// 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();
// Populate the role edit form variables.
$edit = array(
'name' => $drupal_role->name . ' modified',
);
// Submit the role edit form.
$this
->drupalPost('admin/people/permissions/roles/edit/' . $drupal_role->rid, $edit, t('Save role'));
$this
->assertText('The role has been renamed.', t('The drupal role was updated'));
// Load the group from LDAP and check that it was updated.
$ldap_group = new SimpleLdapRole($drupal_role->name . ' modified');
$this
->assertTrue($ldap_group->exists, t('The :dn test group exists in LDAP.', array(
':dn' => $ldap_group->dn,
)));
// Repopulate the role edit form variables.
$edit = array(
'name' => $this->ldapGroup->{$attribute_name}[0],
);
// Submit the role edit form to restore the group to its original value.
$this
->drupalPost('admin/people/permissions/roles/edit/' . $drupal_role->rid, $edit, t('Save role'));
// Verify that the group was restored.
$ldap_group = new SimpleLdapRole($this->ldapGroup->{$attribute_name}[0]);
$this
->assertTrue($ldap_group->exists, t('The :dn test group was restored in LDAP.', array(
':dn' => $ldap_group->dn,
)));
}