You are here

public function SimpleLdapUserTest::testSimpleLdapUserLogin in Simple LDAP 8

Test the Simple LDAP user login and creation process.

File

modules/simple_ldap_user/tests/src/Functional/SimpleLdapUserTest.php, line 68

Class

SimpleLdapUserTest
Tests Simple LDAP User login.

Namespace

Drupal\Tests\simple_ldap_user\Functional

Code

public function testSimpleLdapUserLogin() {

  // 1. Correct username & correct password.
  // Login as Einstein and confirm that the account was created.
  $user_login_url = Url::fromRoute("user.login")
    ->toString();
  $edit = [
    'name' => 'einstein',
    'pass' => 'password',
  ];
  $this
    ->drupalPostForm($user_login_url, $edit, t('Log in'));
  $this
    ->assertText(t('New user created for einstein.'));

  // 2. Correct username & incorrect password.
  $edit = [
    'name' => 'einstein',
    'pass' => 'incorrect!',
  ];
  $this
    ->drupalPostForm($user_login_url, $edit, t('Log in'));
  $this
    ->assertText(t('Could not authenticate with your username/password in LDAP. Please contact your site administrator.'));

  // 3. Incorrect username & incorrect password.
  $edit = [
    'name' => 'nobodyNotExists',
    'pass' => 'incorrect!',
  ];
  $this
    ->drupalPostForm($user_login_url, $edit, t('Log in'));
  $this
    ->assertText(t('An account could not be found or an ID conflict has been detected. Please contact your site administrator.'));
}