From b61cd96e9dcc2c40538df3e636971eeee2eb3e17 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Wed, 5 Oct 2022 13:04:31 +0100
Subject: [PATCH] Issue #3168624 by DerekCresswell, ravi.shankar, BramDriesen,
 jonathanshaw, catch: Add 'user/edit' route

---
 .../user/src/Controller/UserController.php    |  3 +-
 .../Kernel/Controller/UserControllerTest.php  | 76 +++++++++++++++++++
 core/modules/user/user.routing.yml            |  8 ++
 3 files changed, 85 insertions(+), 2 deletions(-)
 create mode 100644 core/modules/user/tests/src/Kernel/Controller/UserControllerTest.php

diff --git a/core/modules/user/src/Controller/UserController.php b/core/modules/user/src/Controller/UserController.php
index ca40039816d0..625969e295a0 100644
--- a/core/modules/user/src/Controller/UserController.php
+++ b/core/modules/user/src/Controller/UserController.php
@@ -283,8 +283,7 @@ public function userPage() {
    * Redirects users to their profile edit page.
    *
    * This controller assumes that it is only invoked for authenticated users.
-   * This is enforced for the 'user.well-known.change_password' route with the
-   * '_user_is_logged_in' requirement.
+   * This is typically enforced with the '_user_is_logged_in' requirement.
    *
    * @return \Symfony\Component\HttpFoundation\RedirectResponse
    *   Returns a redirect to the profile edit form of the currently logged in
diff --git a/core/modules/user/tests/src/Kernel/Controller/UserControllerTest.php b/core/modules/user/tests/src/Kernel/Controller/UserControllerTest.php
new file mode 100644
index 000000000000..942a9f5b9a8c
--- /dev/null
+++ b/core/modules/user/tests/src/Kernel/Controller/UserControllerTest.php
@@ -0,0 +1,76 @@
+<?php
+
+namespace Drupal\Tests\user\Kernel\Controller;
+
+use Drupal\Core\Url;
+use Drupal\KernelTests\KernelTestBase;
+use Drupal\Tests\user\Traits\UserCreationTrait;
+use Drupal\user\Controller\UserController;
+
+/**
+ * Tests for the User controller.
+ *
+ * @group user
+ *
+ * @coversDefaultClass \Drupal\user\Controller\UserController
+ */
+class UserControllerTest extends KernelTestBase {
+
+  use UserCreationTrait;
+
+  /**
+   * The user controller.
+   *
+   * @var \Drupal\user\Controller\UserController
+   */
+  protected $userController;
+
+  /**
+   * The logged in user.
+   *
+   * @var \Drupal\user\UserInterface
+   */
+  protected $user;
+
+  /**
+   * {@inheritdoc}
+   */
+  protected static $modules = [
+    'user',
+  ];
+
+  /**
+   * {@inheritDoc}
+   */
+  protected function setUp(): void {
+
+    parent::setUp();
+
+    $this->userController = UserController::create(\Drupal::getContainer());
+
+    // Create and log in a user.
+    $this->user = $this->setUpCurrentUser();
+
+  }
+
+  /**
+   * Tests the redirection to a user edit page.
+   *
+   * @covers ::userEditPage
+   */
+  public function testUserEditPage() {
+
+    $response = $this->userController->userEditPage();
+
+    // Ensure the response is directed to the correct user edit page.
+    $edit_url = Url::fromRoute('entity.user.edit_form', [
+      'user' => $this->user->id(),
+    ])->setAbsolute()
+      ->toString();
+    $this->assertEquals($edit_url, $response->getTargetUrl());
+
+    $this->assertEquals(301, $response->getStatusCode());
+
+  }
+
+}
diff --git a/core/modules/user/user.routing.yml b/core/modules/user/user.routing.yml
index 04a094abcfe5..d47991784571 100644
--- a/core/modules/user/user.routing.yml
+++ b/core/modules/user/user.routing.yml
@@ -146,6 +146,14 @@ user.page:
   requirements:
     _user_is_logged_in: 'TRUE'
 
+user.edit:
+  path: '/user/edit'
+  defaults:
+    _controller: '\Drupal\user\Controller\UserController::userEditPage'
+    _title: 'Edit account'
+  requirements:
+    _user_is_logged_in: 'TRUE'
+
 user.login:
   path: '/user/login'
   defaults:
-- 
GitLab