You are here

public function SimpleLdapUserManagerTest::testCreateDrupalUser in Simple LDAP 8

@covers ::createDrupalUser @depends testGetLdapUser

File

modules/simple_ldap_user/tests/src/Unit/SimpleLdapUserManagerTest.php, line 150
Contains \Drupal\Tests\simple_ldap\Unit\SimpleLdapUserManagerTest

Class

SimpleLdapUserManagerTest
@coversDefaultClass \Drupal\simple_ldap_user\SimpleLdapUserManager @group simple_ldap

Namespace

Drupal\Tests\simple_ldap\Unit

Code

public function testCreateDrupalUser(SimpleLdapUser $ldap_user) {
  $attributes = $ldap_user
    ->getAttributes();
  $this->config
    ->expects($this
    ->exactly(2))
    ->method('get')
    ->withConsecutive([
    'name_attribute',
  ], [
    'mail_attribute',
  ])
    ->will($this
    ->onConsecutiveCalls('cn', 'mail'));
  $user_storage = $this
    ->getMockBuilder('\\Drupal\\user\\UserStorage')
    ->disableOriginalConstructor()
    ->getMock();
  $user = $this
    ->getMockBuilder('\\Drupal\\user\\User')
    ->disableOriginalConstructor()
    ->setMethods(array(
    'enforceIsNew',
    'activate',
    'save',
  ))
    ->getMock();
  $user
    ->expects($this
    ->once())
    ->method('enforceIsNew');
  $user
    ->expects($this
    ->once())
    ->method('activate');
  $user
    ->expects($this
    ->once())
    ->method('save');
  $user_storage
    ->expects($this
    ->once())
    ->method('create')
    ->with(array(
    'name' => $attributes['cn'][0],
    'mail' => $attributes['mail'][0],
  ))
    ->willReturn($user);
  $this->entity_manager
    ->expects($this
    ->once())
    ->method('getStorage')
    ->with('user')
    ->willReturn($user_storage);
  $user_manager = new SimpleLdapUserManager($this->server, $this->config_factory, $this->query_factory, $this->entity_manager);
  $user = $user_manager
    ->createDrupalUser($ldap_user);
  $this
    ->assertNotEmpty($user);
}