function UserEditTest::testUserChangeSiteLanguage
Same name in other branches
- 9 core/modules/user/tests/src/Functional/UserEditTest.php \Drupal\Tests\user\Functional\UserEditTest::testUserChangeSiteLanguage()
- 8.9.x core/modules/user/tests/src/Functional/UserEditTest.php \Drupal\Tests\user\Functional\UserEditTest::testUserChangeSiteLanguage()
- 10 core/modules/user/tests/src/Functional/UserEditTest.php \Drupal\Tests\user\Functional\UserEditTest::testUserChangeSiteLanguage()
Tests that a user is able to change site language.
File
-
core/
modules/ user/ tests/ src/ Functional/ UserEditTest.php, line 200
Class
- UserEditTest
- Tests user edit page.
Namespace
Drupal\Tests\user\FunctionalCode
public function testUserChangeSiteLanguage() : void {
// Install these modules here as these aren't needed for other test methods.
\Drupal::service('module_installer')->install([
'content_translation',
'language',
]);
// Create and login as an admin user to add a new language and enable
// translation for user accounts.
$adminUser = $this->drupalCreateUser([
'administer account settings',
'administer languages',
'administer content translation',
'administer users',
'translate any entity',
]);
$this->drupalLogin($adminUser);
// Add a new language into the system.
$edit = [
'predefined_langcode' => 'fr',
];
$this->drupalGet('admin/config/regional/language/add');
$this->submitForm($edit, 'Add language');
$this->assertSession()
->pageTextContains('French');
// Enable translation for user accounts.
$edit = [
'language[content_translation]' => 1,
];
$this->drupalGet('admin/config/people/accounts');
$this->submitForm($edit, 'Save configuration');
$this->assertSession()
->pageTextContains('The configuration options have been saved.');
// Create a regular user for whom translation will be enabled.
$webUser = $this->drupalCreateUser();
// Create a translation for a regular user account.
$this->drupalGet('user/' . $webUser->id() . '/translations/add/en/fr');
$this->submitForm([], 'Save');
$this->assertSession()
->pageTextContains('The changes have been saved.');
// Update the site language of the user account.
$edit = [
'preferred_langcode' => 'fr',
];
$this->drupalGet('user/' . $webUser->id() . '/edit');
$this->submitForm($edit, 'Save');
$this->assertSession()
->statusCodeEquals(200);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.