You are here

public function GlobalRedirectTest::assertRedirect in Redirect 8

Visits a path and asserts that it is a redirect.

Parameters

string $path: The request path.

string $expected_destination: The path where we expect it to redirect. If NULL value provided, no redirect is expected.

int $status_code: The status we expect to get with the first request.

Throws

\Behat\Mink\Exception\ExpectationException

2 calls to GlobalRedirectTest::assertRedirect()
GlobalRedirectTest::testLanguageRedirects in tests/src/Functional/GlobalRedirectTest.php
Test that redirects work properly with content_translation enabled.
GlobalRedirectTest::testRedirects in tests/src/Functional/GlobalRedirectTest.php
Will test the redirects.

File

tests/src/Functional/GlobalRedirectTest.php, line 299

Class

GlobalRedirectTest
Global redirect test cases.

Namespace

Drupal\Tests\redirect\Functional

Code

public function assertRedirect($path, $expected_destination, $status_code = 301) {

  // Always just use getAbsolutePath() so that generating the link does not
  // alter special requests.
  $url = $this
    ->getAbsoluteUrl($path);
  $this
    ->getSession()
    ->visit($url);

  // Ensure that any changes to variables in the other thread are picked up.
  $this
    ->refreshVariables();
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->responseHeaderEquals('Location', $this
    ->getAbsoluteUrl($expected_destination));
  $assert_session
    ->statusCodeEquals($status_code);
}