Issue #2560237 by bhanu951, smustgrave, _utsavsharma, ankithashetty, alexpott, larowlan, catch, jhedstrom: UpdatePathTestBase saves the root user before updates have run

(cherry picked from commit 8b53ceb644)
merge-requests/9004/merge
Alex Pott 2024-10-08 10:03:53 +01:00
parent 7c3cdb72a1
commit a113593f22
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
1 changed files with 12 additions and 9 deletions

View File

@ -14,7 +14,6 @@ use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Language\Language;
use Drupal\Core\Url;
use Drupal\Tests\UpdatePathTestTrait;
use Drupal\user\Entity\User;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\Request;
@ -236,14 +235,18 @@ abstract class UpdatePathTestBase extends BrowserTestBase {
* Replace User 1 with the user created here.
*/
protected function replaceUser1() {
/** @var \Drupal\user\UserInterface $account */
// @todo Saving the account before the update is problematic.
// https://www.drupal.org/node/2560237
$account = User::load(1);
$account->setPassword($this->rootUser->pass_raw);
$account->setEmail($this->rootUser->getEmail());
$account->setUsername($this->rootUser->getAccountName());
$account->save();
// We try not to save content entities in hook_update_N() because the schema
// might be out of sync, or hook invocations might rely on other schemas
// that also aren't updated yet. Hence we are directly updating the database
// tables with the values.
Database::getConnection()->update('users_field_data')
->fields([
'name' => $this->rootUser->getAccountName(),
'pass' => \Drupal::service('password')->hash($this->rootUser->pass_raw),
'mail' => $this->rootUser->getEmail(),
])
->condition('uid', 1)
->execute();
}
/**