You are here

public function LdapEntryProvisionTest::testLoginCreate in Lightweight Directory Access Protocol (LDAP) 8.4

Test building the entry.

File

ldap_user/tests/src/Kernel/LdapEntryProvisionTest.php, line 133

Class

LdapEntryProvisionTest
@coversDefaultClass \Drupal\ldap_servers\Processor\TokenProcessor @group ldap

Namespace

Drupal\Tests\ldap_user\Kernel

Code

public function testLoginCreate() : void {

  /** @var \Drupal\ldap_servers_dummy\FakeLdap $ldap */
  $ldap = $this->container
    ->get('ldap.bridge')
    ->get();
  $response = $this
    ->getMockBuilder(EntryManager::class)
    ->disableOriginalConstructor()
    ->getMock();
  $response
    ->expects(self::once())
    ->method('add')
    ->willReturnCallback(function ($entry) : bool {
    self::assertSame($this->user
      ->getEmail(), $entry
      ->getAttribute('mail')[0]);

    // This is not a derived DN.
    self::assertSame('cn=' . $this->user
      ->getAccountName() . ',ou=people,dc=hogwarts,dc=edu', $entry
      ->getDn());
    return TRUE;
  });
  $ldap
    ->setEntryManagerResponse($response);
  $this->user = $this
    ->createUser();
  $this->user
    ->save();
  $this->subscriber
    ->login(new LdapUserLoginEvent($this->user));
}