UserLanguageTest.php in Drupal 8
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 {
public 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
->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
$this
->drupalLogout();
$this
->drupalLogin($web_user);
$path = 'user/' . $web_user
->id() . '/edit';
$this
->drupalGet($path);
$this
->assertText(t('Language'), 'Language selector available.');
$this
->assertText($name, 'Language present on form.');
$edit = [
'preferred_langcode' => $langcode,
];
$this
->drupalPostForm($path, $edit, t('Save'));
$this
->assertText(t('The changes have been saved.'), 'Changes were saved.');
$this
->assertOptionSelected('edit-preferred-langcode', $langcode, 'Default language successfully updated.');
$this
->drupalLogout();
}
}
Classes
Name |
Description |
UserLanguageTest |
Functional tests for a user's ability to change their default language. |