| | 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 | } |