You are here

public function SimplesamlphpDrupalAuthTest::testExternalLoginRegister in simpleSAMLphp Authentication 8.3

Test external load functionality.

@covers ::externalLoginRegister @covers ::__construct

File

tests/src/Unit/Service/SimplesamlphpDrupalAuthTest.php, line 125

Class

SimplesamlphpDrupalAuthTest
SimplesamlphpDrupalAuth unit tests.

Namespace

Drupal\Tests\simplesamlphp_auth\Unit\Service

Code

public function testExternalLoginRegister() {
  $this->externalauth
    ->expects($this
    ->once())
    ->method('login')
    ->will($this
    ->returnValue(FALSE));

  // Set up a mock for SimplesamlphpDrupalAuth class,
  // mocking externalRegister() method.
  $simplesaml_drupalauth = $this
    ->getMockBuilder('Drupal\\simplesamlphp_auth\\Service\\SimplesamlphpDrupalAuth')
    ->setMethods([
    'externalRegister',
  ])
    ->setConstructorArgs([
    $this->simplesaml,
    $this->configFactory,
    $this->entityTypeManager,
    $this->logger,
    $this->externalauth,
    $this->entityAccount,
    $this->messenger,
    $this->moduleHandler,
  ])
    ->getMock();

  // Mock some methods on SimplesamlphpDrupalAuth, since they are out of scope
  // of this specific unit test.
  $simplesaml_drupalauth
    ->expects($this
    ->once())
    ->method('externalRegister')
    ->will($this
    ->returnValue($this->entityAccount));

  // Now that everything is set up, call externalLoad() and expect a User.
  $loaded_account = $simplesaml_drupalauth
    ->externalLoginRegister("testuser");
  $this
    ->assertTrue($loaded_account instanceof UserInterface);
}