You are here

function UserAdminLanguageTest::testActualNegotiation in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/user/src/Tests/UserAdminLanguageTest.php \Drupal\user\Tests\UserAdminLanguageTest::testActualNegotiation()

Tests the actual language negotiation.

File

core/modules/user/src/Tests/UserAdminLanguageTest.php, line 111
Contains \Drupal\user\Tests\UserAdminLanguageTest.

Class

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

Namespace

Drupal\user\Tests

Code

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
    ->assertText('Language negotiation method: language-default');
  $this
    ->drupalGet('xx/' . $path);
  $this
    ->assertText('Language negotiation method: language-url');

  // Set a preferred language code for the user.
  $edit = array();
  $edit['preferred_admin_langcode'] = 'xx';
  $this
    ->drupalPostForm($path, $edit, t('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
    ->assertText('Language negotiation method: language-user-admin');
  $this
    ->drupalGet('xx/' . $path);
  $this
    ->assertText('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
    ->assertText('Language negotiation method: language-user-admin');
  $this
    ->drupalGet('xx/' . $path);
  $this
    ->assertText('Language negotiation method: language-user-admin');

  // Unset the preferred language code for the user.
  $edit = array();
  $edit['preferred_admin_langcode'] = '';
  $this
    ->drupalPostForm($path, $edit, t('Save'));
  $this
    ->drupalGet($path);
  $this
    ->assertText('Language negotiation method: language-default');
  $this
    ->drupalGet('xx/' . $path);
  $this
    ->assertText('Language negotiation method: language-url');
}