1 locale.test | LocaleUserLanguageFunctionalTest::testUserLanguageConfiguration() |
Test if user can change their default language.
File
- core/
modules/ locale/ tests/ locale.test, line 1544 - Tests for locale.module.
Class
- LocaleUserLanguageFunctionalTest
- Functional tests for a user's ability to change their default language.
Code
function testUserLanguageConfiguration() {
global $base_url;
// User to add and remove language.
$admin_user = $this->backdropCreateUser(array('administer languages', 'access administration pages'));
// User to change their default language.
$web_user = $this->backdropCreateUser();
// Add custom language.
$this->backdropLogin($admin_user);
// Code for the language.
$langcode = 'xx';
// The English name for the language.
$name = $this->randomName(16);
$edit = array(
'predefined_langcode' => 'custom',
'langcode' => $langcode,
'name' => $name,
'native' => $name,
'direction' => '0',
);
$this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));
// Add custom language and disable it.
// Code for the language.
$langcode_disabled = 'xx-yy';
// The English name for the language. This will be translated.
$name_disabled = $this->randomName(16);
$edit = array(
'predefined_langcode' => 'custom',
'langcode' => $langcode_disabled,
'name' => $name_disabled,
'native' => $name_disabled,
'direction' => '0',
);
$this->backdropPost('admin/config/regional/language/add', $edit, t('Add custom language'));
// Disable the language.
$edit = array(
'languages[' . $langcode_disabled . '][enabled]' => FALSE,
);
$this->backdropPost('admin/config/regional/language', $edit, t('Save configuration'));
$this->backdropLogout();
// Login as normal user and edit account settings.
$this->backdropLogin($web_user);
$path = 'user/' . $web_user->uid . '/edit';
$this->backdropGet($path);
// Ensure language settings fieldset is available.
$this->assertText(t('Language'), 'Language selector available.');
// Ensure custom language is present.
$this->assertText($name, 'Language present on form.');
// Ensure disabled language isn't present.
$this->assertNoText($name_disabled, 'Disabled language not present on form.');
// Switch to our custom language.
$edit = array(
'language' => $langcode,
);
$this->backdropPost($path, $edit, t('Save'));
// Ensure form was submitted successfully.
$this->assertText(t('The changes have been saved.'), 'Changes were saved.');
// Check if language was changed.
$this->backdropGet($path);
$elements = $this->xpath('//input[@id=:id]', array(':id' => 'edit-language-' . $langcode));
$this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), 'Default language successfully updated.');
$this->backdropLogout();
}