In a Kernel test I need to test the result of an url object per language. But the test doesn't consider the language settings.
Example:
public function register(ContainerBuilder $container) {
parent::register($container);
$language = Language::$defaultValues;
$language['id'] = 'de';
$language['name'] = 'German';
$container->setParameter('language.default_values', $language);
}
protected function setUp() {
parent::setUp();
ConfigurableLanguage::createFromLangcode('fr')->save();
ConfigurableLanguage::createFromLangcode('it')->save();
}
public function testUrls() {
$languageManager = $this->container->get('language_manager');
print_r($languageManager->getLanguages());
$url = Url::fromRoute('<front>');
$url->setOption('language', $languageManager->getLanguage('fr'));
print_r($url->toString());
}
Output:
Array
(
[de]
[fr]
[it]
)
# Output of toString()
/
The output of toString should be /fr
instead of /
Addendum:
I discovered that the \Drupal\language\HttpKernel\PathProcessorLanguage
outbound processor is missing, when UrlGenerator::processPath()
is called from the Kernel test. Therefore, I registered it in the Kernel test's register method, but that doesn't solve the problem.