You are here

public function UserAdminLanguageTest::testActualNegotiation in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/user/tests/src/Functional/UserAdminLanguageTest.php \Drupal\Tests\user\Functional\UserAdminLanguageTest::testActualNegotiation()
  2. 9 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 122

Class

UserAdminLanguageTest
Tests users' ability to change their own administration language.

Namespace

Drupal\Tests\user\Functional

Code

public function testActualNegotiation() {
  $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');

  // 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');
}