You are here

simple_ldap.test in Simple LDAP 7.2

Same filename and directory in other branches
  1. 7 simple_ldap.test

Tests for Simple LDAP module.

File

simple_ldap.test
View source
<?php

/**
 * @file
 * Tests for Simple LDAP module.
 */
class SimpleLdapServerTestCase extends DrupalWebTestCase {

  /**
   * Inherited from DrupalWebTestCase::setUp().
   */
  public function setUp() {

    // Get the live simple_ldap config.
    $host = variable_get('simple_ldap_host');
    $port = variable_get('simple_ldap_port');
    $starttls = variable_get('simple_ldap_starttls');
    $binddn = variable_get('simple_ldap_binddn');
    $bindpw = variable_get('simple_ldap_bindpw');
    $readonly = variable_get('simple_ldap_readonly');
    $pagesize = variable_get('simple_ldap_pagesize');
    $debug = variable_get('simple_ldap_debug');

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

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

    // Configure the sandbox environment.
    variable_set('simple_ldap_host', $host);
    variable_set('simple_ldap_port', $port);
    variable_set('simple_ldap_starttls', $starttls);
    variable_set('simple_ldap_binddn', $binddn);
    variable_set('simple_ldap_bindpw', $bindpw);
    variable_set('simple_ldap_readonly', $readonly);
    variable_set('simple_ldap_pagesize', $pagesize);
    variable_set('simple_ldap_debug', $debug);
  }

}
class SimpleLdapServerConnectionTestCase extends SimpleLdapServerTestCase {

  /**
   * Inherited from DrupalWebTestCase::getInfo().
   */
  public static function getInfo() {
    return array(
      'name' => 'LDAP server connectivity',
      'description' => 'Tests the Simple LDAP server configuration and connectivity.',
      'group' => 'Simple LDAP',
    );
  }

  /**
   * Test the LDAP server configuration and connectivity.
   */
  public function testLdapServer() {

    // Initialize the LDAP server.
    $this->server = new SimpleLdapServer();

    // Initialize t() params.
    $t = array(
      ':host' => $this->server->host,
      ':port' => $this->server->port,
      ':tls' => $this->server->starttls ? ' ' . t('using startTLS') : '',
      ':ssl' => strpos($this->server->host, 'ldaps://') === 0 ? ' ' . t('using SSL') : '',
    );

    // Test connectivity to the configured LDAP server.
    $this
      ->assertTrue($this->server
      ->bind(), t('Successfully bound to :host on port :port:tls:ssl.', $t));
    $this
      ->assertTrue($this->server
      ->unbind(), t('Successfully unbound from :host.', $t));
  }

}

Classes

Namesort descending Description
SimpleLdapServerConnectionTestCase
SimpleLdapServerTestCase @file Tests for Simple LDAP module.