function UrlTest::testUrl

Tests url() functionality.

Tests url() with/without query, with/without fragment, absolute on/off and asserts all that works when clean URLs are on and off.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Common/UrlTest.php, line 179
Definition of Drupal\system\Tests\Common\UrlTest.

Class

UrlTest
Tests for URL generation functions.

Namespace

Drupal\system\Tests\Common

Code

function testUrl() {
  global $base_url, $script_path;
  $script_path_original = $script_path;
  foreach (array(
    '',
    'index.php/',
  ) as $script_path) {
    foreach (array(
      FALSE,
      TRUE,
    ) as $absolute) {

      // Get the expected start of the path string.
      $base = ($absolute ? $base_url . '/' : base_path()) . $script_path;
      $absolute_string = $absolute ? 'absolute' : NULL;
      $url = $base . 'node/123';
      $result = url('node/123', array(
        'absolute' => $absolute,
      ));
      $this
        ->assertEqual($url, $result, "{$url} == {$result}");
      $url = $base . 'node/123#foo';
      $result = url('node/123', array(
        'fragment' => 'foo',
        'absolute' => $absolute,
      ));
      $this
        ->assertEqual($url, $result, "{$url} == {$result}");
      $url = $base . 'node/123?foo';
      $result = url('node/123', array(
        'query' => array(
          'foo' => NULL,
        ),
        'absolute' => $absolute,
      ));
      $this
        ->assertEqual($url, $result, "{$url} == {$result}");
      $url = $base . 'node/123?foo=bar&bar=baz';
      $result = url('node/123', array(
        'query' => array(
          'foo' => 'bar',
          'bar' => 'baz',
        ),
        'absolute' => $absolute,
      ));
      $this
        ->assertEqual($url, $result, "{$url} == {$result}");
      $url = $base . 'node/123?foo#bar';
      $result = url('node/123', array(
        'query' => array(
          'foo' => NULL,
        ),
        'fragment' => 'bar',
        'absolute' => $absolute,
      ));
      $this
        ->assertEqual($url, $result, "{$url} == {$result}");
      $url = $base;
      $result = url('<front>', array(
        'absolute' => $absolute,
      ));
      $this
        ->assertEqual($url, $result, "{$url} == {$result}");
    }
  }
  $script_path = $script_path_original;
}