Make WordPress Core


Ignore:
Timestamp:
02/20/2016 03:40:49 AM (9 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user.php

    r36482 r36594  
    10291029        wp_new_user_notification( self::$contrib_id, null, $notify );
    10301030
     1031        $mailer = tests_retrieve_phpmailer_instance();
     1032
    10311033        /*
    10321034         * Check to see if a notification email was sent to the
    10331035         * post author `blackburn@battlefield3.com` and and site admin `admin@example.org`.
    10341036         */
    1035         if ( ! empty( $GLOBALS['phpmailer']->mock_sent ) ) {
    1036             $was_admin_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && WP_TESTS_EMAIL == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] );
    1037             $was_user_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[1] ) && 'blackburn@battlefield3.com' == $GLOBALS['phpmailer']->mock_sent[1]['to'][0][0] );
    1038         }
     1037        $admin_email = $mailer->get_recipient( 'to' );
     1038        $was_admin_email_sent = $admin_email && WP_TESTS_EMAIL === $admin_email->address;
     1039
     1040        $user_email = $mailer->get_recipient( 'to', 1 );
     1041        $was_user_email_sent = $user_email && 'blackburn@battlefield3.com' == $user_email->address;
     1042
    10391043
    10401044        $this->assertSame( $admin_email_sent_expected, $was_admin_email_sent, 'Admin email result was not as expected in test_wp_new_user_notification' );
Note: See TracChangeset for help on using the changeset viewer.