You are here

public function RedirectTest::testDestinationUrl in Login And Logout Redirect Per Role 8

Test allow_destination option.

File

tests/src/Functional/RedirectTest.php, line 157

Class

RedirectTest
Tests redirects after login and logout.

Namespace

Drupal\Tests\login_redirect_per_role\Functional

Code

public function testDestinationUrl() {

  // Test redirect with allow_destination enabled.
  $this
    ->drupalGet(Url::fromRoute('user.login', [], [
    'query' => [
      'destination' => 'destination-url',
    ],
  ]));
  $this
    ->submitForm([
    'name' => $this->user1
      ->getAccountName(),
    'pass' => $this->user1->passRaw,
  ], 'Log in');
  $this
    ->assertSession()
    ->addressEquals('destination-url');
  $this
    ->drupalGet(Url::fromRoute('user.logout', [], [
    'query' => [
      'destination' => 'destination-url',
    ],
  ]));
  $this
    ->assertSession()
    ->addressEquals('destination-url');

  // Test redirect with allow_destination disabled.
  $this
    ->drupalGet(Url::fromRoute('user.login', [], [
    'query' => [
      'destination' => 'destination-url',
    ],
  ]));
  $this
    ->submitForm([
    'name' => $this->user2
      ->getAccountName(),
    'pass' => $this->user2->passRaw,
  ], 'Log in');
  $this
    ->assertSession()
    ->addressEquals('login-url-role2');
  $this
    ->drupalGet(Url::fromRoute('user.logout', [], [
    'query' => [
      'destination' => 'destination-url',
    ],
  ]));
  $this
    ->assertSession()
    ->addressEquals('logout-url-role2');
}