function CommonURLUnitTest::testUrl in SimpleTest 7
Test url() with/without query, with/without fragment, absolute on/off and assert all that works when clean URLs are on and off.
File
- tests/
common.test, line 199 - Tests for common.inc functionality.
Class
- CommonURLUnitTest
- Tests for URL generation functions.
Code
function testUrl() {
global $base_url;
foreach (array(
FALSE,
TRUE,
) as $absolute) {
// Get the expected start of the path string.
$base = $absolute ? $base_url . '/' : base_path();
$absolute_string = $absolute ? 'absolute' : NULL;
// Disable Clean URLs.
$GLOBALS['conf']['clean_url'] = 0;
$url = $base . '?q=node/123';
$result = url('node/123', array(
'absolute' => $absolute,
));
$this
->assertEqual($url, $result, "{$url} == {$result}");
$url = $base . '?q=node/123#foo';
$result = url('node/123', array(
'fragment' => 'foo',
'absolute' => $absolute,
));
$this
->assertEqual($url, $result, "{$url} == {$result}");
$url = $base . '?q=node/123&foo';
$result = url('node/123', array(
'query' => array(
'foo' => NULL,
),
'absolute' => $absolute,
));
$this
->assertEqual($url, $result, "{$url} == {$result}");
$url = $base . '?q=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 . '?q=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}");
// Enable Clean URLs.
$GLOBALS['conf']['clean_url'] = 1;
$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}");
}
}