function UserAdminLanguageTest::testActualNegotiation
Same name in other branches
- 9 core/modules/user/tests/src/Functional/UserAdminLanguageTest.php \Drupal\Tests\user\Functional\UserAdminLanguageTest::testActualNegotiation()
- 8.9.x core/modules/user/tests/src/Functional/UserAdminLanguageTest.php \Drupal\Tests\user\Functional\UserAdminLanguageTest::testActualNegotiation()
- 11.x core/modules/user/tests/src/Functional/UserAdminLanguageTest.php \Drupal\Tests\user\Functional\UserAdminLanguageTest::testActualNegotiation()
Tests the actual language negotiation.
File
-
core/
modules/ user/ tests/ src/ Functional/ UserAdminLanguageTest.php, line 125
Class
- UserAdminLanguageTest
- Tests users' ability to change their own administration language.
Namespace
Drupal\Tests\user\FunctionalCode
public function testActualNegotiation() : void {
$this->drupalLogin($this->adminUser);
$this->addCustomLanguage();
$this->setLanguageNegotiation();
// Even though we have admin language negotiation, so long as the user has
// no preference set, negotiation will fall back further.
$path = 'user/' . $this->adminUser
->id() . '/edit';
$this->drupalGet($path);
$this->assertSession()
->pageTextContains('Language negotiation method: language-default');
$this->drupalGet('xx/' . $path);
$this->assertSession()
->pageTextContains('Language negotiation method: language-url');
// Set a preferred language code for the user.
$edit = [];
$edit['preferred_admin_langcode'] = 'xx';
$this->drupalGet($path);
$this->submitForm($edit, 'Save');
// Test negotiation with the URL method first. The admin method will only
// be used if the URL method did not match.
$this->drupalGet($path);
$this->assertSession()
->pageTextContains('Language negotiation method: language-user-admin');
$this->drupalGet('xx/' . $path);
$this->assertSession()
->pageTextContains('Language negotiation method: language-url');
// Test negotiation with the admin language method first. The admin method
// will be used at all times.
$this->setLanguageNegotiation(TRUE);
$this->drupalGet($path);
$this->assertSession()
->pageTextContains('Language negotiation method: language-user-admin');
$this->drupalGet('xx/' . $path);
$this->assertSession()
->pageTextContains('Language negotiation method: language-user-admin');
// Make sure 'language-user-admin' plugin does not fail when a route is
// restricted to POST requests and language negotiation with the admin
// language method is used.
$this->drupalGet('/user-language-test/form');
$this->submitForm([], 'Send');
$this->assertSession()
->statusCodeEquals(200);
// Unset the preferred language code for the user.
$edit = [];
$edit['preferred_admin_langcode'] = '';
$this->drupalGet($path);
$this->submitForm($edit, 'Save');
$this->drupalGet($path);
$this->assertSession()
->pageTextContains('Language negotiation method: language-default');
$this->drupalGet('xx/' . $path);
$this->assertSession()
->pageTextContains('Language negotiation method: language-url');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.