You are here

protected function WebTestBase::assertUrl in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/WebTestBase.php \Drupal\simpletest\WebTestBase::assertUrl()

Passes if the internal browser's URL matches the given path.

Parameters

\Drupal\Core\Url|string $path: The expected system path or URL.

$options: (optional) Any additional options to pass for $path to the url generator.

$message: (optional) A message to display with the assertion. Do not translate messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed variables in the message text, not t(). If left blank, a default message will be displayed.

$group: (optional) The group this message is in, which is displayed in a column in test output. Use 'Debug' to indicate this is debugging output. Do not translate this string. Defaults to 'Other'; most tests do not override this default.

Return value

TRUE on pass, FALSE on fail.

80 calls to WebTestBase::assertUrl()
AddFeedTest::testAddFeed in core/modules/aggregator/src/Tests/AddFeedTest.php
Creates and ensures that a feed is unique, checks source, and deletes feed.
AdminTest::testCompactMode in core/modules/system/src/Tests/System/AdminTest.php
Test compact mode.
AjaxFormCacheTest::testQueryString in core/modules/system/src/Tests/Ajax/AjaxFormCacheTest.php
Tests AJAX forms on pages with a query string.
BasicTest::testViewsWizardAndListing in core/modules/views/src/Tests/Wizard/BasicTest.php
BlockContentTypeTest::testBlockContentTypeEditing in core/modules/block_content/src/Tests/BlockContentTypeTest.php
Tests editing a block type using the UI.

... See full list

File

core/modules/simpletest/src/WebTestBase.php, line 2700
Contains \Drupal\simpletest\WebTestBase.

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

Code

protected function assertUrl($path, array $options = array(), $message = '', $group = 'Other') {
  if ($path instanceof Url) {
    $url_obj = $path;
  }
  elseif (UrlHelper::isExternal($path)) {
    $url_obj = Url::fromUri($path, $options);
  }
  else {
    $uri = $path === '<front>' ? 'base:/' : 'base:/' . $path;

    // This is needed for language prefixing.
    $options['path_processing'] = TRUE;
    $url_obj = Url::fromUri($uri, $options);
  }
  $url = $url_obj
    ->setAbsolute()
    ->toString();
  if (!$message) {
    $message = SafeMarkup::format('Expected @url matches current URL (@current_url).', array(
      '@url' => var_export($url, TRUE),
      '@current_url' => $this
        ->getUrl(),
    ));
  }

  // Paths in query strings can be encoded or decoded with no functional
  // difference, decode them for comparison purposes.
  $actual_url = urldecode($this
    ->getUrl());
  $expected_url = urldecode($url);
  return $this
    ->assertEqual($actual_url, $expected_url, $message, $group);
}