You are here

public function CasUserManagerTest::testUserNotFoundAndAutoRegistrationDisabled in CAS 8

Same name and namespace in other branches
  1. 2.x tests/src/Unit/Service/CasUserManagerTest.php \Drupal\Tests\cas\Unit\Service\CasUserManagerTest::testUserNotFoundAndAutoRegistrationDisabled()

User account doesn't exist but auto registration is disabled.

An exception should be thrown and the user should not be logged in.

@covers ::login

File

tests/src/Unit/Service/CasUserManagerTest.php, line 169

Class

CasUserManagerTest
CasUserManager unit tests.

Namespace

Drupal\Tests\cas\Unit\Service

Code

public function testUserNotFoundAndAutoRegistrationDisabled() {
  $config_factory = $this
    ->getConfigFactoryStub([
    'cas.settings' => [
      'user_accounts.auto_register' => FALSE,
    ],
  ]);
  $cas_user_manager = $this
    ->getMockBuilder('Drupal\\cas\\Service\\CasUserManager')
    ->setMethods([
    'storeLoginSessionData',
    'register',
  ])
    ->setConstructorArgs([
    $this->externalAuth,
    $this->authmap,
    $config_factory,
    $this->session,
    $this->connection,
    $this->eventDispatcher,
    $this->casHelper,
    $this->casProxyHelper
      ->reveal(),
  ])
    ->getMock();
  $this->externalAuth
    ->method('load')
    ->willReturn(FALSE);
  $cas_user_manager
    ->expects($this
    ->never())
    ->method('register');
  $this->externalAuth
    ->expects($this
    ->never())
    ->method('userLoginFinalize');
  $this
    ->expectException('Drupal\\cas\\Exception\\CasLoginException', 'Cannot login, local Drupal user account does not exist.');
  $cas_user_manager
    ->login(new CasPropertyBag('test'), 'ticket');
}