You are here

public function ExternalAuthenticationHelperTests::testUserExclusion in Lightweight Directory Access Protocol (LDAP) 8.3

Tests user exclusion for the authentication helper.

File

ldap_user/tests/src/Unit/ExternalAuthenticationHelperTests.php, line 17

Class

ExternalAuthenticationHelperTests
@coversDefaultClass \Drupal\ldap_user\Helper\ExternalAuthenticationHelper @group ldap

Namespace

Drupal\Tests\ldap_user\Unit

Code

public function testUserExclusion() {

  // @TODO 2914053.

  /* Disallow user 1 */
  $account = $this
    ->prophesize('\\Drupal\\user\\Entity\\User');
  $account
    ->id()
    ->willReturn(1);
  $this
    ->assertTrue(ExternalAuthenticationHelper::excludeUser($account
    ->reveal()));

  /* Disallow checkbox exclusion (everyone else allowed). */
  $account = $this
    ->prophesize('\\Drupal\\user\\Entity\\User');
  $account
    ->id()
    ->willReturn(2);
  $value = new \stdClass();
  $value->value = 1;
  $account
    ->get('ldap_user_ldap_exclude')
    ->willReturn($value);
  $this
    ->assertTrue(ExternalAuthenticationHelper::excludeUser($account
    ->reveal()));

  /* Everyone else allowed. */
  $account = $this
    ->prophesize('\\Drupal\\user\\Entity\\User');
  $account
    ->id()
    ->willReturn(2);
  $value = new \stdClass();
  $value->value = '';
  $account
    ->get('ldap_user_ldap_exclude')
    ->willReturn($value);
  $this
    ->assertFalse(ExternalAuthenticationHelper::excludeUser($account
    ->reveal()));
}