You are here

public function CasUserManagerTest::testEventListenerPreventsLogin 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::testEventListenerPreventsLogin()

An event listener prevents the user from logging in.

@covers ::login

File

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

Class

CasUserManagerTest
CasUserManager unit tests.

Namespace

Drupal\Tests\cas\Unit\Service

Code

public function testEventListenerPreventsLogin() {
  $cas_user_manager = $this
    ->getMockBuilder('Drupal\\cas\\Service\\CasUserManager')
    ->setMethods([
    'storeLoginSessionData',
  ])
    ->setConstructorArgs([
    $this->externalAuth,
    $this->authmap,
    $this
      ->getConfigFactoryStub(),
    $this->session,
    $this->connection,
    $this->eventDispatcher,
    $this->casHelper,
    $this->casProxyHelper
      ->reveal(),
  ])
    ->getMock();
  $this->account
    ->method('isactive')
    ->willReturn(TRUE);
  $this->externalAuth
    ->method('load')
    ->willReturn($this->account);
  $this->eventDispatcher
    ->method('dispatch')
    ->willReturnCallback(function ($event_type, $event) {
    if ($event instanceof CasPreLoginEvent) {
      $event
        ->cancelLogin();
    }
  });
  $cas_user_manager
    ->expects($this
    ->never())
    ->method('storeLoginSessionData');
  $this->externalAuth
    ->expects($this
    ->never())
    ->method('userLoginFinalize');
  $this
    ->expectException('Drupal\\cas\\Exception\\CasLoginException', 'Cannot login, an event listener denied access.');
  $cas_user_manager
    ->login(new CasPropertyBag('test'), 'ticket');
}