You are here

public function ExternalAuthTest::testLoad in External Authentication 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Unit/ExternalAuthTest.php \Drupal\Tests\externalauth\Unit\ExternalAuthTest::testLoad()

Test the load() method.

@covers ::load @covers ::__construct

File

tests/src/Unit/ExternalAuthTest.php, line 80

Class

ExternalAuthTest
ExternalAuth unit tests.

Namespace

Drupal\Tests\externalauth\Unit

Code

public function testLoad() {

  // Set up a mock for Authmap class,
  // mocking getUid() method.
  $authmap = $this
    ->getMockBuilder('\\Drupal\\externalauth\\Authmap')
    ->disableOriginalConstructor()
    ->setMethods([
    'getUid',
  ])
    ->getMock();
  $authmap
    ->expects($this
    ->once())
    ->method('getUid')
    ->will($this
    ->returnValue(2));

  // Mock the User storage layer.
  $account = $this
    ->createMock('Drupal\\user\\UserInterface');
  $entity_storage = $this
    ->createMock('Drupal\\Core\\Entity\\EntityStorageInterface');

  // Expect the external loading method to return a user object.
  $entity_storage
    ->expects($this
    ->once())
    ->method('load')
    ->will($this
    ->returnValue($account));
  $this->entityTypeManager
    ->expects($this
    ->once())
    ->method('getStorage')
    ->will($this
    ->returnValue($entity_storage));
  $externalauth = new ExternalAuth($this->entityTypeManager, $authmap, $this->logger, $this->eventDispatcher);
  $result = $externalauth
    ->load("test_authname", "test_provider");
  $this
    ->assertInstanceOf(UserInterface::class, $result);
}