You are here

public function CasUserInteractionTest::testUserInteraction in CAS 8

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

Tests user interaction.

File

tests/src/Functional/CasUserInteractionTest.php, line 49

Class

CasUserInteractionTest
Tests inserting user interaction into the flow.

Namespace

Drupal\Tests\cas\Functional

Code

public function testUserInteraction() {

  // The 'Legal Notice' has not been changed.
  \Drupal::state()
    ->set('cas_user_interaction_test.changed', FALSE);
  $this
    ->casLogin();
  $this
    ->assertUserLoggedIn();
  $this
    ->drupalLogout();

  // The 'Legal Notice' has been changed. Login again with CAS.
  \Drupal::state()
    ->set('cas_user_interaction_test.changed', TRUE);
  $this
    ->casLogin();
  $this
    ->assertUserNotLoggedIn();
  $this
    ->assertSession()
    ->pageTextContains("I agree with the 'Legal Notice'");

  // The user doesn't check the "I agree..." checkbox. Form doesn't validate.
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->pressButton('I agree');
  $this
    ->assertSession()
    ->pageTextContains("I agree with the 'Legal Notice' field is required.");
  $this
    ->assertUserNotLoggedIn();

  // The user checks the "I agree..." checkbox.
  $page
    ->checkField("I agree with the 'Legal Notice'");
  $page
    ->pressButton('I agree');
  $this
    ->assertUserLoggedIn();
}