LoginLink create get Request Locale#40641
LoginLink create get Request Locale#40641fabpot merged 1 commit intosymfony:5.xfrom roromix:loginlink-get-request-locale
Conversation
|
Thanks for the follow-up @roromix. |
There was a problem hiding this comment.
Thank you.
You are the best. Writing docs and patching bugs.
I agree with this PR and I do like the changes in LoginLinkHandler. But you need to update the test. I will pass even without any modifications to LoginLinkHandler.
|
If I copy the tests you written (without the changes in |
Sorry, i have no idea how to do that. Need help |
|
Here is a patch covering this change: diff --git a/src/Symfony/Component/Security/Http/Tests/LoginLink/LoginLinkHandlerTest.php b/src/Symfony/Component/Security/Http/Tests/LoginLink/LoginLinkHandlerTest.php
index 03dd0287d7..12b8f7da4a 100644
--- a/src/Symfony/Component/Security/Http/Tests/LoginLink/LoginLinkHandlerTest.php
+++ b/src/Symfony/Component/Security/Http/Tests/LoginLink/LoginLinkHandlerTest.php
@@ -69,7 +69,12 @@ class LoginLinkHandlerTest extends TestCase
if ($request) {
$this->router->expects($this->once())
->method('getContext')
- ->willReturn(new RequestContext());
+ ->willReturn($currentRequestContext = new RequestContext());
+
+ $this->router
+ ->expects($this->exactly(2))
+ ->method('setContext')
+ ->withConsecutive([$this->equalTo((new RequestContext())->fromRequest($request)->setParameter('_locale', $request->getLocale()))], [$currentRequestContext]);
}
$loginLink = $this->createLinker([], array_keys($extraProperties))->createLoginLink($user, $request);
@@ -78,19 +83,15 @@ class LoginLinkHandlerTest extends TestCase
public function provideCreateLoginLinkData()
{
- $request = Request::create('https://example.com');
- $request->setLocale('en');
-
yield [
new TestLoginLinkHandlerUser('weaverryan', 'ryan@symfonycasts.com', 'pwhash'),
['emailProperty' => 'ryan@symfonycasts.com', 'passwordProperty' => 'pwhash'],
- $request,
+ Request::create('https://example.com'),
];
yield [
new TestLoginLinkHandlerUser('weaverryan', 'ryan@symfonycasts.com', 'pwhash'),
['emailProperty' => 'ryan@symfonycasts.com', 'passwordProperty' => 'pwhash'],
- Request::create('https://example.com'),
];
yield [ |
|
I still have a lot to learn about the Tests |
|
Thank you @roromix. |
This PR was squashed before being merged into the 5.3-dev branch. Discussion ---------- [Security] Customize generated Login Link Fix #15147 and add documentation for symfony/symfony#40641 Commits ------- 830b1f3 [Security] Customize generated Login Link
While writing the documentation for PR#40153 I noticed that the RequestContext :: fromRequest method does not add the '_locale' parameter automaticaly. This new pull request to set _locale parameter to the RequestContext.