Options, Meta APIs: Update the multisite unit tests after [41254], [41164], and [41163].
This moves some more previously Multisite-only tests into the main test suite, and makes small adjustments to their assertions. See #39118, #16470, #39117 git-svn-id: https://develop.svn.wordpress.org/trunk@41255 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
dad257233c
commit
9cd6551e54
@ -1138,6 +1138,140 @@ class Tests_User extends WP_UnitTestCase {
|
||||
$this->assertFalse( $was_user_email_sent );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure blog's admin email change notification emails do not contain encoded HTML entities
|
||||
* @ticket 40015
|
||||
*/
|
||||
function test_new_admin_email_notification_html_entities_decoded() {
|
||||
reset_phpmailer_instance();
|
||||
|
||||
wp_set_current_user( self::$admin_id );
|
||||
|
||||
$existing_email = get_option( 'admin_email' );
|
||||
$new_email = 'new-admin-email@test.dev';
|
||||
|
||||
// Give the site a name containing HTML entities
|
||||
update_option( 'blogname', ''Test' blog's "name" has <html entities> &' );
|
||||
|
||||
update_option_new_admin_email( $existing_email, $new_email );
|
||||
|
||||
$mailer = tests_retrieve_phpmailer_instance();
|
||||
|
||||
$recipient = $mailer->get_recipient( 'to' );
|
||||
$email = $mailer->get_sent();
|
||||
|
||||
// Assert reciepient is correct
|
||||
$this->assertSame( $new_email, $recipient->address, 'Admin email change notification recipient not as expected' );
|
||||
|
||||
// Assert that HTML entites have been decode in body and subject
|
||||
$this->assertContains( '\'Test\' blog\'s "name" has <html entities> &', $email->subject, 'Email subject does not contain the decoded HTML entities' );
|
||||
$this->assertNotContains( ''Test' blog's "name" has <html entities> &', $email->subject, $email->subject, 'Email subject does contains HTML entities' );
|
||||
}
|
||||
|
||||
/**
|
||||
* A confirmation email should not be sent if the new admin email:
|
||||
* - Matches the existing admin email, or
|
||||
* - is not a valid email
|
||||
*
|
||||
* @dataProvider data_user_admin_email_confirmation_emails
|
||||
*/
|
||||
function test_new_admin_email_confirmation_not_sent_when_email_invalid( $email, $message ) {
|
||||
reset_phpmailer_instance();
|
||||
|
||||
update_option_new_admin_email( get_option( 'admin_email' ), $email );
|
||||
|
||||
$mailer = tests_retrieve_phpmailer_instance();
|
||||
|
||||
$this->assertFalse( $mailer->get_sent(), $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_ms_new_admin_email_confirmation_not_sent_when_email_invalid().
|
||||
*
|
||||
* @return array {
|
||||
* @type array {
|
||||
* @type string $email The new email for admin_email
|
||||
* @type string $message An error message to display if the test fails
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
function data_user_admin_email_confirmation_emails() {
|
||||
return array(
|
||||
array(
|
||||
get_option( 'admin_email' ),
|
||||
'A confirmation email should not be sent if the current admin email matches the new email',
|
||||
),
|
||||
array(
|
||||
'not an email',
|
||||
'A confirmation email should not be sent if it is not a valid email',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A confirmation email should not be sent if user's new email:
|
||||
* - Matches their existing email, or
|
||||
* - is not a valid email, or
|
||||
* - Matches another user's email
|
||||
*
|
||||
* @dataProvider data_user_change_email_confirmation_emails
|
||||
*/
|
||||
function test_profile_email_confirmation_not_sent_invalid_email( $email, $message ) {
|
||||
|
||||
$old_current = get_current_user_id();
|
||||
|
||||
$user_id = self::factory()->user->create( array(
|
||||
'role' => 'subscriber',
|
||||
'user_email' => 'email@test.dev',
|
||||
) );
|
||||
wp_set_current_user( $user_id );
|
||||
|
||||
self::factory()->user->create( array(
|
||||
'role' => 'subscriber',
|
||||
'user_email' => 'another-user@test.dev',
|
||||
) );
|
||||
|
||||
reset_phpmailer_instance();
|
||||
|
||||
// Set $_POST['email'] with new email and $_POST['id'] with user's ID.
|
||||
$_POST['user_id'] = $user_id;
|
||||
$_POST['email'] = $email;
|
||||
send_confirmation_on_profile_email();
|
||||
|
||||
$mailer = tests_retrieve_phpmailer_instance();
|
||||
|
||||
$this->assertFalse( $mailer->get_sent(), $message );
|
||||
|
||||
wp_set_current_user( $old_current );
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_ms_profile_email_confirmation_not_sent_invalid_email().
|
||||
*
|
||||
* @return array {
|
||||
* @type array {
|
||||
* @type string $email The user's new e-amil.
|
||||
* @type string $message An error message to display if the test fails
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
function data_user_change_email_confirmation_emails() {
|
||||
return array(
|
||||
array(
|
||||
'email@test.dev',
|
||||
'Confirmation email should not be sent if it matches the user\'s existing email',
|
||||
),
|
||||
array(
|
||||
'not an email',
|
||||
'Confirmation email should not be sent if it is not a valid email',
|
||||
),
|
||||
array(
|
||||
'another-user@test.dev',
|
||||
'Confirmation email should not be sent if it matches another user\'s email',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that calling edit_user() with no password returns an error when adding, and doesn't when updating.
|
||||
*
|
||||
|
@ -451,142 +451,6 @@ class Tests_Multisite_User extends WP_UnitTestCase {
|
||||
$wp_roles->remove_role( $role );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ensure blog's admin e-mail change notification emails do not contain encoded HTML entities
|
||||
* @ticket 40015
|
||||
*/
|
||||
function test_ms_new_admin_email_notification_html_entities_decoded() {
|
||||
reset_phpmailer_instance();
|
||||
|
||||
$existing_email = get_option( 'admin_email' );
|
||||
$new_email = 'new-admin-email@test.dev';
|
||||
|
||||
// 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> &' );
|
||||
|
||||
update_option_new_admin_email( $existing_email, $new_email );
|
||||
|
||||
$mailer = tests_retrieve_phpmailer_instance();
|
||||
|
||||
$recipient = $mailer->get_recipient( 'to' );
|
||||
$email = $mailer->get_sent();
|
||||
|
||||
// Assert reciepient is correct
|
||||
$this->assertSame( $new_email, $recipient->address, 'Admin email change notification recipient not as expected' );
|
||||
|
||||
// Assert that HTML entites have been decode in body and subject
|
||||
$this->assertContains( '\'Test\' site\'s "name" has <html entities> &', $email->body, 'Email body does not contain the decoded HTML entities' );
|
||||
$this->assertNotContains( ''Test' site's "name" has <html entities> &', '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( ''Test' blog's "name" has <html entities> &', $email->subject, $email->subject, 'Email subject does contains HTML entities' );
|
||||
}
|
||||
|
||||
/**
|
||||
* A confirmation email should not be sent if the new admin email:
|
||||
* - Matches the existing admin email, or
|
||||
* - is not a valid email
|
||||
*
|
||||
* @dataProvider data_user_admin_email_confirmation_emails
|
||||
*/
|
||||
function test_ms_new_admin_email_confirmation_not_sent_when_email_invalid( $email, $message ) {
|
||||
reset_phpmailer_instance();
|
||||
|
||||
update_option_new_admin_email( get_option( 'admin_email' ), $email );
|
||||
|
||||
$mailer = tests_retrieve_phpmailer_instance();
|
||||
|
||||
$this->assertFalse( $mailer->get_sent(), $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_ms_new_admin_email_confirmation_not_sent_when_email_invalid().
|
||||
*
|
||||
* @return array {
|
||||
* @type array {
|
||||
* @type string $email The new email for admin_email
|
||||
* @type string $message An error message to display if the test fails
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
function data_user_admin_email_confirmation_emails() {
|
||||
return array(
|
||||
array(
|
||||
get_option( 'admin_email' ),
|
||||
'A confirmation email should not be sent if the current admin email matches the new email',
|
||||
),
|
||||
array(
|
||||
'not an email',
|
||||
'A confirmation email should not be sent if it is not a valid email',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A confirmation e-mail should not be sent if user's new e-mail:
|
||||
* - Matches their existing email, or
|
||||
* - is not a valid e-mail, or
|
||||
* - Matches another user's email
|
||||
*
|
||||
* @dataProvider data_user_change_email_confirmation_emails
|
||||
*/
|
||||
function test_ms_profile_email_confirmation_not_sent_invalid_email( $email, $message ) {
|
||||
|
||||
$old_current = get_current_user_id();
|
||||
|
||||
$user_id = self::factory()->user->create( array(
|
||||
'role' => 'subscriber',
|
||||
'user_email' => 'email@test.dev',
|
||||
) );
|
||||
wp_set_current_user( $user_id );
|
||||
|
||||
self::factory()->user->create( array(
|
||||
'role' => 'subscriber',
|
||||
'user_email' => 'another-user@test.dev',
|
||||
) );
|
||||
|
||||
reset_phpmailer_instance();
|
||||
|
||||
// Set $_POST['email'] with new e-mail and $_POST['id'] with user's ID.
|
||||
$_POST['user_id'] = $user_id;
|
||||
$_POST['email'] = $email;
|
||||
send_confirmation_on_profile_email();
|
||||
|
||||
$mailer = tests_retrieve_phpmailer_instance();
|
||||
|
||||
$this->assertFalse( $mailer->get_sent(), $message );
|
||||
|
||||
wp_set_current_user( $old_current );
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_ms_profile_email_confirmation_not_sent_invalid_email().
|
||||
*
|
||||
* @return array {
|
||||
* @type array {
|
||||
* @type string $email The user's new e-amil.
|
||||
* @type string $message An error message to display if the test fails
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
function data_user_change_email_confirmation_emails() {
|
||||
return array(
|
||||
array(
|
||||
'email@test.dev',
|
||||
'Confirmation e-mail should not be sent if it matches the user\'s existing e-mail',
|
||||
),
|
||||
array(
|
||||
'not an email',
|
||||
'Confirmation e-mail should not be sent if it is not a valid e-mail',
|
||||
),
|
||||
array(
|
||||
'another-user@test.dev',
|
||||
'Confirmation e-mail should not be sent if it matches another user\'s e-mail',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
endif ;
|
||||
|
Loading…
Reference in New Issue
Block a user