You are here

public function CasEventsTest::testLoginCancelling in CAS 2.x

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

Tests cancelling the login process from a subscriber.

File

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

Class

CasEventsTest
Tests CAS events.

Namespace

Drupal\Tests\cas\Functional

Code

public function testLoginCancelling() {

  // Create a local user.
  $account = $this
    ->createUser([], 'Antoine Batiste');

  // And a linked CAS user.
  $this
    ->createCasUser('Antoine Batiste', 'antoine@example.com', 'baTistE', [], $account);

  // Place the login/logout block so that we can check if user is logged in.
  $this
    ->placeBlock('system_menu_block:account');

  // Check the case when the subscriber didn't set a reason message.
  \Drupal::state()
    ->set('cas_test.flag', 'cancel login without message');
  $this
    ->casLogin('antoine@example.com', 'baTistE');
  $this
    ->assertSession()
    ->pageTextContains('You do not have access to log in to this website. Please contact a site administrator if you believe you should have access.');
  $this
    ->assertSession()
    ->linkExists('Log in');

  // Check the case when the subscriber has set a reason message.
  \Drupal::state()
    ->set('cas_test.flag', 'cancel login with message');
  $this
    ->casLogin('antoine@example.com', 'baTistE');
  $this
    ->assertSession()
    ->pageTextContains('Cancelled with a custom message.');
  $this
    ->assertSession()
    ->linkExists('Log in');
}