diff --git a/core/modules/user/lib/Drupal/user/Tests/UserAdminLanguageTest.php b/core/modules/user/lib/Drupal/user/Tests/UserAdminLanguageTest.php index 110c2fd..62da2c3 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserAdminLanguageTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserAdminLanguageTest.php @@ -13,8 +13,20 @@ * Tests users' ability to change their own administration language. */ class UserAdminLanguageTest extends WebTestBase { - protected $admin_user; - protected $regular_user; + + /** + * Administrator user for this test. + * + * @var \Drupal\user\Entity\User + */ + protected $adminUser; + + /** + * Non-administrator user for this test. + * + * @var \Drupal\user\Entity\User + */ + protected $regularUser; /** * Modules to enable. @@ -34,7 +46,7 @@ public static function getInfo() { public function setUp() { parent::setUp(); // User to add and remove language. - $this->admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages')); + $this->adminUser = $this->drupalCreateUser(array('administer languages', 'access administration pages')); // User to check non-admin access. $this->regular_user = $this->drupalCreateUser(); } @@ -43,9 +55,9 @@ public function setUp() { * Tests that admin language is not configurable in single language sites. */ function testUserAdminLanguageConfigurationNotAvailableWithOnlyOneLanguage() { - $this->drupalLogin($this->admin_user); + $this->drupalLogin($this->adminUser); $this->setLanguageNegotiation(); - $path = 'user/' . $this->admin_user->id() . '/edit'; + $path = 'user/' . $this->adminUser->id() . '/edit'; $this->drupalGet($path); // Ensure administration pages language settings widget is not available. $this->assertNoFieldById('edit-preferred-admin-langcode', '', 'Administration pages language selector not available.'); @@ -54,36 +66,56 @@ function testUserAdminLanguageConfigurationNotAvailableWithOnlyOneLanguage() { /** * Tests that admin language negotiation is configurable only if enabled. */ - function testUserAdminLanguageConfigurationNotAvailableWithoutAdminLanguageNegotiation() { - $this->drupalLogin($this->admin_user); - $path = 'user/' . $this->admin_user->id() . '/edit'; + function testUserAdminLanguageConfigurationAvailableWithAdminLanguageNegotiation() { + $this->drupalLogin($this->adminUser); + $this->addCustomLanguage(); + $path = 'user/' . $this->adminUser->id() . '/edit'; + + // Checks with user administration pages language negotiation disabled. $this->drupalGet($path); // Ensure administration pages language settings widget is not available. $this->assertNoFieldById('edit-preferred-admin-langcode', '', 'Administration pages language selector not available.'); + + // Checks with user administration pages language negotiation enabled. + $this->setLanguageNegotiation(); + $this->drupalGet($path); + // Ensure administration pages language settings widget is available. + $this->assertFieldById('edit-preferred-admin-langcode', '', 'Administration pages language selector not available.'); } /** - * Tests that the admin language is configurable only for admins. + * 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. */ function testUserAdminLanguageConfigurationAvailableIfAdminLanguageNegotiationIsEnabled() { - $this->drupalLogin($this->admin_user); + $this->drupalLogin($this->adminUser); + // Adds a new language, because with only one language the setting won't show. $this->addCustomLanguage(); $this->setLanguageNegotiation(); - $path = 'user/' . $this->admin_user->id() . '/edit'; + $path = 'user/' . $this->adminUser->id() . '/edit'; $this->drupalGet($path); // Ensure administration pages language settings widget is available for admin. $this->assertFieldById('edit-preferred-admin-langcode', 'en', 'Administration pages language selector available for admins.'); // Ensure administration pages language settings widget is not available // for regular users. - $this->drupalLogin($this->regular_user); - $path = 'user/' . $this->regular_user->id() . '/edit'; + $this->drupalLogin($this->regularUser); + $path = 'user/' . $this->regularUser->id() . '/edit'; $this->drupalGet($path); $this->assertNoFieldById('edit-preferred-admin-langcode', '', 'Administration pages language selector not available for regular user.'); } /** - * Helper method for setting the language user admin negotiation. + * Sets the User interface negotiation detection method. + * + * Enables the "Account preference for administration pages" language + * detection method for the User interface language negotiation type. */ function setLanguageNegotiation() { $edit = array( @@ -110,4 +142,5 @@ function addCustomLanguage() { ); $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language')); } + }