You are here

public function LdapAuthenticationAdminFormTest::testForm in Lightweight Directory Access Protocol (LDAP) 8.4

Test the form.

File

ldap_authentication/tests/src/Functional/LdapAuthenticationAdminFormTest.php, line 77

Class

LdapAuthenticationAdminFormTest
Test the admin form.

Namespace

Drupal\Tests\ldap_authentication\Functional

Code

public function testForm() : void {
  $this
    ->drupalGet(self::FORM_PATH);
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $account = $this
    ->drupalCreateUser([
    'administer ldap',
  ]);
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet(self::FORM_PATH);
  $this
    ->assertSession()
    ->pageTextContains('My Test Server 1');
  $this
    ->assertSession()
    ->pageTextContains('My Test Server 2');
  $this
    ->assertSession()
    ->pageTextNotContains('My Test Server 3');
  $edit = [
    'authenticationMode' => 'exclusive',
    'allowOnlyIfTextInDn' => "one\ntwo",
    'edit-authenticationservers-my-test-server-1' => 1,
  ];
  $this
    ->submitForm($edit, 'op');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  /** @var \Drupal\Core\Config\ImmutableConfig $config */
  $config = $this->container
    ->get('config.factory')
    ->get('ldap_authentication.settings');
  self::assertEquals('exclusive', $config
    ->get('authenticationMode'));
  self::assertEquals([
    'one',
    'two',
  ], $config
    ->get('allowOnlyIfTextInDn'));

  // @todo Those could be saved nicer.
  $sids = [
    'my_test_server_1' => 'my_test_server_1',
    'my_test_server_2' => 0,
    'my_test_server_3' => 0,
  ];
  self::assertEquals($sids, $config
    ->get('sids'));
}