You are here

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

A user is able to login when their account exists.

@covers ::login

File

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

Class

CasUserManagerTest
CasUserManager unit tests.

Namespace

Drupal\Tests\cas\Unit\Service

Code

public function testExistingAccountIsLoggedIn() {
  $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);
  $cas_user_manager
    ->expects($this
    ->once())
    ->method('storeLoginSessionData');
  $this->externalAuth
    ->expects($this
    ->once())
    ->method('userLoginFinalize')
    ->willReturn($this->account);
  $attributes = [
    'attr1' => 'foo',
    'attr2' => 'bar',
  ];
  $this->session
    ->method('set')
    ->withConsecutive([
    'is_cas_user',
    TRUE,
  ], [
    'cas_username',
    'test',
  ]);
  $propertyBag = new CasPropertyBag('test');
  $propertyBag
    ->setAttributes($attributes);
  $cas_user_manager
    ->login($propertyBag, 'ticket');
}