Commit 4beaeab9 authored by catch's avatar catch
Browse files

Issue #1552236 by duellj: Move user language tests to user module.

parent 9be8c892
......@@ -1890,175 +1890,6 @@ class LocaleBrowserDetectionTest extends DrupalUnitTestCase {
}
}
/**
* Functional tests for a user's ability to change their default language.
*/
class LocaleUserLanguageFunctionalTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'User language settings',
'description' => "Tests user's ability to change their default language.",
'group' => 'Locale',
);
}
function setUp() {
parent::setUp('locale');
}
/**
* Test if user can change their default language.
*/
function testUserLanguageConfiguration() {
global $base_url;
// User to add and remove language.
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
// User to change their default language.
$web_user = $this->drupalCreateUser();
// Add custom language.
$this->drupalLogin($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,
'direction' => '0',
);
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
$this->drupalLogout();
// Login as normal user and edit account settings.
$this->drupalLogin($web_user);
$path = 'user/' . $web_user->uid . '/edit';
$this->drupalGet($path);
// Ensure language settings fieldset is available.
$this->assertText(t('Language'), t('Language selector available.'));
// Ensure custom language is present.
$this->assertText($name, t('Language present on form.'));
// Switch to our custom language.
$edit = array(
'preferred_langcode' => $langcode,
);
$this->drupalPost($path, $edit, t('Save'));
// Ensure form was submitted successfully.
$this->assertText(t('The changes have been saved.'), t('Changes were saved.'));
// Check if language was changed.
$elements = $this->xpath('//input[@id=:id]', array(':id' => 'edit-preferred-langcode-' . $langcode));
$this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), t('Default language successfully updated.'));
$this->drupalLogout();
}
}
/**
* Functional test for language handling during user creation.
*/
class LocaleUserCreationTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'User creation',
'description' => 'Tests whether proper language is stored for new users and access to language selector.',
'group' => 'Locale',
);
}
function setUp() {
parent::setUp('locale');
variable_set('user_register', USER_REGISTER_VISITORS);
}
/**
* Functional test for language handling during user creation.
*/
function testLocalUserCreation() {
// User to add and remove language and create new users.
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer users'));
$this->drupalLogin($admin_user);
// Add predefined language.
$langcode = 'fr';
$edit = array(
'predefined_langcode' => 'fr',
);
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
$this->assertText('French', t('Language added successfully.'));
$this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.'));
// Set language negotiation.
$edit = array(
'language_interface[enabled][language-url]' => TRUE,
);
$this->drupalPost('admin/config/regional/language/detection', $edit, t('Save settings'));
$this->assertText(t('Language negotiation configuration saved.'), t('Set language negotiation.'));
// Check if the language selector is available on admin/people/create and
// set to the currently active language.
$this->drupalGet($langcode . '/admin/people/create');
$this->assertFieldChecked("edit-preferred-langcode-$langcode", t('Global language set in the language selector.'));
// Create a user with the admin/people/create form and check if the correct
// language is set.
$username = $this->randomName(10);
$edit = array(
'name' => $username,
'mail' => $this->randomName(4) . '@example.com',
'pass[pass1]' => $username,
'pass[pass2]' => $username,
);
$this->drupalPost($langcode . '/admin/people/create', $edit, t('Create new account'));
$user = user_load_by_name($username);
$this->assertEqual($user->preferred_langcode, $langcode, t('New user has correct preferred language set.'));
$this->assertEqual($user->langcode, $langcode, t('New user has correct profile language set.'));
// Register a new user and check if the language selector is hidden.
$this->drupalLogout();
$this->drupalGet($langcode . '/user/register');
$this->assertNoFieldByName('language[fr]', t('Language selector is not accessible.'));
$username = $this->randomName(10);
$edit = array(
'name' => $username,
'mail' => $this->randomName(4) . '@example.com',
);
$this->drupalPost($langcode . '/user/register', $edit, t('Create new account'));
$user = user_load_by_name($username);
$this->assertEqual($user->preferred_langcode, $langcode, t('New user has correct preferred language set.'));
$this->assertEqual($user->langcode, $langcode, t('New user has correct profile language set.'));
// Test if the admin can use the language selector and if the
// correct language is was saved.
$user_edit = $langcode . '/user/' . $user->uid . '/edit';
$this->drupalLogin($admin_user);
$this->drupalGet($user_edit);
$this->assertFieldChecked("edit-preferred-langcode-$langcode", t('Language selector is accessible and correct language is selected.'));
// Set pass_raw so we can login the new user.
$user->pass_raw = $this->randomName(10);
$edit = array(
'pass[pass1]' => $user->pass_raw,
'pass[pass2]' => $user->pass_raw,
);
$this->drupalPost($user_edit, $edit, t('Save'));
$this->drupalLogin($user);
$this->drupalGet($user_edit);
$this->assertFieldChecked("edit-preferred-langcode-$langcode", t('Language selector is accessible and correct language is selected.'));
}
}
/**
* Functional tests for configuring a different path alias per language.
*/
......
......@@ -2416,3 +2416,172 @@ class UserEntityCallbacksTestCase extends DrupalWebTestCase {
$this->assertEqual('user/' . $this->account->uid, $uri['path'], t('Correct user URI.'));
}
}
/**
* Functional tests for a user's ability to change their default language.
*/
class UserLanguageFunctionalTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'User language settings',
'description' => "Tests user's ability to change their default language.",
'group' => 'User',
);
}
function setUp() {
parent::setUp(array('user', 'language'));
}
/**
* Test if user can change their default language.
*/
function testUserLanguageConfiguration() {
global $base_url;
// User to add and remove language.
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
// User to change their default language.
$web_user = $this->drupalCreateUser();
// Add custom language.
$this->drupalLogin($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,
'direction' => '0',
);
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
$this->drupalLogout();
// Login as normal user and edit account settings.
$this->drupalLogin($web_user);
$path = 'user/' . $web_user->uid . '/edit';
$this->drupalGet($path);
// Ensure language settings fieldset is available.
$this->assertText(t('Language'), t('Language selector available.'));
// Ensure custom language is present.
$this->assertText($name, t('Language present on form.'));
// Switch to our custom language.
$edit = array(
'preferred_langcode' => $langcode,
);
$this->drupalPost($path, $edit, t('Save'));
// Ensure form was submitted successfully.
$this->assertText(t('The changes have been saved.'), t('Changes were saved.'));
// Check if language was changed.
$elements = $this->xpath('//input[@id=:id]', array(':id' => 'edit-preferred-langcode-' . $langcode));
$this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), t('Default language successfully updated.'));
$this->drupalLogout();
}
}
/**
* Functional test for language handling during user creation.
*/
class UserLanguageCreationTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'User language creation',
'description' => 'Tests whether proper language is stored for new users and access to language selector.',
'group' => 'User',
);
}
function setUp() {
parent::setUp(array('user', 'language'));
variable_set('user_register', USER_REGISTER_VISITORS);
}
/**
* Functional test for language handling during user creation.
*/
function testLocalUserCreation() {
// User to add and remove language and create new users.
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer users'));
$this->drupalLogin($admin_user);
// Add predefined language.
$langcode = 'fr';
$edit = array(
'predefined_langcode' => 'fr',
);
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
$this->assertText('French', t('Language added successfully.'));
$this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), t('Correct page redirection.'));
// Set language negotiation.
$edit = array(
'language_interface[enabled][language-url]' => TRUE,
);
$this->drupalPost('admin/config/regional/language/detection', $edit, t('Save settings'));
$this->assertText(t('Language negotiation configuration saved.'), t('Set language negotiation.'));
// Check if the language selector is available on admin/people/create and
// set to the currently active language.
$this->drupalGet($langcode . '/admin/people/create');
$this->assertFieldChecked("edit-preferred-langcode-$langcode", t('Global language set in the language selector.'));
// Create a user with the admin/people/create form and check if the correct
// language is set.
$username = $this->randomName(10);
$edit = array(
'name' => $username,
'mail' => $this->randomName(4) . '@example.com',
'pass[pass1]' => $username,
'pass[pass2]' => $username,
);
$this->drupalPost($langcode . '/admin/people/create', $edit, t('Create new account'));
$user = user_load_by_name($username);
$this->assertEqual($user->preferred_langcode, $langcode, t('New user has correct preferred language set.'));
$this->assertEqual($user->langcode, $langcode, t('New user has correct profile language set.'));
// Register a new user and check if the language selector is hidden.
$this->drupalLogout();
$this->drupalGet($langcode . '/user/register');
$this->assertNoFieldByName('language[fr]', t('Language selector is not accessible.'));
$username = $this->randomName(10);
$edit = array(
'name' => $username,
'mail' => $this->randomName(4) . '@example.com',
);
$this->drupalPost($langcode . '/user/register', $edit, t('Create new account'));
$user = user_load_by_name($username);
$this->assertEqual($user->preferred_langcode, $langcode, t('New user has correct preferred language set.'));
$this->assertEqual($user->langcode, $langcode, t('New user has correct profile language set.'));
// Test if the admin can use the language selector and if the
// correct language is was saved.
$user_edit = $langcode . '/user/' . $user->uid . '/edit';
$this->drupalLogin($admin_user);
$this->drupalGet($user_edit);
$this->assertFieldChecked("edit-preferred-langcode-$langcode", t('Language selector is accessible and correct language is selected.'));
// Set pass_raw so we can login the new user.
$user->pass_raw = $this->randomName(10);
$edit = array(
'pass[pass1]' => $user->pass_raw,
'pass[pass2]' => $user->pass_raw,
);
$this->drupalPost($user_edit, $edit, t('Save'));
$this->drupalLogin($user);
$this->drupalGet($user_edit);
$this->assertFieldChecked("edit-preferred-langcode-$langcode", t('Language selector is accessible and correct language is selected.'));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment