You are here

function UserAdminLanguageTest::testUserAdminLanguageConfigurationAvailableIfAdminLanguageNegotiationIsEnabled in Zircon Profile 8

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

Tests that the admin language is configurable only for administrators.

If a user has the permission "access administration pages", they should be able to see the setting to pick the language they want those pages in.

If a user does not have that permission, it would confusing for them to have a setting for pages they cannot access, so they should not be able to set a language for those pages.

File

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

Class

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

Namespace

Drupal\user\Tests

Code

function testUserAdminLanguageConfigurationAvailableIfAdminLanguageNegotiationIsEnabled() {
  $this
    ->drupalLogin($this->adminUser);

  // Adds a new language, because with only one language, setting won't show.
  $this
    ->addCustomLanguage();
  $this
    ->setLanguageNegotiation();
  $path = 'user/' . $this->adminUser
    ->id() . '/edit';
  $this
    ->drupalGet($path);

  // Ensure administration pages language setting is visible for admin.
  $this
    ->assertFieldByXPath($this
    ->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector available for admins.');

  // Ensure administration pages language setting is hidden for non-admins.
  $this
    ->drupalLogin($this->regularUser);
  $path = 'user/' . $this->regularUser
    ->id() . '/edit';
  $this
    ->drupalGet($path);
  $this
    ->assertNoFieldByXPath($this
    ->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector not available for regular user.');
}