You are here

public function CasAttributesSubscriberTest::testMapFieldsOnLogin in CAS Attributes 8

Same name and namespace in other branches
  1. 2.x tests/src/Unit/Subscriber/CasAttributesSubscriberTest.php \Drupal\Tests\cas_attributes\Unit\Subscriber\CasAttributesSubscriberTest::testMapFieldsOnLogin()

Test the field mapping functionality for username.

@dataProvider mapFieldsOnLogin

File

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

Class

CasAttributesSubscriberTest
CasAttributesSubscriber unit tests.

Namespace

Drupal\Tests\cas_attributes\Unit\Subscriber

Code

public function testMapFieldsOnLogin($mappings, $attributes, $overwrite, $empty) {
  $config_factory = $this
    ->getConfigFactoryStub([
    'cas_attributes.settings' => [
      'field.mappings' => $mappings,
      'field.overwrite' => $overwrite,
      'field.sync_frequency' => CasAttributesSettings::SYNC_FREQUENCY_EVERY_LOGIN,
    ],
  ]);
  $this->propertyBag
    ->expects($this
    ->any())
    ->method('getAttributes')
    ->willReturn($attributes);
  $this->tokenService
    ->expects($this
    ->any())
    ->method('replace')
    ->will($this
    ->returnCallback([
    $this,
    'tokenReplace',
  ]));
  if ($empty || $overwrite) {
    $this->account
      ->expects($this
      ->once())
      ->method('set')
      ->with('name', $attributes[$mappings['name']][0]);
  }
  else {
    $this->account
      ->expects($this
      ->never())
      ->method('setUsername');
  }
  $event = new CasPreLoginEvent($this->account, $this->propertyBag);
  $subscriber = new CasAttributesSubscriber($config_factory, $this->tokenService, $this->requestStack);
  $subscriber
    ->onPreLogin($event);
}