function ConfigurableLanguageManagerTest::testUrlContentTranslationWithSessionLanguage
Same name in other branches
- 8.9.x core/modules/language/tests/src/Functional/ConfigurableLanguageManagerTest.php \Drupal\Tests\language\Functional\ConfigurableLanguageManagerTest::testUrlContentTranslationWithSessionLanguage()
- 10 core/modules/language/tests/src/Functional/ConfigurableLanguageManagerTest.php \Drupal\Tests\language\Functional\ConfigurableLanguageManagerTest::testUrlContentTranslationWithSessionLanguage()
- 11.x core/modules/language/tests/src/Functional/ConfigurableLanguageManagerTest.php \Drupal\Tests\language\Functional\ConfigurableLanguageManagerTest::testUrlContentTranslationWithSessionLanguage()
Tests translation with URL and Session Language Negotiators.
File
-
core/
modules/ language/ tests/ src/ Functional/ ConfigurableLanguageManagerTest.php, line 152
Class
- ConfigurableLanguageManagerTest
- Tests Language Negotiation.
Namespace
Drupal\Tests\language\FunctionalCode
public function testUrlContentTranslationWithSessionLanguage() {
$assert_session = $this->assertSession();
/** @var \Drupal\language\LanguageNegotiatorInterface $language_negotiator */
$language_negotiator = \Drupal::getContainer()->get('language_negotiator');
// Set Interface Language Negotiator to Session.
$language_negotiator->saveConfiguration('language_interface', [
'language-session' => 1,
'language-url' => 2,
'language-selected' => 3,
]);
// Set Content Language Negotiator to URL.
$language_negotiator->saveConfiguration('language_content', [
'language-url' => 4,
'language-selected' => 5,
]);
// See if the full view of the node in english is present and the
// string in the Powered By Block is in English.
$this->drupalGet('/node/1');
$assert_session->pageTextContains('English');
$assert_session->pageTextContains('Powered by');
// The language session variable has not been set yet, so
// The string should be in Spanish.
$this->drupalGet('/es/node/1');
$assert_session->pageTextContains('Español');
$assert_session->pageTextNotContains('Powered by');
$assert_session->pageTextContains('Funciona con');
// Set the session language to Spanish but load the English node page.
$this->drupalGet('/node/1', [
'query' => [
'language' => 'es',
],
]);
$assert_session->pageTextContains('English');
$assert_session->pageTextNotContains('Español');
$assert_session->pageTextContains('Funciona con');
$assert_session->pageTextNotContains('Powered by');
// Set the session language to English but load the node page in Spanish.
$this->drupalGet('/es/node/1', [
'query' => [
'language' => 'en',
],
]);
$assert_session->pageTextNotContains('English');
$assert_session->pageTextContains('Español');
$assert_session->pageTextNotContains('Funciona con');
$assert_session->pageTextContains('Powered by');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.