You are here

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

Test access to the settings form.

File

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

Class

RedirectTest
Tests redirects after login and logout.

Namespace

Drupal\Tests\login_redirect_per_role\Functional

Code

public function testLoginAndLogoutRedirectUrl() {
  $this
    ->drupalLogin($this->user1);
  $this
    ->assertSession()
    ->addressEquals('login-url-role1');
  $this
    ->drupalGet(Url::fromRoute('user.logout'));
  $this
    ->assertSession()
    ->addressEquals('logout-url-role1');
  $this
    ->drupalLogin($this->user2);
  $this
    ->assertSession()
    ->addressEquals('login-url-role2');
  $this
    ->drupalGet(Url::fromRoute('user.logout'));
  $this
    ->assertSession()
    ->addressEquals('logout-url-role2');

  // Test redirect with token.
  $this
    ->drupalLogin($this->user3);
  $this
    ->assertSession()
    ->addressEquals('valid-path');
  $this
    ->drupalGet(Url::fromRoute('user.logout'));
  $this
    ->assertSession()
    ->addressEquals('invalid-path');

  // Test <front> as destination URL.
  $this
    ->drupalLogin($this->user4);

  // The default front page is /user/login so the user is redirected to it's
  // own user page.
  $this
    ->assertSession()
    ->addressEquals('user/' . $this->user4
    ->id());
  $this
    ->drupalGet(Url::fromRoute('user.logout'));
  $this
    ->assertSession()
    ->addressEquals('');
}