Make WordPress Core

Ticket #36658: 36658.diff

File 36658.diff, 7.6 KB (added by welcher, 8 years ago)
  • tests/phpunit/includes/mock-mailer.php

     
    7777 *
    7878 * @return object|bool
    7979 */
    80 function tests_retrieve_phpmailer_instance() {
     80function retrieve_phpmailer_instance() {
    8181        $mailer = false;
    8282        if ( isset( $GLOBALS['phpmailer'] ) ) {
    8383                $mailer = $GLOBALS['phpmailer'];
     
    8484        }
    8585        return $mailer;
    8686}
     87
     88
     89/**
     90 * Helper method to reset the phpmailer instance.
     91 *
     92 * @since 4.6.0
     93 *
     94 * @return bool
     95 */
     96function reset_php_mailer_instance() {
     97        $mailer = retrieve_phpmailer_instance();
     98        if ( $mailer && isset( $mailer->mock_sent ) ) {
     99                unset( $mailer->mock_sent );
     100                return true;
     101        }
     102
     103        return false;
     104}
  • tests/phpunit/tests/comment.php

     
    99
    1010        public function setUp() {
    1111                parent::setUp();
    12                 unset( $GLOBALS['phpmailer']->mock_sent );
     12                reset_php_mailer_instance();
    1313        }
    1414
    1515        public static function wpSetUpBeforeClass( $factory ) {
     
    558558                        && WP_TESTS_EMAIL == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]
    559559                ) {
    560560                        $email_sent_when_comment_added = true;
    561                         unset( $GLOBALS['phpmailer']->mock_sent );
     561                        reset_php_mailer_instance();
    562562                } else {
    563563                        $email_sent_when_comment_added = false;
    564564                }
     
    589589                } else {
    590590                        $email_sent_when_comment_approved = false;
    591591                }
    592                 unset( $GLOBALS['phpmailer']->mock_sent );
     592                reset_php_mailer_instance();
    593593
    594594                // Post authors are notified when a new comment is added to their post.
    595595                $data = array(
     
    607607                     ! empty( $GLOBALS['phpmailer']->mock_sent ) &&
    608608                     'test@test.com' == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] ) {
    609609                        $email_sent_when_comment_added = true;
    610                         unset( $GLOBALS['phpmailer']->mock_sent );
     610                        reset_php_mailer_instance();
    611611                } else {
    612612                        $email_sent_when_comment_added = false;
    613613                }
  • tests/phpunit/tests/mail.php

     
    66class Tests_Mail extends WP_UnitTestCase {
    77        function setUp() {
    88                parent::setUp();
    9                 unset( $GLOBALS['phpmailer']->mock_sent );
     9                reset_php_mailer_instance();
    1010        }
    1111
    1212        function tearDown() {
    13                 unset( $GLOBALS['phpmailer']->mock_sent );
    1413                parent::tearDown();
     14                reset_php_mailer_instance();
    1515        }
    1616
    1717        /**
     
    7878
    7979                wp_mail( $to, $subject, $body, $headers );
    8080
    81                 $mailer = tests_retrieve_phpmailer_instance();
     81                $mailer = retrieve_phpmailer_instance();
    8282
    8383                // We need some better assertions here but these catch the failure for now.
    8484                $this->assertEquals( $body, $mailer->get_sent()->body );
     
    106106                // Earlier versions of PHPMailer were not touchy about the formatting of these arguments.
    107107
    108108                //retrieve the mailer instance
    109                 $mailer = tests_retrieve_phpmailer_instance();
     109                $mailer = retrieve_phpmailer_instance();
    110110                $this->assertEquals( 'address@tld.com',      $mailer->get_recipient( 'to' )->address );
    111111                $this->assertEquals( 'Name',                 $mailer->get_recipient( 'to' )->name );
    112112                $this->assertEquals( 'cc@cc.com',            $mailer->get_recipient( 'cc' )->address );
     
    128128
    129129                // WordPress 3.2 and later correctly split the address into the two parts and send them seperately to PHPMailer
    130130                // Earlier versions of PHPMailer were not touchy about the formatting of these arguments.
    131                 $mailer = tests_retrieve_phpmailer_instance();
     131                $mailer = retrieve_phpmailer_instance();
    132132                $this->assertEquals( 'address@tld.com',                   $mailer->get_recipient( 'to' )->address );
    133133                $this->assertEquals( 'Name',                              $mailer->get_recipient( 'to' )->name );
    134134                $this->assertEquals( 'another_address@different-tld.com', $mailer->get_recipient( 'to', 0, 1 )->address );
     
    143143
    144144                wp_mail( $to, $subject, $message );
    145145
    146                 $mailer = tests_retrieve_phpmailer_instance();
     146                $mailer = retrieve_phpmailer_instance();
    147147                $this->assertEquals( 'address@tld.com',                   $mailer->get_recipient( 'to' )->address );
    148148                $this->assertEquals( 'another_address@different-tld.com', $mailer->get_recipient( 'to', 0, 1 )->address );
    149149                $this->assertEquals( $message . "\n",                     $mailer->get_sent()->body );
     
    159159
    160160                wp_mail( $to, $subject, $message );
    161161
    162                 $mailer = tests_retrieve_phpmailer_instance();
     162                $mailer = retrieve_phpmailer_instance();
    163163                $this->assertEquals( 'address@tld.com', $mailer->get_recipient( 'to' )->address );
    164164                $this->assertEquals( $message . "\n",    $mailer->get_sent()->body );
    165165        }
     
    190190
    191191                wp_mail( $to, $subject, $message, $headers );
    192192
    193                 $mailer = tests_retrieve_phpmailer_instance();
     193                $mailer = retrieve_phpmailer_instance();
    194194                $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
    195195        }
    196196
     
    206206
    207207                wp_mail( $to, $subject, $message, $headers );
    208208
    209                 $mailer = tests_retrieve_phpmailer_instance();
     209                $mailer = retrieve_phpmailer_instance();
    210210                $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
    211211        }
    212212
     
    222222
    223223                wp_mail( $to, $subject, $message, $headers );
    224224
    225                 $mailer = tests_retrieve_phpmailer_instance();
     225                $mailer = retrieve_phpmailer_instance();
    226226                $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
    227227        }
    228228
     
    238238
    239239                wp_mail( $to, $subject, $message, $headers );
    240240
    241                 $mailer = tests_retrieve_phpmailer_instance();
     241                $mailer = retrieve_phpmailer_instance();
    242242                $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
    243243        }
    244244
     
    254254
    255255                wp_mail( $to, $subject, $message, $headers );
    256256
    257                 $mailer = tests_retrieve_phpmailer_instance();
     257                $mailer = retrieve_phpmailer_instance();
    258258                $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
    259259        }
    260260
     
    270270
    271271                wp_mail( $to, $subject, $message, $headers );
    272272
    273                 $mailer = tests_retrieve_phpmailer_instance();
     273                $mailer = retrieve_phpmailer_instance();
    274274                $this->assertTrue( strpos( $mailer->get_sent()->header, $expected ) > 0 );
    275275        }
    276276
  • tests/phpunit/tests/user.php

     
    10241024         * @ticket 36009
    10251025         */
    10261026        function test_wp_new_user_notification( $notify, $admin_email_sent_expected, $user_email_sent_expected ) {
    1027                 unset( $GLOBALS['phpmailer']->mock_sent );
     1027                reset_php_mailer_instance();
    10281028
    10291029                $was_admin_email_sent = false;
    10301030                $was_user_email_sent = false;
     
    10311031
    10321032                wp_new_user_notification( self::$contrib_id, null, $notify );
    10331033
    1034                 $mailer = tests_retrieve_phpmailer_instance();
     1034                $mailer = retrieve_phpmailer_instance();
    10351035
    10361036                /*
    10371037                 * Check to see if a notification email was sent to the
     
    11001100         * @expectedDeprecated wp_new_user_notification
    11011101         */
    11021102        function test_wp_new_user_notification_old_signature_throws_deprecated_warning_but_sends() {
    1103                 unset( $GLOBALS['phpmailer']->mock_sent );
     1103                reset_php_mailer_instance();
    11041104
    11051105                $was_admin_email_sent = false;
    11061106                $was_user_email_sent = false;
     
    11251125         * @ticket 34377
    11261126         */
    11271127        function test_wp_new_user_notification_old_signature_no_password() {
    1128                 unset( $GLOBALS['phpmailer']->mock_sent );
     1128                reset_php_mailer_instance();
    11291129
    11301130                $was_admin_email_sent = false;
    11311131                $was_user_email_sent = false;