diff -u b/core/modules/user/src/AccountForm.php b/core/modules/user/src/AccountForm.php --- b/core/modules/user/src/AccountForm.php +++ b/core/modules/user/src/AccountForm.php @@ -16,6 +16,7 @@ use Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser; use Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Database\Database; /** * Form controller for the user account forms. @@ -448,6 +449,8 @@ $account = $this->entity; $name = $form_state->getValue('name'); $mail = $form_state->getValue('mail'); + // Get a list of files in the database for this directory. + $database = Database::getConnection(); // For new registrations, make sure the username does not conflict with // an existing user's email address. @@ -457,8 +460,8 @@ // For existing users whose username matches another user's email address // are not forced to update their username. if ($account->isAuthenticated()) { - $name_taken = (bool) db_select('users_field_data', 'ufd') - ->condition('ufd.name', db_like($name), 'LIKE') + $name_taken = (bool) $database->select('users_field_data', 'ufd') + ->condition('ufd.name', '%' . $database->escapeLike($search_phrase) . '%', 'LIKE') ->condition('ufd.uid', $account->id(), '<>') ->range(0, 1) ->countQuery() @@ -466,11 +469,11 @@ ->fetchField(); } else { - $name_taken = (bool) db_select('users_field_data', 'ufd') + $name_taken = (bool) $database->select('users_field_data', 'ufd') ->condition( db_or() - ->condition('ufd.name', db_like($name), 'LIKE') - ->condition('ufd.mail', db_like($name), 'LIKE') + ->condition('ufd.name', '%' . $database->escapeLike($search_phrase) . '%', 'LIKE') + ->condition('ufd.mail', '%' . $database->escapeLike($search_phrase) . '%', 'LIKE') ) ->condition('ufd.status', 1) ->range(0, 1) @@ -492,8 +495,8 @@ // For existing users whose email matches another user's username are not // forced to update their email address. if ($account->isAuthenticated()) { - $mail_taken = (bool) db_select('users_field_data', 'ufd') - ->condition('ufd.mail', db_like($mail), 'LIKE') + $mail_taken = (bool) $database->select('users_field_data', 'ufd') + ->condition('ufd.mail', '%' . $database->escapeLike($search_phrase) . '%', 'LIKE') ->condition('ufd.uid', $account->id(), '<>') ->range(0, 1) ->countQuery() @@ -501,11 +504,11 @@ ->fetchField(); } else { - $mail_taken = (bool) db_select('users_field_data', 'ufd') + $mail_taken = (bool) $database->select('users_field_data', 'ufd') ->condition( db_or() - ->condition('ufd.mail', db_like($mail), 'LIKE') - ->condition('ufd.name', db_like($mail), 'LIKE') + ->condition('ufd.name', '%' . $database->escapeLike($search_phrase) . '%', 'LIKE') + ->condition('ufd.mail', '%' . $database->escapeLike($search_phrase) . '%', 'LIKE') ) ->condition('ufd.status', 1) ->range(0, 1) diff -u b/core/modules/user/src/Form/UserPasswordForm.php b/core/modules/user/src/Form/UserPasswordForm.php --- b/core/modules/user/src/Form/UserPasswordForm.php +++ b/core/modules/user/src/Form/UserPasswordForm.php @@ -16,6 +16,8 @@ use Drupal\Core\Site\Settings; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Url; +use Drupal\user\UserInterface; +use Drupal\Core\Messenger\MessengerInterface; /** * Provides a user password reset form. @@ -275,14 +277,14 @@ } if (isset($account)) { // Mail one-time login URL and instructions using current language. - $mail = _user_mail_notify('password_reset', $account, $language_interface->getId()); + $mail = _user_mail_notify('password_reset', $account); if (!empty($mail)) { $this->logger('user')->notice('Password reset instructions mailed to %name at %email.', [ ' %name' => $account->name, '%email' => $account->mail, ]); - \Drupal::messenger($this->t('Further instructions have been sent to your e-mail address.')); + \Drupal::messenger()->addMessage($this->t('Further instructions have been sent to your e-mail address.')); } $form_state->setRedirectUrl(Url::fromRoute('user.page')); diff -u b/core/modules/user/tests/src/Functional/UserEditTest.php b/core/modules/user/tests/src/Functional/UserEditTest.php --- b/core/modules/user/tests/src/Functional/UserEditTest.php +++ b/core/modules/user/tests/src/Functional/UserEditTest.php @@ -265,14 +265,14 @@ // Test that the first user can save their account with no errors. $this->drupalLogin($user_with_email); - $this->drupalPostForm("user/" . $user_with_email->id() . "/edit", [], t('Save')); - $this->assertText(t("The changes have been saved."), "The user does not need to change their username if it matches another user's email address."); + $this->submitForm("user/" . $user_with_email->id() . "/edit", [], t('Save')); + $this->assertSession()->responseContains(t("The changes have been saved."), "The user does not need to change their username if it matches another user's email address."); $this->drupalLogout(); // Test that the second user can save their account with no errors. $this->drupalLogin($user_with_name); - $this->drupalPostForm("user/" . $user_with_name->id() . "/edit", [], t('Save')); - $this->assertText(t("The changes have been saved."), "The user does not need to change their email address if it matches another user's username."); + $this->submitForm("user/" . $user_with_name->id() . "/edit", [], t('Save')); + $this->assertSession()->responseContains(t("The changes have been saved."), "The user does not need to change their email address if it matches another user's username."); } } diff -u b/core/modules/user/tests/src/Functional/UserPasswordResetTest.php b/core/modules/user/tests/src/Functional/UserPasswordResetTest.php --- b/core/modules/user/tests/src/Functional/UserPasswordResetTest.php +++ b/core/modules/user/tests/src/Functional/UserPasswordResetTest.php @@ -250,7 +250,7 @@ $user_settings->set('verify_mail', FALSE)->save(); // Don't require admin approval for new accounts. - $user_settings->set('register', USER_REGISTER_VISITORS)->save(); + $user_settings->set('register', REGISTER_VISITORS)->save(); // Create two users. $user_with_email = $this->drupalCreateUser(); $user_with_name = $this->drupalCreateUser(); @@ -263,26 +263,26 @@ // Try and reset based on the duplicated email. $edit = []; $edit['name'] = $user_with_email->getEmail(); - $this->drupalPostForm('user/password', $edit, t('Submit')); + $this->submitForm('user/password', $edit, t('Submit')); // There should be a field prompting the user to pick and account. - $this->assertField('choose_account', 'User is prompted to pick an account when email matches two accounts.'); + $this->assertSession()->fieldExists('choose_account', 'User is prompted to pick an account when email matches two accounts.'); // We should be sure to not expose another user's email to the user. - $this->assertNoText($user_with_name->getEmail(), "Duplicated user's email is not exposed to the other user."); + $this->assertSession()->pageTextNotContains($user_with_name->getEmail(), "Duplicated user's email is not exposed to the other user."); // Select the account with the username matching the entered email. $edit = []; $edit['choose_account'] = Crypt::hashBase64(Settings::getHashSalt() . $user_with_email->id()); - $this->drupalPostForm(NULL, $edit, t('Submit')); - $this->assertText(t('Further instructions have been sent to your e-mail address.'), 'User is notified that password reset was sent.'); + $this->submitForm(NULL, $edit, t('Submit')); + $this->assertSession()->pageTextContains(t('Further instructions have been sent to your e-mail address.'), 'User is notified that password reset was sent.'); // Make sure that right user was sent a reset email. - $this->assertEqual(count($this->drupalGetMails([ + $this->assertEquals(count($this->drupalGetMails([ 'key' => 'password_reset', 'to' => $user_with_email->getEmail(), ] )), 1, 'The right user was sent a password reset mail.'); // Make sure that the other user was not sent an email. - $this->assertEqual(count($this->drupalGetMails([ + $this->assertEquals(count($this->drupalGetMails([ 'key' => 'password_reset', 'to' => $user_with_name->getEmail(), ])), 0, 'The other user was not sent a password reset mail.'); @@ -292,11 +292,11 @@ $this->drupalLogin($user_with_name); $this->drupalGet('user/password'); // There should not be a form element for name. - $this->assertNoField('name', 'Duplicate user is not asked for a name when resetting password while logged in.'); - $this->drupalPostForm(NULL, [], t('Submit')); + $this->assertSession()->fieldNotExists('name', 'Duplicate user is not asked for a name when resetting password while logged in.'); + $this->submitForm(NULL, [], t('Submit')); // Make sure the user with the matching username was sent an email. - $this->assertText(t('Further instructions have been sent to your e-mail address.'), 'User is notified that password reset was sent when logged in.'); - $this->assertEqual(count($this->drupalGetMails( + $this->assertSession()->pageTextContains(t('Further instructions have been sent to your e-mail address.'), 'User is notified that password reset was sent when logged in.'); + $this->assertEquals(count($this->drupalGetMails( [ 'key' => 'password_reset', 'to' => $user_with_name->getEmail(), @@ -304,7 +304,7 @@ // Make sure that the user with the matching // email address was not sent an email. // (An email was already sent to this user earlier.) - $this->assertEqual(count($this->drupalGetMails( + $this->assertEquals(count($this->drupalGetMails( [ 'key' => 'password_reset', 'to' => $user_with_email->getEmail(), diff -u b/core/modules/user/tests/src/Functional/UserRegistrationTest.php b/core/modules/user/tests/src/Functional/UserRegistrationTest.php --- b/core/modules/user/tests/src/Functional/UserRegistrationTest.php +++ b/core/modules/user/tests/src/Functional/UserRegistrationTest.php @@ -29,7 +29,9 @@ protected $defaultTheme = 'stark'; /** + * Tests registration of user with email verification. * + * @group user */ public function testRegistrationWithEmailVerification() { $config = $this->config('user.settings'); @@ -74,7 +76,9 @@ } /** + * Tests registration of user without email verification. * + * @group user */ public function testRegistrationWithoutEmailVerification() { $config = $this->config('user.settings'); @@ -149,7 +153,9 @@ } /** + * Tests registration of user with email duplicates. * + * @group user */ public function testRegistrationEmailDuplicates() { // Don't require email verification and allow registration by site visitors @@ -250,7 +256,9 @@ } /** + * Tests registration of user with default values. * + * @group user */ public function testRegistrationDefaultValues() { // Don't require email verification and allow registration by site visitors @@ -432,7 +440,7 @@ $user_settings->set('verify_mail', FALSE)->save(); // Don't require admin approval for new accounts. - $user_settings->set('register', USER_REGISTER_VISITORS)->save(); + $user_settings->set('register', REGISTER_VISITORS)->save(); // Set up a user to check for duplicates. $duplicate_user = $this->drupalCreateUser(); @@ -445,8 +453,8 @@ // Attempt to create a new account using a username that matches an // existing email. - $this->drupalPostForm('user/register', $edit, t('Create new account')); - $this->assertText(t('The name @name is already taken.', ['@name' => $edit['name']]), "A user cannot be created when their username matches an existing user's email address."); + $this->submitForm('user/register', $edit, t('Create new account')); + $this->assertSession()->pageTextContains(t('The name @name is already taken.', ['@name' => $edit['name']]), "A user cannot be created when their username matches an existing user's email address."); // Change the username to an email address. $duplicate_user->name = $name = $this->randomMachineName() . '@example.com'; @@ -458,8 +466,8 @@ // Attempt to create a new account using an email that matches an existing // username. - $this->drupalPostForm('user/register', $edit, t('Create new account')); - $this->assertText(t('The email address @email is already registered.', ['@email' => $edit['mail']]), "A user cannot be created when their email address matches an existing username."); + $this->submitForm('user/register', $edit, t('Create new account')); + $this->assertSession()->pageTextContains(t('The email address @email is already registered.', ['@email' => $edit['mail']]), "A user cannot be created when their email address matches an existing username."); } } reverted: --- b/core/modules/user/user.module +++ a/core/modules/user/user.module @@ -29,8 +29,6 @@ use Drupal\user\Entity\User; use Drupal\user\RoleInterface; use Drupal\user\UserInterface; -use Drupal\Core\Language\LanguageInterface; -use Symfony\Component\HttpKernel\HttpKernelInterface; /** * Implements hook_help().