From 80a680c5ca9571125bbee99cbcf6051b67d77486 Mon Sep 17 00:00:00 2001 From: nod_ Date: Sat, 7 Sep 2024 01:00:08 +0200 Subject: [PATCH] Revert "Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login link instead of user login form in BrowserTestBase tests" This reverts commit b16714a91971401137bd1f9564648951fd896fb4. --- .../LocaleTranslatedSchemaDefinitionTest.php | 5 ---- .../tests/src/Functional/UserLoginTest.php | 8 +----- .../src/Functional/UserTokenReplaceTest.php | 5 ---- core/modules/user/user.module | 2 +- core/tests/Drupal/Tests/UiHelperTrait.php | 25 ++++--------------- 5 files changed, 7 insertions(+), 38 deletions(-) diff --git a/core/modules/locale/tests/src/Functional/LocaleTranslatedSchemaDefinitionTest.php b/core/modules/locale/tests/src/Functional/LocaleTranslatedSchemaDefinitionTest.php index 97fbfc7c503..8e0b38e2eac 100644 --- a/core/modules/locale/tests/src/Functional/LocaleTranslatedSchemaDefinitionTest.php +++ b/core/modules/locale/tests/src/Functional/LocaleTranslatedSchemaDefinitionTest.php @@ -28,11 +28,6 @@ class LocaleTranslatedSchemaDefinitionTest extends BrowserTestBase { */ protected $defaultTheme = 'stark'; - /** - * {@inheritdoc} - */ - protected bool $useOneTimeLoginLinks = FALSE; - /** * {@inheritdoc} */ diff --git a/core/modules/user/tests/src/Functional/UserLoginTest.php b/core/modules/user/tests/src/Functional/UserLoginTest.php index 5006d1b292b..4302113c42a 100644 --- a/core/modules/user/tests/src/Functional/UserLoginTest.php +++ b/core/modules/user/tests/src/Functional/UserLoginTest.php @@ -169,13 +169,7 @@ class UserLoginTest extends BrowserTestBase { $this->assertTrue($password_hasher->needsRehash($account->getPassword())); $account->passRaw = $password; - $this->drupalGet('user/login'); - $edit = [ - 'name' => $account->getAccountName(), - 'pass' => $account->passRaw, - ]; - $this->submitForm($edit, 'Log in'); - + $this->drupalLogin($account); // Load the stored user, which should have a different password hash now. $user_storage->resetCache([$account->id()]); $account = $user_storage->load($account->id()); diff --git a/core/modules/user/tests/src/Functional/UserTokenReplaceTest.php b/core/modules/user/tests/src/Functional/UserTokenReplaceTest.php index 2c6fcfb04b6..89b90d98ca0 100644 --- a/core/modules/user/tests/src/Functional/UserTokenReplaceTest.php +++ b/core/modules/user/tests/src/Functional/UserTokenReplaceTest.php @@ -27,11 +27,6 @@ class UserTokenReplaceTest extends BrowserTestBase { */ protected $defaultTheme = 'stark'; - /** - * {@inheritdoc} - */ - protected bool $useOneTimeLoginLinks = FALSE; - /** * {@inheritdoc} */ diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 9fafc8f63eb..76209b00ecc 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -521,7 +521,7 @@ function user_user_logout(AccountInterface $account) { * they can change their password. */ function user_pass_reset_url($account, $options = []) { - $timestamp = \Drupal::time()->getCurrentTime(); + $timestamp = \Drupal::time()->getRequestTime(); $langcode = $options['langcode'] ?? $account->getPreferredLangcode(); return Url::fromRoute('user.reset', [ diff --git a/core/tests/Drupal/Tests/UiHelperTrait.php b/core/tests/Drupal/Tests/UiHelperTrait.php index 87ab946dfba..fb96e5034fc 100644 --- a/core/tests/Drupal/Tests/UiHelperTrait.php +++ b/core/tests/Drupal/Tests/UiHelperTrait.php @@ -28,11 +28,6 @@ trait UiHelperTrait { */ protected $loggedInUser = FALSE; - /** - * Use one-time login links instead of submitting the login form. - */ - protected bool $useOneTimeLoginLinks = TRUE; - /** * The number of meta refresh redirects to follow, or NULL if unlimited. * @@ -161,21 +156,11 @@ trait UiHelperTrait { $this->drupalLogout(); } - if ($this->useOneTimeLoginLinks) { - // Reload to get latest login timestamp. - $storage = \Drupal::entityTypeManager()->getStorage('user'); - /** @var \Drupal\user\UserInterface $accountUnchanged */ - $accountUnchanged = $storage->loadUnchanged($account->id()); - $login = user_pass_reset_url($accountUnchanged) . '/login?destination=user/' . $account->id(); - $this->drupalGet($login); - } - else { - $this->drupalGet(Url::fromRoute('user.login')); - $this->submitForm([ - 'name' => $account->getAccountName(), - 'pass' => $account->passRaw, - ], 'Log in'); - } + $this->drupalGet(Url::fromRoute('user.login')); + $this->submitForm([ + 'name' => $account->getAccountName(), + 'pass' => $account->passRaw, + ], 'Log in'); // @see ::drupalUserIsLoggedIn() $account->sessionId = $this->getSession()->getCookie(\Drupal::service('session_configuration')->getOptions(\Drupal::request())['name']);