Skip to content

Commit 87ff677

Browse files
committed
Tests: Cover password reset URL formatting in emails.
Verify that `retrieve_password()` and `wp_new_user_notification()` include password reset links without surrounding angle brackets. Developed in: #14078 Props irozum, huzaifaalmesbah. See #65819, #44589. git-svn-id: https://develop.svn.wordpress.org/trunk@65092 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f567b52 commit 87ff677

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

‎tests/phpunit/tests/user.php‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,42 @@ static function ( $email ) use ( &$user_email_locale ) {
20122012
$this->assertSame( 'es_ES', $user_email_locale, 'User email was not sent in the expected locale' );
20132013
}
20142014

2015+
/**
2016+
* The reset link in the new user notification email should not be wrapped
2017+
* in angle brackets, as that caused some email clients to include the
2018+
* closing bracket as part of the URL and break the link.
2019+
*
2020+
* @ticket 44589
2021+
*/
2022+
public function test_wp_new_user_notification_does_not_wrap_reset_link_in_angle_brackets() {
2023+
$message = '';
2024+
2025+
add_filter(
2026+
'wp_new_user_notification_email',
2027+
static function ( $email ) use ( &$message ) {
2028+
$message = $email['message'];
2029+
return $email;
2030+
}
2031+
);
2032+
2033+
wp_new_user_notification( self::$contrib_id, null, 'user' );
2034+
2035+
$this->assertNotEmpty( $message, 'The notification email message should not be empty.' );
2036+
2037+
$reset_link_line = '';
2038+
2039+
foreach ( explode( "\r\n", $message ) as $line ) {
2040+
if ( str_contains( $line, 'wp-login.php' ) ) {
2041+
$reset_link_line = $line;
2042+
break;
2043+
}
2044+
}
2045+
2046+
$this->assertNotEmpty( $reset_link_line, 'The reset password link should be present in the email message.' );
2047+
$this->assertFalse( str_starts_with( $reset_link_line, '<' ), 'The reset password link should not start with an angle bracket.' );
2048+
$this->assertFalse( str_ends_with( $reset_link_line, '>' ), 'The reset password link should not end with an angle bracket.' );
2049+
}
2050+
20152051
/**
20162052
* Callback that returns 0.0.
20172053
*

‎tests/phpunit/tests/user/retrievePassword.php‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,40 @@ public function test_retrieve_password_does_not_throw_fatal_error_with_array_par
106106
$error_codes = $error->get_error_codes();
107107
$this->assertContains( 'empty_username', $error_codes, 'The "empty_username" error code should be present.' );
108108
}
109+
110+
/**
111+
* The password reset link in the notification email should not be wrapped
112+
* in angle brackets, as that caused some email clients to include the
113+
* closing bracket as part of the URL and break the link.
114+
*
115+
* @ticket 44589
116+
*/
117+
public function test_retrieve_password_email_does_not_wrap_reset_link_in_angle_brackets() {
118+
$message = '';
119+
120+
add_filter(
121+
'retrieve_password_notification_email',
122+
static function ( $defaults ) use ( &$message ) {
123+
$message = $defaults['message'];
124+
return $defaults;
125+
}
126+
);
127+
128+
retrieve_password( $this->user->user_login );
129+
130+
$this->assertNotEmpty( $message, 'The notification email message should not be empty.' );
131+
132+
$reset_link_line = '';
133+
134+
foreach ( explode( "\r\n", $message ) as $line ) {
135+
if ( str_contains( $line, 'wp-login.php' ) ) {
136+
$reset_link_line = $line;
137+
break;
138+
}
139+
}
140+
141+
$this->assertNotEmpty( $reset_link_line, 'The reset password link should be present in the email message.' );
142+
$this->assertFalse( str_starts_with( $reset_link_line, '<' ), 'The reset password link should not start with an angle bracket.' );
143+
$this->assertFalse( str_ends_with( $reset_link_line, '>' ), 'The reset password link should not end with an angle bracket.' );
144+
}
109145
}

0 commit comments

Comments
 (0)