private function LanguageUrlRewritingTest::checkUrl in Drupal 8
Same name and namespace in other branches
- 9 core/modules/language/tests/src/Functional/LanguageUrlRewritingTest.php \Drupal\Tests\language\Functional\LanguageUrlRewritingTest::checkUrl()
- 10 core/modules/language/tests/src/Functional/LanguageUrlRewritingTest.php \Drupal\Tests\language\Functional\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 $message: Message to display in assertion that language prefixes are not added.
1 call to LanguageUrlRewritingTest::checkUrl()
- LanguageUrlRewritingTest::testUrlRewritingEdgeCases in core/
modules/ language/ tests/ src/ Functional/ LanguageUrlRewritingTest.php - Check that non-installed languages are not considered.
File
- core/
modules/ language/ tests/ src/ Functional/ LanguageUrlRewritingTest.php, line 87
Class
- LanguageUrlRewritingTest
- Tests that URL rewriting works as expected.
Namespace
Drupal\Tests\language\FunctionalCode
private function checkUrl(LanguageInterface $language, $message) {
$options = [
'language' => $language,
'script' => '',
];
$base_path = trim(base_path(), '/');
$rewritten_path = trim(str_replace($base_path, '', Url::fromRoute('<front>', [], $options)
->toString()), '/');
$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 = $this
->config('language.negotiation')
->get('url.prefixes');
$stored_prefix = isset($prefixes[$language
->getId()]) ? $prefixes[$language
->getId()] : $this
->randomMachineName();
$this
->assertNotEqual($stored_prefix, $prefix, $message);
$prefix = $stored_prefix;
$this
->drupalGet("{$prefix}/{$path}");
$this
->assertSession()
->statusCodeEquals(404);
}