UserLanguageTest.php in Drupal 10
File
core/modules/user/tests/src/Functional/UserLanguageTest.php
View source
<?php
namespace Drupal\Tests\user\Functional;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Tests\BrowserTestBase;
class UserLanguageTest extends BrowserTestBase {
protected static $modules = [
'user',
'language',
];
protected $defaultTheme = 'stark';
public function testUserLanguageConfiguration() {
$admin_user = $this
->drupalCreateUser([
'administer languages',
'access administration pages',
]);
$web_user = $this
->drupalCreateUser();
$this
->drupalLogin($admin_user);
$langcode = 'xx';
$name = $this
->randomMachineName(16);
$edit = [
'predefined_langcode' => 'custom',
'langcode' => $langcode,
'label' => $name,
'direction' => LanguageInterface::DIRECTION_LTR,
];
$this
->drupalGet('admin/config/regional/language/add');
$this
->submitForm($edit, 'Add custom language');
$this
->drupalLogout();
$this
->drupalLogin($web_user);
$path = 'user/' . $web_user
->id() . '/edit';
$this
->drupalGet($path);
$this
->assertSession()
->pageTextContains('Language');
$this
->assertSession()
->pageTextContains($name);
$edit = [
'preferred_langcode' => $langcode,
];
$this
->drupalGet($path);
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->pageTextContains('The changes have been saved.');
$this
->assertTrue($this
->assertSession()
->optionExists('edit-preferred-langcode', $langcode)
->isSelected());
$this
->drupalLogout();
}
}
Classes
Name |
Description |
UserLanguageTest |
Functional tests for a user's ability to change their default language. |