public function LanguageSwitchingTest::testLanguageSessionSwitchLinks in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/language/src/Tests/LanguageSwitchingTest.php \Drupal\language\Tests\LanguageSwitchingTest::testLanguageSessionSwitchLinks()
Tests language switcher links for session based negotiation.
File
- core/
modules/ language/ src/ Tests/ LanguageSwitchingTest.php, line 399 - Contains \Drupal\language\Tests\LanguageSwitchingTest.
Class
- LanguageSwitchingTest
- Functional tests for the language switching feature.
Namespace
Drupal\language\TestsCode
public function testLanguageSessionSwitchLinks() {
// Add language.
$edit = array(
'predefined_langcode' => 'fr',
);
$this
->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
// Enable session language detection and selection.
$edit = array(
'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, array(
'id' => 'test_language_block',
));
// Enable the main menu block.
$this
->drupalPlaceBlock('system_menu_block:main', array(
'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');
}