Tests path-based URL generation.
public function testPathBasedURLGeneration() {
$base_path = '/subdir';
$base_url = 'http://www.example.com' . $base_path;
$this->generator
->setBasePath($base_path . '/');
$this->generator
->setBaseUrl($base_url . '/');
foreach (array(
'',
'index.php/',
) as $script_path) {
$this->generator
->setScriptPath($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 = $this->generator
->generateFromPath('node/123', array(
'absolute' => $absolute,
));
$this
->assertEquals($url, $result, "{$url} == {$result}");
$url = $base . 'node/123#foo';
$result = $this->generator
->generateFromPath('node/123', array(
'fragment' => 'foo',
'absolute' => $absolute,
));
$this
->assertEquals($url, $result, "{$url} == {$result}");
$url = $base . 'node/123?foo';
$result = $this->generator
->generateFromPath('node/123', array(
'query' => array(
'foo' => NULL,
),
'absolute' => $absolute,
));
$this
->assertEquals($url, $result, "{$url} == {$result}");
$url = $base . 'node/123?foo=bar&bar=baz';
$result = $this->generator
->generateFromPath('node/123', array(
'query' => array(
'foo' => 'bar',
'bar' => 'baz',
),
'absolute' => $absolute,
));
$this
->assertEquals($url, $result, "{$url} == {$result}");
$url = $base . 'node/123?foo#bar';
$result = $this->generator
->generateFromPath('node/123', array(
'query' => array(
'foo' => NULL,
),
'fragment' => 'bar',
'absolute' => $absolute,
));
$this
->assertEquals($url, $result, "{$url} == {$result}");
$url = $base;
$result = $this->generator
->generateFromPath('<front>', array(
'absolute' => $absolute,
));
$this
->assertEquals($url, $result, "{$url} == {$result}");
}
}
}