Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correction de URL dans le email de réinitialisation de mot de passe #1599

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function resetPassword(User $user)
$this->userRepository->save($user);

$login = $user->getUsername();
$url = $this->urlGenerator->generate('admin_login');
$url = $this->urlGenerator->generate('admin_login', [], UrlGeneratorInterface::ABSOLUTE_URL);
$message = new Message(
'AFUP : Mot de passe perdu ?',
new MailUser($this->sender),
Expand Down
80 changes: 80 additions & 0 deletions tests/behat/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,84 @@ public function printLastResponseHeaders()

echo implode("\n", $headers);
}

/**
* @When I request a password reset for :arg1
*/
public function iRequestAPasswordReset(string $arg1): void
{
$this->minkContext->iAmOnHomepage();
$this->minkContext->assertPageContainsText("Tous les trois mois, des nouvelles de L'AFUP");
$this->minkContext->clickLink("Se connecter");
$this->minkContext->assertPageContainsText("Email ou nom d'utilisateur");
$this->minkContext->clickLink("Mot de passe perdu");
$this->minkContext->assertPageContainsText("Mot de passe perdu");
$this->minkContext->fillField("form_email", $arg1);
$this->minkContext->pressButton("Demander un nouveau mot de passe");
$this->minkContext->assertPageContainsText("Votre demande a été prise en compte. Si un compte correspond à cet email vous recevez un nouveau mot de passe rapidement.");
}

/**
* @Then I should receive an email
*/
public function iShouldReceiveAnEmail(): void
{
$content = file_get_contents(self::MAILCATCHER_URL.'/messages');
$decodedContent = json_decode($content, true);

$foundEmails = [];
foreach ($decodedContent as $mail) {
$foundEmails[] = [
'to' => $mail['to'],
'subject' => $mail['subject'],
];
}

if (count($foundEmails) !== 1) {
throw new ExpectationException(
sprintf(
'The email has not been received "%s" (expected "%s")',
var_export($foundEmails, true),
)
);
}
}

/**
* @Then the email should contain a full URL starting with :arg1
*/
public function theEmailShouldContainAFullUrlStartingWith(string $arg1): void
{
$content = file_get_contents(self::MAILCATCHER_URL.'/messages');
$decodedContent = json_decode($content, true);

$foundEmails = [];
foreach ($decodedContent as $mail) {
$foundEmails[] = [
'id' => $mail['id'],
'to' => $mail['to'],
'subject' => $mail['subject'],
];
}

if (count($foundEmails) !== 1) {
throw new ExpectationException(
sprintf(
'The email has not been received "%s" (expected "%s")',
var_export($foundEmails, true),
)
);
}

$content = file_get_contents(self::MAILCATCHER_URL.'/messages/'.$foundEmails[0]['id'].'.plain');
if (false === strpos($content, $arg1)) {
throw new ExpectationException(
sprintf(
'The email content does not contain the expected URL "%s" (expected "%s")',
$content,
$arg1
)
);
}
}
}
8 changes: 8 additions & 0 deletions tests/behat/features/Admin/PasswordReset.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: Password Reset

@reloadDbWithTestData
@clearEmails
Scenario: L'utilisateur reçoit une URL de connexion complète dans l'e-mail de réinitialisation du mot de passe.
When I request a password reset for "[email protected]"
Then I should receive an email
And the email should contain a full URL starting with "https://apachephptest:80/admin/login"