private function LanguageUrlRewritingTest::checkUrl in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/language/src/Tests/LanguageUrlRewritingTest.php \Drupal\language\Tests\LanguageUrlRewritingTest::checkUrl()
Check URL rewriting for the given language.
The test is performed with a fixed URL (the default front page) to simply check that language prefixes are not added to it and that the prefixed URL is actually not working.
Parameters
\Drupal\Core\Language\LanguageInterface $language: The language object.
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.
1 call to LanguageUrlRewritingTest::checkUrl()
- LanguageUrlRewritingTest::testUrlRewritingEdgeCases in core/
modules/ language/ src/ Tests/ LanguageUrlRewritingTest.php - Check that non-installed languages are not considered.
File
- core/
modules/ language/ src/ Tests/ LanguageUrlRewritingTest.php, line 86 - Contains \Drupal\language\Tests\LanguageUrlRewritingTest.
Class
- LanguageUrlRewritingTest
- Tests that URL rewriting works as expected.
Namespace
Drupal\language\TestsCode
private function checkUrl(LanguageInterface $language, $message1, $message2) {
$options = array(
'language' => $language,
'script' => '',
);
$base_path = trim(base_path(), '/');
$rewritten_path = trim(str_replace($base_path, '', \Drupal::url('<front>', array(), $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 = language_negotiation_url_prefixes();
$stored_prefix = isset($prefixes[$language
->getId()]) ? $prefixes[$language
->getId()] : $this
->randomMachineName();
if ($this
->assertNotEqual($stored_prefix, $prefix, $message1)) {
$prefix = $stored_prefix;
}
$this
->drupalGet("{$prefix}/{$path}");
$this
->assertResponse(404, $message2);
}