You are here

public function ExternalAuthTest::testLogin 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::testLogin()

Test the login() method.

@covers ::login @covers ::__construct

File

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

Class

ExternalAuthTest
ExternalAuth unit tests.

Namespace

Drupal\Tests\externalauth\Unit

Code

public function testLogin() {

  // Set up a mock for ExternalAuth class,
  // mocking load() & userLoginFinalize() methods.
  $externalauth = $this
    ->getMockBuilder('Drupal\\externalauth\\ExternalAuth')
    ->setMethods([
    'load',
    'userLoginFinalize',
  ])
    ->setConstructorArgs([
    $this->entityTypeManager,
    $this->authmap,
    $this->logger,
    $this->eventDispatcher,
  ])
    ->getMock();

  // Mock load method.
  $externalauth
    ->expects($this
    ->once())
    ->method('load')
    ->will($this
    ->returnValue(FALSE));

  // Expect userLoginFinalize() to not be called.
  $externalauth
    ->expects($this
    ->never())
    ->method('userLoginFinalize');
  $result = $externalauth
    ->login("test_authname", "test_provider");
  $this
    ->assertEquals(FALSE, $result);
}