You are here

public function SimpleLdapTest::testSimpleLdapServerConfiguration in Simple LDAP 8

Test the Simple LDAP server configuration.

File

tests/src/Functional/SimpleLdapTest.php, line 67

Class

SimpleLdapTest
Tests Simple LDAP configuration options.

Namespace

Drupal\Tests\simple_ldap\Functional

Code

public function testSimpleLdapServerConfiguration() {

  // Check that the server is not connected.
  $ldap_config_url = Url::fromRoute("simple_ldap.server")
    ->toString();
  $this
    ->drupalGet($ldap_config_url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('Not connected');

  // Test by connecting to a free online LDAP test server. See:
  // http://www.forumsys.com/en/tutorials/integration-how-to/ldap/online-ldap-test-server/
  $edit = [
    'host' => $this->host,
    'port' => $this->port,
    'binddn' => $this->binddn,
    'bindpw' => $this->bindpw,
  ];
  $this
    ->submitForm($edit, t('Save'));

  // Check that the server is connected.
  $this
    ->drupalGet($ldap_config_url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('Successfully binded to');

  // Configure non-existent LDAP server.
  $edit = [
    'host' => 'not.a.real.ldap.server',
    'port' => 123,
    'binddn' => 'fake',
    'bindpw' => 'credentials',
  ];
  $this
    ->submitForm($edit, t('Save'));

  // Check that the server is does not connect.
  $this
    ->drupalGet($ldap_config_url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains('Could not bind to not.a.real.ldap.server');
}