Skip to content
Snippets Groups Projects
Commit 7df98375 authored by Stefanos Petrakis's avatar Stefanos Petrakis Committed by Greg Knaddison
Browse files

Issue #3024558 by stefanos.petrakis, JeroenT, henk, pradosh15, mattjones86,...

Issue #3024558 by stefanos.petrakis, JeroenT, henk, pradosh15, mattjones86, greggles, klausi, andypost, joachim: Username regenerated improperly after rc6 release
parent d1e5ea75
Branches
Tags 8.x-1.0-rc7
No related merge requests found
......@@ -123,7 +123,11 @@ function email_registration_cleanup_username($name) {
*/
function email_registration_form_user_form_alter(&$form, FormStateInterface $form_state) {
$form['account']['name']['#type'] = 'value';
$form['account']['name']['#value'] = 'email_registration_' . user_password();
// Provide a random user name only if we are creating a new user, i.e. this
// is a registration.
if ($form_state->getFormObject()->getEntity()->isNew()) {
$form['account']['name']['#value'] = 'email_registration_' . user_password();
}
$form['account']['mail']['#title'] = t('Email');
}
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\email_registration\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\Entity\User;
/**
* Tests the email registration module.
......@@ -106,6 +107,16 @@ class EmailRegistrationTestCase extends BrowserTestBase {
$this->drupalPostForm('/user/register', $register, t('Create new account'));
$account = user_load_by_mail($register['mail']);
$this->assertTrue($next_unique_name === $account->getAccountName());
$this->drupalLogout();
// Check if custom username stays the same when user is edited.
$user = $this->createUser();
$name = $user->label();
$this->drupalLogin($user);
$this->drupalPostForm('/user/' . $user->id() . '/edit', [], 'Save');
$this->assertEqual($name, User::load($user->id())->label(), 'Username should not change after empty edit.');
$this->drupalLogout($user);
$this->drupalLogin($user);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment