public function LanguageSwitchingTest::testLanguageSessionSwitchLinks in Drupal 8
Same name and namespace in other branches
- 9 core/modules/language/tests/src/Functional/LanguageSwitchingTest.php \Drupal\Tests\language\Functional\LanguageSwitchingTest::testLanguageSessionSwitchLinks()
- 10 core/modules/language/tests/src/Functional/LanguageSwitchingTest.php \Drupal\Tests\language\Functional\LanguageSwitchingTest::testLanguageSessionSwitchLinks()
Tests language switcher links for session based negotiation.
File
- core/
modules/ language/ tests/ src/ Functional/ LanguageSwitchingTest.php, line 415
Class
- LanguageSwitchingTest
- Functional tests for the language switching feature.
Namespace
Drupal\Tests\language\FunctionalCode
public function testLanguageSessionSwitchLinks() {
// Add language.
$edit = [
'predefined_langcode' => 'fr',
];
$this
->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
// Enable session language detection and selection.
$edit = [
'language_interface[enabled][language-url]' => FALSE,
'language_interface[enabled][language-session]' => TRUE,
];
$this
->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
// Enable the language switching block.
$this
->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, [
'id' => 'test_language_block',
]);
// Enable the main menu block.
$this
->drupalPlaceBlock('system_menu_block:main', [
'id' => 'test_menu',
]);
// Add a link to the homepage.
$link = MenuLinkContent::create([
'title' => 'Home',
'menu_name' => 'main',
'bundle' => 'menu_link_content',
'link' => [
[
'uri' => 'entity:user/2',
],
],
]);
$link
->save();
// Go to the homepage.
$this
->drupalGet('');
// Click on the French link.
$this
->clickLink(t('French'));
// There should be a query parameter to set the session language.
$this
->assertUrl('user/2', [
'query' => [
'language' => 'fr',
],
]);
// Click on the 'Home' Link.
$this
->clickLink(t('Home'));
// There should be no query parameter.
$this
->assertUrl('user/2');
// Click on the French link.
$this
->clickLink(t('French'));
// There should be no query parameter.
$this
->assertUrl('user/2');
}