| 86 | | $this->assertStringContainsString( 'boundary="----=_Part_4892_25692638.1192452070893"', iconv_mime_decode_headers( ( $mailer->get_sent()->header ) )['Content-Type'][0] ); |
| 87 | | $this->assertStringContainsString( 'charset=', $mailer->get_sent()->header ); |
| | 86 | $headers = iconv_mime_decode_headers( $mailer->get_sent()->header ); |
| | 87 | $this->assertArrayHasKey( 'Content-Type', $headers, 'Expected Content-Type header to be sent.' ); |
| | 88 | $content_type_headers = (array) $headers['Content-Type']; |
| | 89 | $this->assertCount( 1, $content_type_headers, "Expected only one Content-Type header to be sent. Saw:\n" . implode( "\n", $content_type_headers ) ); |
| | 90 | $this->assertSame( 'multipart/mixed; boundary="----=_Part_4892_25692638.1192452070893"; charset=', $content_type_headers[0], 'Expected Content-Type to match.' ); |
| | 675 | |
| | 676 | /** |
| | 677 | * Test that wp_mail() can send a multipart/alternative email with plain text and html versions. |
| | 678 | * |
| | 679 | * @ticket 15448 |
| | 680 | */ |
| | 681 | public function test_wp_mail_plain_and_html() { |
| | 682 | $headers = 'Content-Type: multipart/alternative; boundary="TestBoundary"'; |
| | 683 | $to = '[email protected]'; |
| | 684 | $subject = 'Test email with plain text and html versions'; |
| | 685 | $message = <<<EOT |
| | 686 | --TestBoundary |
| | 687 | Content-Type: text/plain; charset=us-ascii |
| | 688 | |
| | 689 | Here is some plain text. |
| | 690 | --TestBoundary |
| | 691 | Content-Type: text/html; charset=UTF-8 |
| | 692 | Content-Transfer-Encoding: 8bit |
| | 693 | |
| | 694 | <html><head></head><body>Here is the HTML with UTF-8 γειά σου Κόσμε;-)<body></html> |
| | 695 | --TestBoundary-- |
| | 696 | EOT; |
| | 697 | |
| | 698 | wp_mail( $to, $subject, $message, $headers ); |
| | 699 | $mailer = tests_retrieve_phpmailer_instance(); |
| | 700 | |
| | 701 | $this->assertSame( 1, preg_match( '/boundary="(.*)"/', $mailer->get_sent()->header, $matches ), 'Expected to match boundary directive in header.' ); |
| | 702 | $boundary = $matches[1]; |
| | 703 | $body = '--' . $boundary . "\n"; |
| | 704 | $body .= 'Content-Type: text/plain; charset=us-ascii' . "\n"; |
| | 705 | $body .= "\n"; |
| | 706 | $body .= 'Here is some plain text.' . "\n"; |
| | 707 | $body .= '--' . $boundary . "\n"; |
| | 708 | $body .= 'Content-Type: text/html; charset=UTF-8' . "\n"; |
| | 709 | $body .= 'Content-Transfer-Encoding: 8bit' . "\n"; |
| | 710 | $body .= "\n"; |
| | 711 | $body .= '<html><head></head><body>Here is the HTML with UTF-8 γειά σου Κόσμε;-)<body></html>' . "\n"; |
| | 712 | $body .= '--' . $boundary . '--' . "\n"; |
| | 713 | |
| | 714 | $this->assertSameIgnoreEOL( $body, $mailer->get_sent()->body, 'The body is not as expected.' ); |
| | 715 | $this->assertStringContainsString( |
| | 716 |