You are here

public function SimpleLdapRoleTestCase::setUp in Simple LDAP 7

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

Inherited parent::setUp().

Overrides SimpleLdapUserTestCase::setUp

File

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

Class

SimpleLdapRoleTestCase
@file Tests for Simple LDAP Role module.

Code

public function setUp() {

  // Get the live simple_ldap_role configuration.
  $basedn = simple_ldap_role_variable_get('simple_ldap_role_basedn');
  $scope = simple_ldap_role_variable_get('simple_ldap_role_scope');
  $objectclass = simple_ldap_role_variable_get('simple_ldap_role_objectclass');
  $attribute_name = simple_ldap_role_variable_get('simple_ldap_role_attribute_name');
  $attribute_member = simple_ldap_role_variable_get('simple_ldap_role_attribute_member');
  $attribute_member_format = simple_ldap_role_variable_get('simple_ldap_role_attribute_member_format');
  $attribute_member_default = simple_ldap_role_variable_get('simple_ldap_role_attribute_member_default');
  $filter = simple_ldap_role_variable_get('simple_ldap_role_filter');
  $source = simple_ldap_role_variable_get('simple_ldap_role_source');
  $sync = simple_ldap_role_variable_get('simple_ldap_role_sync');

  // Create the simpletest sandbox.
  $modules = func_get_args();
  if (isset($modules[0]) && is_array($modules[0])) {
    $modules = $modules[0];
  }
  parent::setUp($modules);

  // Enable the simple_ldap_role module.
  $modules = array(
    'simple_ldap_role',
  );
  $success = module_enable($modules);
  $this
    ->assertTrue($success, t('Enabled modules: %modules', array(
    '%modules' => implode(', ', $modules),
  )));

  // Configure the sandbox simple_ldap_role instance.
  variable_set('simple_ldap_role_basedn', $basedn);
  variable_set('simple_ldap_role_scope', $scope);
  variable_set('simple_ldap_role_objectclass', $objectclass);
  variable_set('simple_ldap_role_attribute_name', $attribute_name);
  variable_set('simple_ldap_role_attribute_member', $attribute_member);
  variable_set('simple_ldap_role_attribute_member_format', $attribute_member_format);
  variable_set('simple_ldap_role_attribute_member_default', $attribute_member_default);
  variable_set('simple_ldap_role_filter', $filter);
  variable_set('simple_ldap_role_source', $source);
  variable_set('simple_ldap_role_sync', $sync);

  // Create an LDAP group entry to use during testing.
  $name = $this
    ->randomName();
  $this->ldapGroup = new SimpleLdapRole($name);
  $this->ldapGroup
    ->addUser($this->ldapUser[0]);
  $this->ldapGroup
    ->save();

  // If now exception is thrown by save(), then the save was successful, but
  // reload the object and show the DN to make the tester feel better.
  $this->ldapGroup = new SimpleLdapRole($name);
  $this
    ->assertTrue($this->ldapGroup->exists, t(':dn was added to LDAP', array(
    ':dn' => $this->ldapGroup->dn,
  )));
}