You are here

protected function CasTestTrait::createCasUser in CAS 2.x

Same name and namespace in other branches
  1. 8 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.

3 calls to CasTestTrait::createCasUser()
CasEventsTest::testLoginCancelling in tests/src/Functional/CasEventsTest.php
Tests cancelling the login process from a subscriber.
CasEventsTest::testRegistrationCancelling in tests/src/Functional/CasEventsTest.php
Tests cancelling the login with auto register 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();
}