1.20.x user.test | UserEditedOwnAccountTestCase::testUserEditedOwnAccount() |
Tests a user editing their own account.
File
- modules/
user/ tests/ user.test, line 2093 - Tests for user.module.
Class
Code
function testUserEditedOwnAccount() {
// Change account setting 'Who can register accounts?' to Administrators
// only.
config_set('system.core', 'user_register', USER_REGISTER_ADMINISTRATORS_ONLY);
// Create a new user account and log in.
$account = $this->backdropCreateUser(array('change own username'));
$this->backdropLogin($account);
// Change own username.
$edit = array();
$edit['name'] = $this->randomName();
$this->backdropPost('user/' . $account->uid . '/edit', $edit, t('Save'));
// Log out.
$this->backdropLogout();
// Set the new name on the user account and attempt to log back in.
$account->name = $edit['name'];
$this->backdropLogin($account);
// Attempt to change username to an email other than my own.
$edit['name'] = $this->randomName() . '@example.com';
$this->backdropPost('user/' . $account->uid . '/edit', $edit, t('Save'));
$this->assertText(t('An email address was provided as a username, but does not match the account email address.', array('%name' => $edit['name'])), 'Error message found when an email username does not match user email.');
$this->assertNoText(t('The changes have been saved.'), 'The user account was not saved.');
// Lookup user by name to make sure we didn't actually change the name.
$changed = user_load_by_name($edit['name']);
$this->assertFalse($changed, 'Username was not changed to email address other than my own.');
// Change username to my email address.
$edit['name'] = $account->mail;
$this->backdropPost('user/' . $account->uid . '/edit', $edit, t('Save'));
$this->assertText(t('The changes have been saved.'), 'The user account was saved.');
// Test that 'verify_email_match' turned off allows emails that don't match.
config_set('system.core', 'user_email_match', FALSE);
// Change username to random, non-matching email address.
$edit['name'] = $this->randomName() . '@example.com';
$this->backdropPost('user/' . $account->uid . '/edit', $edit, t('Save'));
$this->assertText(t('The changes have been saved.'), 'The user account was saved.');
}