You are here

public function LdapServersTestCase::testInstall in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 7.2 ldap_servers/tests/ldap_servers.test \LdapServersTestCase::testInstall()
  2. 7 ldap_servers/tests/ldap_servers.test \LdapServersTestCase::testInstall()

File

ldap_servers/tests/ldap_servers.test, line 139

Class

LdapServersTestCase

Code

public function testInstall() {
  $group = 'ldap_servers: install and uninstall';
  $install_tables = array(
    'ldap_servers',
  );

  // disable, uninstall, and enable/install module
  $modules = array(
    $this->module_name,
  );
  $ldap_module_uninstall_sequence = array(
    'ldap_authentication',
    'ldap_test',
    'ldap_user',
    'ldap_group',
    'ldap_servers',
  );
  module_disable($ldap_module_uninstall_sequence);

  // disable dependent modules
  drupal_uninstall_modules($ldap_module_uninstall_sequence);
  module_enable($modules, TRUE);
  foreach ($install_tables as $table) {
    $this
      ->assertTrue(db_table_exists($table), $table . ' table creates', $group);
  }
  $var_created = $this
    ->assertTrue(TRUE, 'ldap_servers_encryption variable initialized', $group);
  $var_created = $this
    ->assertTrue(config('ldap_server.settings')
    ->get('encrypt_key'), 'ldap_servers_encrypt_key variable initialized', $group);
  module_disable($modules, TRUE);

  // disable dependent modules
  drupal_uninstall_modules($modules, TRUE);

  // unistall dependent modules
  foreach ($install_tables as $table) {
    $this
      ->assertFalse(db_table_exists($table), $table . ' table removed', $group);
  }
  $var_created = $this
    ->assertFalse(config('ldap_server.settings')
    ->get('encryption'), 'ldap_servers_encryption variable removed', $group);
  $var_created = $this
    ->assertFalse(config('ldap_server.settings')
    ->get('encrypt_key'), 'ldap_servers_encrypt_key variable removed', $group);

  // test tokens, see http://drupal.org/node/1245736
  $ldap_entry = array(
    'dn' => 'cn=hpotter,ou=people,dc=hogwarts,dc=edu',
    'mail' => array(
      0 => 'hpotter@hogwarts.edu',
      'count' => 1,
    ),
    'sAMAccountName' => array(
      0 => 'hpotter',
      'count' => 1,
    ),
    'house' => array(
      0 => 'Gryffindor',
      1 => 'Privet Drive',
      'count' => 2,
    ),
    'guid' => array(
      0 => 'sdafsdfsdf',
      'count' => 1,
    ),
    'count' => 3,
  );
  $this->ldapTestId = 'ldap_server.tokens';
  $dn = ldap_servers_token_replace($ldap_entry, '[dn]');
  $this
    ->assertTrue($dn == $ldap_entry['dn'], t('[dn] token worked on ldap_servers_token_replace().'), $this->ldapTestId);
  $house0 = ldap_servers_token_replace($ldap_entry, '[house:0]');
  $this
    ->assertTrue($house0 == $ldap_entry['house'][0], t("[house:0] token worked ({$house0}) on ldap_servers_token_replace()."), $this->ldapTestId);
  $mixed = ldap_servers_token_replace($ldap_entry, 'thisold[house:0]');
  $this
    ->assertTrue($mixed == 'thisold' . $ldap_entry['house'][0], t("thisold[house:0] token worked ({$mixed}) on ldap_servers_token_replace()."), $this->ldapTestId);
  $compound = ldap_servers_token_replace($ldap_entry, '[samaccountname:0][house:0]');
  $this
    ->assertTrue($compound == $ldap_entry['sAMAccountName'][0] . $ldap_entry['house'][0], t("[samaccountname:0][house:0] compound token worked ({$mixed}) on ldap_servers_token_replace()."), $this->ldapTestId);
  $literalvalue = ldap_servers_token_replace($ldap_entry, 'literalvalue');
  $this
    ->assertTrue($literalvalue == 'literalvalue', t("'literalvalue' token worked ({$literalvalue}) on ldap_servers_token_replace()."), $this->ldapTestId);
  $house0 = ldap_servers_token_replace($ldap_entry, '[house]');
  $this
    ->assertTrue($house0 == $ldap_entry['house'][0], t("[house] token worked ({$house0}) on ldap_servers_token_replace()."), $this->ldapTestId);
  $house1 = ldap_servers_token_replace($ldap_entry, '[house:last]');
  $this
    ->assertTrue($house1 == $ldap_entry['house'][1], t('[house:last] token worked on ldap_servers_token_replace().'), $this->ldapTestId);
  $sAMAccountName = ldap_servers_token_replace($ldap_entry, '[samaccountname:0]');
  $this
    ->assertTrue($sAMAccountName == $ldap_entry['sAMAccountName'][0], t('[samaccountname:0] token worked on ldap_servers_token_replace().'), $this->ldapTestId);
  $sAMAccountNameMixedCase = ldap_servers_token_replace($ldap_entry, '[sAMAccountName:0]');
  $this
    ->assertTrue($sAMAccountNameMixedCase == $ldap_entry['sAMAccountName'][0], t('[sAMAccountName:0] token worked on ldap_servers_token_replace().'), $this->ldapTestId);
  $sAMAccountName2 = ldap_servers_token_replace($ldap_entry, '[samaccountname]');
  $this
    ->assertTrue($sAMAccountName2 == $ldap_entry['sAMAccountName'][0], t('[samaccountname] token worked on ldap_servers_token_replace().'), $this->ldapTestId);
  $sAMAccountName3 = ldap_servers_token_replace($ldap_entry, '[sAMAccountName]');
  $this
    ->assertTrue($sAMAccountName2 == $ldap_entry['sAMAccountName'][0], t('[sAMAccountName] token worked on ldap_servers_token_replace().'), $this->ldapTestId);
  $base64encode = ldap_servers_token_replace($ldap_entry, '[guid;base64_encode]');
  $this
    ->assertTrue($base64encode == base64_encode($ldap_entry['guid'][0]), t('[guid;base64_encode] token worked on ldap_servers_token_replace().'), $this->ldapTestId);
  $bin2hex = ldap_servers_token_replace($ldap_entry, '[guid;bin2hex]');
  $this
    ->assertTrue($bin2hex == bin2hex($ldap_entry['guid'][0]), t('[guid;bin2hex] token worked on ldap_servers_token_replace().'), $this->ldapTestId);
  $msguid = ldap_servers_token_replace($ldap_entry, '[guid;msguid]');
  $this
    ->assertTrue($msguid == ldap_servers_msguid($ldap_entry['guid'][0]), t('[guid;msguid] token worked on ldap_servers_token_replace().'), $this->ldapTestId);
  $binary = ldap_servers_token_replace($ldap_entry, '[guid;binary]');
  $this
    ->assertTrue($binary == ldap_servers_binary($ldap_entry['guid'][0]), t('[guid;binary] token worked on ldap_servers_token_replace().'), $this->ldapTestId);

  /**
  * @todo test tokens for 'user_account'
  *
      $account = new stdClass();
      $account->
      ldap_servers_token_replace($account, '[property.name]', 'user_account');
  */
  module_enable($modules, TRUE);
}