Users: Further fixes to entitiy decoding in the user email address change confirmation email, and the corresponding tests.

See #16470, #40015


git-svn-id: https://develop.svn.wordpress.org/trunk@41171 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2017-07-27 14:58:06 +00:00
parent b59d96d978
commit 1071986cb9
3 changed files with 51 additions and 43 deletions
+43
View File
@@ -1272,4 +1272,47 @@ class Tests_User extends WP_UnitTestCase {
// $_POST['email'] should be the email address posted from the form.
$this->assertEquals( $_POST['email'], 'after@example.com' );
}
/**
* Ensure user email address change confirmation emails do not contain encoded HTML entities
*
* @ticket 16470
* @ticket 40015
*/
function test_send_confirmation_on_profile_email_html_entities_decoded() {
$user_id = self::factory()->user->create( array(
'role' => 'subscriber',
'user_email' => 'old-email@test.dev',
) );
wp_set_current_user( $user_id );
reset_phpmailer_instance();
// Give the site and blog a name containing HTML entities
update_site_option( 'site_name', ''Test' site's "name" has <html entities> &' );
update_option( 'blogname', ''Test' blog's "name" has <html entities> &' );
// Set $_POST['email'] with new e-mail and $_POST['user_id'] with user's ID.
$_POST['user_id'] = $user_id;
$_POST['email'] = 'new-email@test.dev';
send_confirmation_on_profile_email( );
$mailer = tests_retrieve_phpmailer_instance();
$recipient = $mailer->get_recipient( 'to' );
$email = $mailer->get_sent();
// Assert recipient is correct
$this->assertSame( 'new-email@test.dev', $recipient->address, 'User email change confirmation recipient not as expected' );
// Assert that HTML entites have been decoded in body and subject
if ( is_multisite() ) {
$this->assertContains( '\'Test\' site\'s "name" has <html entities> &', $email->body, 'Email body does not contain the decoded HTML entities' );
$this->assertNotContains( '&#039;Test&#039; site&#039;s &quot;name&quot; has &lt;html entities&gt; &amp;', $email->body, 'Email body does contains HTML entities' );
}
$this->assertContains( '\'Test\' blog\'s "name" has <html entities> &', $email->subject, 'Email subject does not contain the decoded HTML entities' );
$this->assertNotContains( '&#039;Test&#039; blog&#039;s &quot;name&quot; has &lt;html entities&gt; &amp;', $email->subject, 'Email subject does contains HTML entities' );
}
}