Changeset 41255 for trunk/tests/phpunit/tests/user/multisite.php
- Timestamp:
- 08/15/2017 09:15:53 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/user/multisite.php
r41225 r41255 452 452 } 453 453 454 455 /**456 * Ensure blog's admin e-mail change notification emails do not contain encoded HTML entities457 * @ticket 40015458 */459 function test_ms_new_admin_email_notification_html_entities_decoded() {460 reset_phpmailer_instance();461 462 $existing_email = get_option( 'admin_email' );463 $new_email = 'new-admin-email@test.dev';464 465 // Give the site and blog a name containing HTML entities466 update_site_option( 'site_name', ''Test' site's "name" has <html entities> &' );467 update_option( 'blogname', ''Test' blog's "name" has <html entities> &' );468 469 update_option_new_admin_email( $existing_email, $new_email );470 471 $mailer = tests_retrieve_phpmailer_instance();472 473 $recipient = $mailer->get_recipient( 'to' );474 $email = $mailer->get_sent();475 476 // Assert reciepient is correct477 $this->assertSame( $new_email, $recipient->address, 'Admin email change notification recipient not as expected' );478 479 // Assert that HTML entites have been decode in body and subject480 $this->assertContains( '\'Test\' site\'s "name" has <html entities> &', $email->body, 'Email body does not contain the decoded HTML entities' );481 $this->assertNotContains( ''Test' site's "name" has <html entities> &', 'Email body does contains HTML entities' );482 $this->assertContains( '\'Test\' blog\'s "name" has <html entities> &', $email->subject, 'Email subject does not contain the decoded HTML entities' );483 $this->assertNotContains( ''Test' blog's "name" has <html entities> &', $email->subject, $email->subject, 'Email subject does contains HTML entities' );484 }485 486 /**487 * A confirmation email should not be sent if the new admin email:488 * - Matches the existing admin email, or489 * - is not a valid email490 *491 * @dataProvider data_user_admin_email_confirmation_emails492 */493 function test_ms_new_admin_email_confirmation_not_sent_when_email_invalid( $email, $message ) {494 reset_phpmailer_instance();495 496 update_option_new_admin_email( get_option( 'admin_email' ), $email );497 498 $mailer = tests_retrieve_phpmailer_instance();499 500 $this->assertFalse( $mailer->get_sent(), $message );501 }502 503 /**504 * Data provider for test_ms_new_admin_email_confirmation_not_sent_when_email_invalid().505 *506 * @return array {507 * @type array {508 * @type string $email The new email for admin_email509 * @type string $message An error message to display if the test fails510 * }511 * }512 */513 function data_user_admin_email_confirmation_emails() {514 return array(515 array(516 get_option( 'admin_email' ),517 'A confirmation email should not be sent if the current admin email matches the new email',518 ),519 array(520 'not an email',521 'A confirmation email should not be sent if it is not a valid email',522 )523 );524 }525 526 /**527 * A confirmation e-mail should not be sent if user's new e-mail:528 * - Matches their existing email, or529 * - is not a valid e-mail, or530 * - Matches another user's email531 *532 * @dataProvider data_user_change_email_confirmation_emails533 */534 function test_ms_profile_email_confirmation_not_sent_invalid_email( $email, $message ) {535 536 $old_current = get_current_user_id();537 538 $user_id = self::factory()->user->create( array(539 'role' => 'subscriber',540 'user_email' => 'email@test.dev',541 ) );542 wp_set_current_user( $user_id );543 544 self::factory()->user->create( array(545 'role' => 'subscriber',546 'user_email' => 'another-user@test.dev',547 ) );548 549 reset_phpmailer_instance();550 551 // Set $_POST['email'] with new e-mail and $_POST['id'] with user's ID.552 $_POST['user_id'] = $user_id;553 $_POST['email'] = $email;554 send_confirmation_on_profile_email();555 556 $mailer = tests_retrieve_phpmailer_instance();557 558 $this->assertFalse( $mailer->get_sent(), $message );559 560 wp_set_current_user( $old_current );561 }562 563 /**564 * Data provider for test_ms_profile_email_confirmation_not_sent_invalid_email().565 *566 * @return array {567 * @type array {568 * @type string $email The user's new e-amil.569 * @type string $message An error message to display if the test fails570 * }571 * }572 */573 function data_user_change_email_confirmation_emails() {574 return array(575 array(576 'email@test.dev',577 'Confirmation e-mail should not be sent if it matches the user\'s existing e-mail',578 ),579 array(580 'not an email',581 'Confirmation e-mail should not be sent if it is not a valid e-mail',582 ),583 array(584 'another-user@test.dev',585 'Confirmation e-mail should not be sent if it matches another user\'s e-mail',586 ),587 );588 }589 590 454 } 591 455
Note: See TracChangeset
for help on using the changeset viewer.