You are here

protected function RedirectTestHelper::addRedirect in Redirect 7.2

Same name and namespace in other branches
  1. 7 redirect.test \RedirectTestHelper::addRedirect()

Add an URL redirection

Parameters

$source: A source path.

$redirect: A redirect path.

3 calls to RedirectTestHelper::addRedirect()
RedirectFunctionalTest::testDisableEnableRedirect in ./redirect.test
RedirectFunctionalTest::testPageCache in ./redirect.test
RedirectUnitTest::testLoadRedirectsBySource in ./redirect.test
Test redirect_load_by_source().

File

./redirect.test, line 40
Unit tests for the redirect module.

Class

RedirectTestHelper
@file Unit tests for the redirect module.

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 stdClass();
  redirect_object_prepare($redirect_object, $redirect);
  redirect_save($redirect_object);
  return $redirect_object;
}