You are here

public function CasAttributesSubscriberTest::testAllowedAttributesSettings in CAS Attributes 2.x

Tests that role mapping works as expected during login.

@dataProvider allowedAttributesSettings

File

tests/src/Unit/Subscriber/CasAttributesSubscriberTest.php, line 647

Class

CasAttributesSubscriberTest
CasAttributesSubscriber unit tests.

Namespace

Drupal\Tests\cas_attributes\Unit\Subscriber

Code

public function testAllowedAttributesSettings($settings, $cas_attributes, $expected_attributes) {
  $config_factory = $this
    ->getConfigFactoryStub($settings);
  $request = $this
    ->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Request')
    ->disableOriginalConstructor()
    ->getMock();
  $request
    ->expects($this
    ->any())
    ->method('getSession')
    ->willReturn($this->session);
  $this->requestStack
    ->expects($this
    ->any())
    ->method('getCurrentRequest')
    ->willReturn($request);
  $this->session
    ->expects($this
    ->any())
    ->method('set')
    ->will($this
    ->returnCallback([
    $this,
    'setSessionAttr',
  ]));
  $this->session
    ->expects($this
    ->any())
    ->method('get')
    ->will($this
    ->returnCallback([
    $this,
    'getSessionAttr',
  ]));
  $account = $this
    ->createMock('\\Drupal\\user\\UserInterface');
  $propertyBag = new CasPropertyBag('test');
  $propertyBag
    ->setAttributes($cas_attributes);
  $subscriber = new CasAttributesSubscriber($config_factory, $this->tokenService, $this->requestStack);
  $event = new CasPostLoginEvent($account, $propertyBag);
  $subscriber
    ->onPostLogin($event);
  $session = $this->requestStack
    ->getCurrentRequest()
    ->getSession();
  $attributes = $session
    ->get('cas_attributes');
  $this
    ->assertEquals($attributes, $expected_attributes);
}