diff --git a/core/modules/user/lib/Drupal/user/Tests/UserAdminLanguageTest.php b/core/modules/user/lib/Drupal/user/Tests/UserAdminLanguageTest.php new file mode 100644 index 0000000..8591069 --- /dev/null +++ b/core/modules/user/lib/Drupal/user/Tests/UserAdminLanguageTest.php @@ -0,0 +1,114 @@ + 'User administration pages language settings', + 'description' => "Tests user's ability to change their administation pages language.", + 'group' => 'User', + ); + } + + protected function setUp() { + parent::setUp(); + // User to add and remove language. + $this->admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages')); + // User to check non-admin access. + $this->regular_user = $this->drupalCreateUser(); + } + + /** + * Tests that admin language is not configurable in single language sites. + */ + function testUserAdminLanguageConfigurationNotAvailableWithOnlyOneLanguage() { + $this->drupalLogin($this->admin_user); + $this->setLanguageNegotiation(); + $path = 'user/' . $this->admin_user->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.'); + } + + /** + * Tests that admin language is configurable only if admin language negotiation + * is enabled. + */ + function testUserAdminLanguageConfigurationNotAvailableWithoutAdminLanguageNegotiation() { + $this->drupalLogin($this->admin_user); + $path = 'user/' . $this->admin_user->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.'); + } + + /** + * Tests that the admin language is configurable only for admins. + */ + function testUserAdminLanguageConfigurationAvailableIfAdminLanguageNegotiationIsEnabled() { + $this->drupalLogin($this->admin_user); + $this->addCustomLanguage(); + $this->setLanguageNegotiation(); + $path = 'user/' . $this->admin_user->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->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. + */ + function setLanguageNegotiation() { + $edit = array( + 'language_interface[enabled][language-user-admin]' => TRUE, + 'language_interface[enabled][language-url]' => TRUE, + 'language_interface[weight][language-user-admin]' => -8, + 'language_interface[weight][language-url]' => -10, + ); + $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings')); + } + + /** + * Helper meethod for adding a custom language. + */ + function addCustomLanguage() { + $langcode = 'xx'; + // The English name for the language. + $name = $this->randomName(16); + $edit = array( + 'predefined_langcode' => 'custom', + 'langcode' => $langcode, + 'name' => $name, + 'direction' => '0', + ); + $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language')); + } +}