Tests: Introduce `reset_phpmailer_instance()` function.
This function provides a more convenient method for resetting the PHPMailer instance than the previous technique of reaching into the global. Props welcher. Fixes #36658. git-svn-id: https://develop.svn.wordpress.org/trunk@37358 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
23b3f3e2ee
commit
8e417dd09b
|
@ -84,3 +84,20 @@ function tests_retrieve_phpmailer_instance() {
|
||||||
}
|
}
|
||||||
return $mailer;
|
return $mailer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to reset the phpmailer instance.
|
||||||
|
*
|
||||||
|
* @since 4.6.0
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function reset_phpmailer_instance() {
|
||||||
|
$mailer = tests_retrieve_phpmailer_instance();
|
||||||
|
if ( $mailer && isset( $mailer->mock_sent ) ) {
|
||||||
|
unset( $mailer->mock_sent );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Tests_Comment extends WP_UnitTestCase {
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
unset( $GLOBALS['phpmailer']->mock_sent );
|
reset_phpmailer_instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function wpSetUpBeforeClass( $factory ) {
|
public static function wpSetUpBeforeClass( $factory ) {
|
||||||
|
@ -558,7 +558,7 @@ class Tests_Comment extends WP_UnitTestCase {
|
||||||
&& WP_TESTS_EMAIL == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]
|
&& WP_TESTS_EMAIL == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]
|
||||||
) {
|
) {
|
||||||
$email_sent_when_comment_added = true;
|
$email_sent_when_comment_added = true;
|
||||||
unset( $GLOBALS['phpmailer']->mock_sent );
|
reset_phpmailer_instance();
|
||||||
} else {
|
} else {
|
||||||
$email_sent_when_comment_added = false;
|
$email_sent_when_comment_added = false;
|
||||||
}
|
}
|
||||||
|
@ -589,7 +589,7 @@ class Tests_Comment extends WP_UnitTestCase {
|
||||||
} else {
|
} else {
|
||||||
$email_sent_when_comment_approved = false;
|
$email_sent_when_comment_approved = false;
|
||||||
}
|
}
|
||||||
unset( $GLOBALS['phpmailer']->mock_sent );
|
reset_phpmailer_instance();
|
||||||
|
|
||||||
// Post authors are notified when a new comment is added to their post.
|
// Post authors are notified when a new comment is added to their post.
|
||||||
$data = array(
|
$data = array(
|
||||||
|
@ -607,7 +607,7 @@ class Tests_Comment extends WP_UnitTestCase {
|
||||||
! empty( $GLOBALS['phpmailer']->mock_sent ) &&
|
! empty( $GLOBALS['phpmailer']->mock_sent ) &&
|
||||||
'test@test.com' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ) {
|
'test@test.com' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ) {
|
||||||
$email_sent_when_comment_added = true;
|
$email_sent_when_comment_added = true;
|
||||||
unset( $GLOBALS['phpmailer']->mock_sent );
|
reset_phpmailer_instance();
|
||||||
} else {
|
} else {
|
||||||
$email_sent_when_comment_added = false;
|
$email_sent_when_comment_added = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
class Tests_Mail extends WP_UnitTestCase {
|
class Tests_Mail extends WP_UnitTestCase {
|
||||||
function setUp() {
|
function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
unset( $GLOBALS['phpmailer']->mock_sent );
|
reset_phpmailer_instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
unset( $GLOBALS['phpmailer']->mock_sent );
|
reset_phpmailer_instance();
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1024,7 +1024,7 @@ class Tests_User extends WP_UnitTestCase {
|
||||||
* @ticket 36009
|
* @ticket 36009
|
||||||
*/
|
*/
|
||||||
function test_wp_new_user_notification( $notify, $admin_email_sent_expected, $user_email_sent_expected ) {
|
function test_wp_new_user_notification( $notify, $admin_email_sent_expected, $user_email_sent_expected ) {
|
||||||
unset( $GLOBALS['phpmailer']->mock_sent );
|
reset_phpmailer_instance();
|
||||||
|
|
||||||
$was_admin_email_sent = false;
|
$was_admin_email_sent = false;
|
||||||
$was_user_email_sent = false;
|
$was_user_email_sent = false;
|
||||||
|
@ -1100,7 +1100,7 @@ class Tests_User extends WP_UnitTestCase {
|
||||||
* @expectedDeprecated wp_new_user_notification
|
* @expectedDeprecated wp_new_user_notification
|
||||||
*/
|
*/
|
||||||
function test_wp_new_user_notification_old_signature_throws_deprecated_warning_but_sends() {
|
function test_wp_new_user_notification_old_signature_throws_deprecated_warning_but_sends() {
|
||||||
unset( $GLOBALS['phpmailer']->mock_sent );
|
reset_phpmailer_instance();
|
||||||
|
|
||||||
$was_admin_email_sent = false;
|
$was_admin_email_sent = false;
|
||||||
$was_user_email_sent = false;
|
$was_user_email_sent = false;
|
||||||
|
@ -1125,7 +1125,7 @@ class Tests_User extends WP_UnitTestCase {
|
||||||
* @ticket 34377
|
* @ticket 34377
|
||||||
*/
|
*/
|
||||||
function test_wp_new_user_notification_old_signature_no_password() {
|
function test_wp_new_user_notification_old_signature_no_password() {
|
||||||
unset( $GLOBALS['phpmailer']->mock_sent );
|
reset_phpmailer_instance();
|
||||||
|
|
||||||
$was_admin_email_sent = false;
|
$was_admin_email_sent = false;
|
||||||
$was_user_email_sent = false;
|
$was_user_email_sent = false;
|
||||||
|
|
Loading…
Reference in New Issue