WordPress.org

Make WordPress Core

Ticket #15448: 15448-unittests.diff

File 15448-unittests.diff, 1.3 KB (added by MikeHansenMe, 5 years ago)

see #30284

  • tests/phpunit/tests/mail.php

    diff --git a/tests/phpunit/tests/mail.php b/tests/phpunit/tests/mail.php
    index 547ed99..d7d5abf 100644
    a b class Tests_Mail extends WP_UnitTestCase { 
    7272        }
    7373
    7474        /**
     75         * @ticket 15448
     76         */
     77        function test_wp_mail_plain_and_html() {
     78                $to = 'user@example.com';
     79                $subject = 'Test email with plain text and html versions';
     80                $messages = array( 'text/plain' => 'Here is some plain text.',
     81                                           'text/html' =>'<html><head></head><body>Here is the HTML ;-)<body></html>' );
     82
     83                wp_mail( $to, $subject, $messages );
     84
     85                preg_match( '/boundary="(.*)"/', $GLOBALS['phpmailer']->mock_sent[0]['header'], $matches);
     86                $boundry = $matches[1];
     87                $body = '--' . $boundry . '
     88Content-Type: text/plain; charset = "UTF-8"
     89Content-Transfer-Encoding: 8bit
     90
     91Here is some plain text.
     92
     93
     94--' . $boundry . '
     95Content-Type: text/html; charset = "UTF-8"
     96Content-Transfer-Encoding: 8bit
     97
     98<html><head></head><body>Here is the HTML ;-)<body></html>
     99
     100
     101
     102--' . $boundry . '--
     103';
     104                // We need some better assertions here but these test the behaviour for now.
     105                $this->assertEquals($body, $GLOBALS['phpmailer']->mock_sent[0]['body']);
     106        }
     107
     108        /**
    75109         * @ticket 17305
    76110         */
    77111        function test_wp_mail_rfc2822_addresses() {