1 locale.test | private LocaleUrlRewritingTest::checkUrl($language, $message1, $message2) |
Check URL rewriting for the given language.
The test is performed with a fixed URL (the default home page) to check that language prefixes are not added to it, and that the prefixed URL is actually not working.
Parameters
string $language: The language prefix, e.g. 'es'.
string $message1: Message to display in assertion that language prefixes are not added.
string $message2: The message to display confirming prefixed URL is not working.
File
- core/
modules/ locale/ tests/ locale.test, line 2436 - Tests for locale.module.
Class
- LocaleUrlRewritingTest
- Test that URL rewriting works as expected.
Code
private function checkUrl($language, $message1, $message2) {
$options = array('language' => $language);
$base_path = trim(base_path(), '/');
$rewritten_path = trim(str_replace(array('?q=', $base_path), '', url('node', $options)), '/');
$segments = explode('/', $rewritten_path, 2);
$prefix = $segments[0];
$path = isset($segments[1]) ? $segments[1] : $prefix;
// If the rewritten URL has not a language prefix we pick a random prefix so
// we can always check the prefixed URL.
$prefixes = locale_language_negotiation_url_prefixes();
$stored_prefix = isset($prefixes[$language->langcode]) ? $prefixes[$language->langcode] : $this->randomName();
if ($this->assertNotEqual($stored_prefix, $prefix, $message1)) {
$prefix = $stored_prefix;
}
$this->backdropGet("$prefix/$path");
$this->assertResponse(404, $message2);
}