Make WordPress Core

Ticket #35598: 35598.4.diff

File 35598.4.diff, 2.8 KB (added by stephenharris, 5 years ago)
  • src/wp-includes/pluggable.php

    diff --git src/wp-includes/pluggable.php src/wp-includes/pluggable.php
    index fe4c0a9..d739f44 100644
    function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() 
    471471        } catch ( phpmailerException $e ) {
    472472
    473473                $mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
     474                $mail_error_data['phpmailer_exception_code'] = $e->getCode();
    474475
    475476                /**
    476477                 * Fires after a phpmailerException is caught.
    477478                 *
    478479                 * @since 4.4.0
    479480                 *
    480                  * @param WP_Error $error A WP_Error object with the phpmailerException code, message, and an array
     481                 * @param WP_Error $error A WP_Error object with the phpmailerException message, and an array
    481482                 *                        containing the mail recipient, subject, message, headers, and attachments.
    482483                 */
    483                 do_action( 'wp_mail_failed', new WP_Error( $e->getCode(), $e->getMessage(), $mail_error_data ) );
     484                do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );
    484485
    485486                return false;
    486487        }
  • tests/phpunit/includes/bootstrap.php

    diff --git tests/phpunit/includes/bootstrap.php tests/phpunit/includes/bootstrap.php
    index 299429b..34153a6 100644
    $multisite = $multisite || ( defined( 'MULTISITE' ) && MULTISITE ); 
    4949
    5050// Override the PHPMailer
    5151require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
    52 $phpmailer = new MockPHPMailer();
     52$phpmailer = new MockPHPMailer( true );
    5353
    5454system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite );
    5555
  • tests/phpunit/tests/mail.php

    diff --git tests/phpunit/tests/mail.php tests/phpunit/tests/mail.php
    index d3e7698..1522594 100644
    class Tests_Mail extends WP_UnitTestCase { 
    360360
    361361                $this->assertEquals( '', $mailer->Sender );
    362362        }
     363
     364        /**
     365         * @ticket 35598
     366         */
     367        public function test_phpmailer_exception_thrown() {
     368                $to       = 'an_invalid_address';
     369                $subject  = 'Testing';
     370                $message  = 'Test Message';
     371
     372                $ma = new MockAction();
     373                add_action( 'wp_mail_failed', array( &$ma, 'action' ) );
     374
     375                wp_mail( $to, $subject, $message );
     376
     377                $this->assertEquals( 1, $ma->get_call_count() );
     378
     379                $expected_error_data = array(
     380                        'to'          => array( 'an_invalid_address' ),
     381                        'subject'     => 'Testing',
     382                        'message'     => 'Test Message',
     383                        'headers'     => array(),
     384                        'attachments' => array(),
     385                        'phpmailer_exception_code' => 2,
     386                );
     387
     388                //Retrieve the arguments passed to the 'wp_mail_failed' hook callbacks
     389                $all_args = $ma->get_args();
     390                $call_args = array_pop( $all_args );
     391
     392                $this->assertEquals( 'wp_mail_failed', $call_args[0]->get_error_code() );
     393                $this->assertEquals( $expected_error_data, $call_args[0]->get_error_data() );
     394        }
    363395}