You are here

public function RedirectMethodTest::testMessageDisplay in Entity Legal 8.2

Same name and namespace in other branches
  1. 4.0.x tests/src/Functional/RedirectMethodTest.php \Drupal\Tests\entity_legal\Functional\RedirectMethodTest::testMessageDisplay()
  2. 3.0.x tests/src/Functional/RedirectMethodTest.php \Drupal\Tests\entity_legal\Functional\RedirectMethodTest::testMessageDisplay()

Tests the case when the origin pages has set messages.

An origin page might have set status, warning or error messages to be displayed on the destination page. Test that such messages are not shown on the entity legal acceptance page.

File

tests/src/Functional/RedirectMethodTest.php, line 160

Class

RedirectMethodTest
Tests the 'redirect' plugin.

Namespace

Drupal\Tests\entity_legal\Functional

Code

public function testMessageDisplay() {
  $document = $this
    ->createDocument(TRUE, TRUE, [
    'existing_users' => [
      'require_method' => 'redirect',
    ],
  ]);
  $this
    ->createDocumentVersion($document, TRUE);
  $this
    ->drupalLogin($this
    ->createUserWithAcceptancePermissions($document));

  // Check that the acceptance form doesn't contain the messages.
  $this
    ->assertSession()
    ->pageTextContains('You must accept this agreement before continuing.');
  $this
    ->assertSession()
    ->pageTextNotContains('A status message sample');
  $this
    ->assertSession()
    ->pageTextNotContains('A warning message sample');
  $this
    ->assertSession()
    ->pageTextNotContains('An error message sample');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->checkField('I agree to the document');
  $page
    ->pressButton('Submit');

  // Check that messages are shown on the destination page.
  $account = User::load(\Drupal::currentUser()
    ->id());
  $this
    ->assertUrl($account
    ->toUrl());
  $this
    ->assertSession()
    ->pageTextContains('A status message sample');
  $this
    ->assertSession()
    ->pageTextContains('A warning message sample');
  $this
    ->assertSession()
    ->pageTextContains('An error message sample');
}