diff options
Diffstat (limited to 'modules/simpletest/drupal_web_test_case.php')
-rw-r--r-- | modules/simpletest/drupal_web_test_case.php | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index 37c5964bc..ca7502fb7 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -1789,42 +1789,28 @@ class DrupalWebTestCase extends DrupalTestCase { * Takes a path and returns an absolute path. * * @param $path - * The path, can be a Drupal path or a site-relative path. It might have a - * query, too. Can even be an absolute path which is just passed through. + * A path from the internal browser content. * @return - * An absolute path. - * - * @todo What is the intention of this function? It is only invoked from - * locations, where URLs from the *output* are turned into absolute URLs, - * so why do we pass that through url() again? + * The $path with $base_url prepended, if necessary. */ protected function getAbsoluteUrl($path) { + global $base_url, $base_path; + $parts = parse_url($path); - // This is more crude than menu_path_is_external() but enough here. if (empty($parts['host'])) { - $options = array('absolute' => TRUE); - $path = $parts['path']; - $base_path = base_path(); - $n = strlen($base_path); - if (substr($path, 0, $n) == $base_path) { - $path = substr($path, $n); + // Ensure that we have a string (and no xpath object). + $path = (string) $path; + // Strip $base_path, if existent. + $length = strlen($base_path); + if (substr($path, 0, $length) === $base_path) { + $path = substr($path, $length); } - if (isset($parts['query'])) { - parse_str($parts['query'], $options['query']); - // Let's make it a bit more crude. It's not clear why we invoke url() on - // a URL contained in the returned page output again, but since $path is - // FALSE (see $path = $parts['path'] above) with Clean URLs disabled, - // and url() now encodes the passed in query parameter array, we get a - // double-encoded 'q' query string in the resulting absolute URL - // generated by url(). This cannot be avoided in url(). But it could be - // completely avoided if this function wouldn't be calling url(). - // @see SimpleTestURLTestCase->testGetAbsoluteUrl() - if (isset($options['query']['q'])) { - $path = $options['query']['q']; - unset($options['query']['q']); - } + // Ensure that we have an absolute path. + if ($path[0] !== '/') { + $path = '/' . $path; } - $path = url($path, $options); + // Finally, prepend the $base_url. + $path = $base_url . $path; } return $path; } |