You are here

protected function CasTestTrait::createCasUser in CAS 8

Same name and namespace in other branches
  1. 2.x tests/src/Traits/CasTestTrait.php \Drupal\Tests\cas\Traits\CasTestTrait::createCasUser()

Creates a CAS user and starts the CAS mock server.

Parameters

string $authname: The CAS authentication name.

string $email: The CAS user email.

string $password: The CAS server password.

array $attributes: (optional) Additional attributes to be added to the CAS account.

\Drupal\user\UserInterface|null $local_account: (optional) A user local account. If passed, the CAS user will be linked with the local user.

2 calls to CasTestTrait::createCasUser()
CasEventsTest::testLoginCancelling in tests/src/Functional/CasEventsTest.php
Tests cancelling the login process from a subscriber.
CasUserInteractionTest::setUp in tests/src/Functional/CasUserInteractionTest.php

File

tests/src/Traits/CasTestTrait.php, line 28

Class

CasTestTrait
Provides reusable code for tests.

Namespace

Drupal\Tests\cas\Traits

Code

protected function createCasUser($authname, $email, $password, array $attributes = [], UserInterface $local_account = NULL) {
  $cas_user = [
    'username' => $authname,
    'email' => $email,
    'password' => $password,
  ] + $attributes;
  \Drupal::service('cas_mock_server.user_manager')
    ->addUser($cas_user);

  // Link with the local account if it has been requested.
  if ($local_account) {
    \Drupal::service('externalauth.externalauth')
      ->linkExistingAccount($authname, 'cas', $local_account);
  }

  // Start the CAS mock server.
  \Drupal::service('cas_mock_server.server_manager')
    ->start();
}