Make WordPress Core

Ticket #23291: 23291-unit-tests.3.diff

File 23291-unit-tests.3.diff, 1.8 KB (added by iandunn, 12 years ago)
  • tests/mail.php

     
    223223                // Fatal errors
    224224                $this->assertFalse( wp_mail( 'invalid.address', 'subject', 'body', '', array() ) );
    225225        }
     226
     227        /**
     228         * @ticket 23291
     229         */
     230        function test_wp_mail_return_value_with_wp_error() {
     231                global $phpmailer;
     232                $phpmailer = new MockPHPMailer( true ); // recreate the mailer with exceptions turned on
     233
     234                // No errors
     235                $this->assertTrue( wp_mail( 'valid-address@example.net', 'subject', 'body' ), true );
     236
     237                // Non-fatal errors
     238                $result = wp_mail( 'valid-address@example.org', 'subject', 'body', "Cc: invalid_address\nBcc: another_invalid_address", array( '/this/file/does/not/exist' ), true );
     239                $this->assertWPError( $result );
     240                $this->assertCount( 3, $result->get_error_codes() );
     241                $this->assertContains( 'mailer_add_cc', $result->get_error_codes() );
     242                $this->assertContains( 'mailer_add_bcc', $result->get_error_codes() );
     243                $this->assertContains( 'mailer_add_attachment', $result->get_error_codes() );
     244                $this->assertNotContains( 'mailer_send', $result->get_error_codes() );
     245
     246                // Fatal error
     247                $result = wp_mail( 'invalid.address', 'subject', 'body', '', array(), true );
     248                $this->assertWPError( $result );
     249                $this->assertCount( 2, $result->get_error_codes() );
     250                $this->assertContains( 'mailer_add_address', $result->get_error_codes() );
     251                $this->assertContains( 'mailer_send', $result->get_error_codes() );
     252        }
    226253}
  • includes/mock-mailer.php

     
    2020
    2121                        return true;
    2222                } catch ( phpmailerException $e ) {
     23                        if ( $this->exceptions ) {
     24                                throw $e;
     25                        }
    2326                        return false;
    2427                }
    2528        }