function UserAdminLanguageTest::testUserAdminLanguageConfigurationAvailableIfAdminLanguageNegotiationIsEnabled

Same name in other branches
  1. 9 core/modules/user/tests/src/Functional/UserAdminLanguageTest.php \Drupal\Tests\user\Functional\UserAdminLanguageTest::testUserAdminLanguageConfigurationAvailableIfAdminLanguageNegotiationIsEnabled()
  2. 8.9.x core/modules/user/tests/src/Functional/UserAdminLanguageTest.php \Drupal\Tests\user\Functional\UserAdminLanguageTest::testUserAdminLanguageConfigurationAvailableIfAdminLanguageNegotiationIsEnabled()
  3. 11.x 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 98

Class

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

Namespace

Drupal\Tests\user\Functional

Code

public function testUserAdminLanguageConfigurationAvailableIfAdminLanguageNegotiationIsEnabled() : void {
    $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->assertSession()
        ->fieldExists('edit-preferred-admin-langcode');
    // 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->assertSession()
        ->fieldExists('edit-preferred-admin-langcode');
    // Ensure administration pages language setting is hidden for non-admins.
    $this->drupalLogin($this->regularUser);
    $path = 'user/' . $this->regularUser
        ->id() . '/edit';
    $this->drupalGet($path);
    $this->assertSession()
        ->fieldNotExists('edit-preferred-admin-langcode');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.