You are here

public function CasEventsTest::testSettingPropertiesOnRegistration in CAS 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/CasEventsTest.php \Drupal\Tests\cas\Functional\CasEventsTest::testSettingPropertiesOnRegistration()

Tests we can use the CasPreRegisterEvent to alter user properties.

File

tests/src/Functional/CasEventsTest.php, line 25

Class

CasEventsTest
Class CasEventsTest.

Namespace

Drupal\Tests\cas\Functional

Code

public function testSettingPropertiesOnRegistration() {

  /* The "cas_test" module includes a subscriber to CasPreRegisterEvent
   * which will prefix all auto-registered users with "testing_"
   */
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'administer account settings',
  ]));
  $edit = [
    'user_accounts[auto_register]' => TRUE,
    'user_accounts[email_hostname]' => 'sample.com',
  ];
  $this
    ->drupalPostForm('/admin/config/people/cas', $edit, 'Save configuration');
  $cas_property_bag = new CasPropertyBag('foo');
  \Drupal::service('cas.user_manager')
    ->login($cas_property_bag, 'fake_ticket_string');
  $this
    ->assertFalse(user_load_by_name('foo'), 'User with name "foo" exists, but should not.');

  /** @var \Drupal\user\UserInterface $account */
  $account = user_load_by_name('testing_foo');
  $this
    ->assertNotFalse($account, 'User with name "testing_foo" was not found.');

  /** @var \Drupal\externalauth\AuthmapInterface $authmap */
  $authmap = \Drupal::service('externalauth.authmap');

  // Check that the external name has been registered correctly.
  $this
    ->assertSame('foo', $authmap
    ->get($account
    ->id(), 'cas'));
}