mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Tests: Add decorators to PHPMailer mock object.
The new `get_recipient()` and `get_sent()` methods greatly simplify the syntax required when writing tests for `wp_mail()`. Props welcher. Fixes #34161. git-svn-id: https://develop.svn.wordpress.org/trunk@36594 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1028,14 +1028,18 @@ class Tests_User extends WP_UnitTestCase {
|
||||
|
||||
wp_new_user_notification( self::$contrib_id, null, $notify );
|
||||
|
||||
$mailer = tests_retrieve_phpmailer_instance();
|
||||
|
||||
/*
|
||||
* Check to see if a notification email was sent to the
|
||||
* post author `blackburn@battlefield3.com` and and site admin `admin@example.org`.
|
||||
*/
|
||||
if ( ! empty( $GLOBALS['phpmailer']->mock_sent ) ) {
|
||||
$was_admin_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && WP_TESTS_EMAIL == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] );
|
||||
$was_user_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[1] ) && 'blackburn@battlefield3.com' == $GLOBALS['phpmailer']->mock_sent[1]['to'][0][0] );
|
||||
}
|
||||
$admin_email = $mailer->get_recipient( 'to' );
|
||||
$was_admin_email_sent = $admin_email && WP_TESTS_EMAIL === $admin_email->address;
|
||||
|
||||
$user_email = $mailer->get_recipient( 'to', 1 );
|
||||
$was_user_email_sent = $user_email && 'blackburn@battlefield3.com' == $user_email->address;
|
||||
|
||||
|
||||
$this->assertSame( $admin_email_sent_expected, $was_admin_email_sent, 'Admin email result was not as expected in test_wp_new_user_notification' );
|
||||
$this->assertSame( $user_email_sent_expected , $was_user_email_sent, 'User email result was not as expected in test_wp_new_user_notification' );
|
||||
|
||||
Reference in New Issue
Block a user