1 redirect.test protected RedirectTestHelper::addRedirect($source_path, $redirect_path, array $redirect = array())

Add an URL redirection.

Parameters

string $source_path: A source path.

string $redirect_path: A redirect path.

array $redirect: An array of values from which a Redirect object will be created.

Return value

Redirect: A redirect object.

File

core/modules/redirect/tests/redirect.test, line 54
Unit tests for the redirect module.

Class

RedirectTestHelper

Code

protected function addRedirect($source_path, $redirect_path, array $redirect = array()) {
  $source_parsed = redirect_parse_url($source_path);
  $redirect['source'] = $source_parsed['url'];
  if (isset($source_parsed['query'])) {
    $redirect['source_options']['query'] = $source_parsed['query'];
  }

  $redirect_parsed = redirect_parse_url($redirect_path);
  $redirect['redirect'] = $redirect_parsed['url'];
  if (isset($redirect_parsed['query'])) {
    $redirect['redirect_options']['query'] = $redirect_parsed['query'];
  }
  if (isset($redirect_parsed['fragment'])) {
    $redirect['redirect_options']['fragment'] = $redirect_parsed['fragment'];
  }

  $redirect_object = new Redirect($redirect);
  redirect_save($redirect_object);
  return $redirect_object;
}