You are here

public function GlobalRedirectTest::assertRedirect in Global Redirect 8

Asserts the redirect from $path to the $expected_ending_url.

Parameters

string $path: The request path.

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

string $expected_ending_status: The status we expect to get with the first request.

1 call to GlobalRedirectTest::assertRedirect()
GlobalRedirectTest::testRedirects in src/Tests/GlobalRedirectTest.php
Will test the redirects.

File

src/Tests/GlobalRedirectTest.php, line 188
Global Redirect functionality tests

Class

GlobalRedirectTest
Global redirect test cases.

Namespace

Drupal\globalredirect\Tests

Code

public function assertRedirect($path, $expected_ending_url, $expected_ending_status = 'HTTP/1.1 301 Moved Permanently') {
  $this
    ->drupalHead($GLOBALS['base_url'] . '/' . $path);
  $headers = $this
    ->drupalGetHeaders(TRUE);
  $ending_url = isset($headers[0]['location']) ? $headers[0]['location'] : NULL;
  $message = SafeMarkup::format('Testing redirect from %from to %to. Ending url: %url', array(
    '%from' => $path,
    '%to' => $expected_ending_url,
    '%url' => $ending_url,
  ));
  if ($expected_ending_url == '<front>') {
    $expected_ending_url = $GLOBALS['base_url'] . '/';
  }
  elseif (!empty($expected_ending_url)) {
    $expected_ending_url = $GLOBALS['base_url'] . '/' . $expected_ending_url;
  }
  else {
    $expected_ending_url = NULL;
  }
  $this
    ->assertEqual($expected_ending_url, $ending_url, $message);
  $this
    ->assertEqual($headers[0][':status'], $expected_ending_status);
}