WordPress.org

Make WordPress Core

Changeset 359 in tests


Ignore:
Timestamp:
05/23/11 10:33:35 (3 years ago)
Author:
westi
Message:

Add some test cases for wp_mail behaviour with RFC2822 addresses like "Name < address@…>".

These worked fine with the old PHP4 compatible PHPMailer but the PHP5 only version is more strict about how we configure it.

The test cases have different expected results for old and new WordPress versions because of this.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_pluggable.php

    r329 r359  
    141141        unset( $_SERVER['SERVER_NAME'] ); 
    142142    } 
     143 
     144    function test_wp_mail_rfc2822_addresses() { 
     145        $this->knownWPBug(17305); 
     146         
     147        $to = "Name <address@tld.com>"; 
     148        $from = "Another Name <another_address@different-tld.com>"; 
     149        $cc = "The Carbon Guy <cc@cc.com>"; 
     150        $bcc = "The Blind Carbon Guy <bcc@bcc.com>"; 
     151        $subject = "RFC2822 Testing"; 
     152        $message = "My RFC822 Test Message"; 
     153        $headers[] = "From: {$from}"; 
     154        $headers[] = "CC: {$cc}"; 
     155        $headers[] = "BCC: {$bcc}"; 
     156 
     157        unset($GLOBALS['phpmailer']->mock_sent); 
     158        $_SERVER['SERVER_NAME'] = 'example.com'; 
     159        wp_mail( $to, $subject, $message, $headers ); 
     160 
     161        // WordPress 3.2 and later correctly split the address into the two parts and send them seperately to PHPMailer 
     162        // Earlier versions of PHPMailer were not touchy about the formatting of these arguments. 
     163        if ( version_compare( $GLOBALS['wp_version'], '3.1.9', '>' ) ) { 
     164            $this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]); 
     165            $this->assertEquals('Name', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][1]); 
     166            $this->assertEquals('cc@cc.com', $GLOBALS['phpmailer']->mock_sent[0]['cc'][0][0]); 
     167            $this->assertEquals('The Carbon Guy', $GLOBALS['phpmailer']->mock_sent[0]['cc'][0][1]); 
     168            $this->assertEquals('bcc@bcc.com', $GLOBALS['phpmailer']->mock_sent[0]['bcc'][0][0]); 
     169            $this->assertEquals('The Blind Carbon Guy', $GLOBALS['phpmailer']->mock_sent[0]['bcc'][0][1]); 
     170        } else { 
     171            $this->assertEquals($to, $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]); 
     172            $this->assertEquals($cc, $GLOBALS['phpmailer']->mock_sent[0]['cc'][0][0]); 
     173            $this->assertEquals($bcc, $GLOBALS['phpmailer']->mock_sent[0]['bcc'][0][0]); 
     174        } 
     175 
     176        $this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']); 
     177        unset( $_SERVER['SERVER_NAME'] ); 
     178    } 
     179 
     180    function test_wp_mail_multiple_rfc2822_to_addresses() { 
     181        $this->knownWPBug(17305); 
     182         
     183        $to = "Name <address@tld.com>, Another Name <another_address@different-tld.com>"; 
     184        $subject = "RFC2822 Testing"; 
     185        $message = "My RFC822 Test Message"; 
     186 
     187        unset($GLOBALS['phpmailer']->mock_sent); 
     188        $_SERVER['SERVER_NAME'] = 'example.com'; 
     189        wp_mail( $to, $subject, $message ); 
     190 
     191        // WordPress 3.2 and later correctly split the address into the two parts and send them seperately to PHPMailer 
     192        // Earlier versions of PHPMailer were not touchy about the formatting of these arguments. 
     193        if ( version_compare( $GLOBALS['wp_version'], '3.1.9', '>' ) ) { 
     194            $this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]); 
     195            $this->assertEquals('Name', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][1]); 
     196            $this->assertEquals('another_address@different-tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][0]); 
     197            $this->assertEquals('Another Name', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][1]); 
     198        } else { 
     199            $this->assertEquals('Name <address@tld.com>', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]); 
     200            $this->assertEquals('Another Name <another_address@different-tld.com>', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][0]); 
     201        } 
     202 
     203        $this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']); 
     204        unset( $_SERVER['SERVER_NAME'] ); 
     205    } 
     206 
     207    function test_wp_mail_multiple_to_addresses() { 
     208        $to = "address@tld.com, another_address@different-tld.com"; 
     209        $subject = "RFC2822 Testing"; 
     210        $message = "My RFC822 Test Message"; 
     211 
     212        unset($GLOBALS['phpmailer']->mock_sent); 
     213        $_SERVER['SERVER_NAME'] = 'example.com'; 
     214        wp_mail( $to, $subject, $message ); 
     215 
     216        $this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]); 
     217        $this->assertEquals('another_address@different-tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][0]); 
     218        $this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']); 
     219        unset( $_SERVER['SERVER_NAME'] ); 
     220    } 
    143221} 
    144222 
Note: See TracChangeset for help on using the changeset viewer.