You are here

public function UserAdminLanguageTest::testUserAdminLanguageConfigurationAvailableIfAdminLanguageNegotiationIsEnabled in Drupal 8

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

Tests that the admin language is configurable only for administrators.

If a user has the permission "access administration pages" or "view the administration theme", 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/tests/src/Functional/UserAdminLanguageTest.php, line 95

Class

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

Namespace

Drupal\Tests\user\Functional

Code

public 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 visible for editors.
  $editor = $this
    ->drupalCreateUser([
    'view the administration theme',
  ]);
  $this
    ->drupalLogin($editor);
  $path = 'user/' . $editor
    ->id() . '/edit';
  $this
    ->drupalGet($path);
  $this
    ->assertFieldByXPath($this
    ->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector available for editors.');

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