Make WordPress Core

Changeset 25381


Ignore:
Timestamp:
09/12/2013 04:46:49 AM (11 years ago)
Author:
wonderboymusic
Message:

Avoid a notice and clean up setting/unsetting of globals by moving them into setUp() and tearDown() methods in Tests_Mail.

See #25282.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/mail.php

    r25264 r25381  
    11<?php
    2 
    32/**
    43 * @group pluggable
     
    87    function setUp() {
    98        parent::setUp();
     9        $_SERVER['SERVER_NAME'] = 'example.com';
     10        unset( $GLOBALS['phpmailer']->mock_sent );
     11    }
     12
     13    function tearDown() {
     14        parent::tearDown();
     15        unset( $_SERVER['SERVER_NAME'] );
    1016    }
    1117
     
    5864        $body .= "\n";
    5965
    60         unset($GLOBALS['phpmailer']->mock_sent);
    61         $_SERVER['SERVER_NAME'] = 'example.com';
    6266        wp_mail($to, $subject, $body, $headers);
    6367
     
    6670        $this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'boundary="----=_Part_4892_25692638.1192452070893"') > 0);
    6771        $this->assertTrue(strpos($GLOBALS['phpmailer']->mock_sent[0]['header'], 'charset=') > 0);
    68         unset( $_SERVER['SERVER_NAME'] );
    6972    }
    7073
     
    7376     */
    7477    function test_wp_mail_plain_and_html() {
    75 
    7678        $to = 'user@example.com';
    7779        $subject = 'Test email with plain text and html versions';
     
    7981                       'text/html' =>'<html><head></head><body>Here is the HTML ;-)<body></html>' );
    8082
    81         unset($GLOBALS['phpmailer']->mock_sent);
    82         $_SERVER['SERVER_NAME'] = 'example.com';
    8383        wp_mail( $to, $subject, $messages );
    8484
     
    104104        // We need some better assertions here but these test the behaviour for now.
    105105        $this->assertEquals($body, $GLOBALS['phpmailer']->mock_sent[0]['body']);
    106         unset( $_SERVER['SERVER_NAME'] );
    107106    }
    108107
     
    111110     */
    112111    function test_wp_mail_rfc2822_addresses() {
    113 
    114112        $to = "Name <address@tld.com>";
    115113        $from = "Another Name <another_address@different-tld.com>";
     
    122120        $headers[] = "BCC: {$bcc}";
    123121
    124         unset($GLOBALS['phpmailer']->mock_sent);
    125         $_SERVER['SERVER_NAME'] = 'example.com';
    126122        wp_mail( $to, $subject, $message, $headers );
    127123
     
    134130        $this->assertEquals('bcc@bcc.com', $GLOBALS['phpmailer']->mock_sent[0]['bcc'][0][0]);
    135131        $this->assertEquals('The Blind Carbon Guy', $GLOBALS['phpmailer']->mock_sent[0]['bcc'][0][1]);
    136 
    137132        $this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);
    138         unset( $_SERVER['SERVER_NAME'] );
    139133    }
    140134
     
    143137     */
    144138    function test_wp_mail_multiple_rfc2822_to_addresses() {
    145 
    146139        $to = "Name <address@tld.com>, Another Name <another_address@different-tld.com>";
    147140        $subject = "RFC2822 Testing";
    148141        $message = "My RFC822 Test Message";
    149142
    150         unset($GLOBALS['phpmailer']->mock_sent);
    151         $_SERVER['SERVER_NAME'] = 'example.com';
    152143        wp_mail( $to, $subject, $message );
    153144
     
    158149        $this->assertEquals('another_address@different-tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][0]);
    159150        $this->assertEquals('Another Name', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][1]);
    160 
    161151        $this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);
    162         unset( $_SERVER['SERVER_NAME'] );
    163152    }
    164153
     
    168157        $message = "My RFC822 Test Message";
    169158
    170         unset($GLOBALS['phpmailer']->mock_sent);
    171         $_SERVER['SERVER_NAME'] = 'example.com';
    172159        wp_mail( $to, $subject, $message );
    173160
     
    175162        $this->assertEquals('another_address@different-tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][1][0]);
    176163        $this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);
    177         unset( $_SERVER['SERVER_NAME'] );
    178164    }
    179165
     
    182168     */
    183169    function test_wp_mail_to_address_no_name() {
    184 
    185170        $to = "<address@tld.com>";
    186171        $subject = "RFC2822 Testing";
    187172        $message = "My RFC822 Test Message";
    188173
    189         unset($GLOBALS['phpmailer']->mock_sent);
    190         $_SERVER['SERVER_NAME'] = 'example.com';
    191174        wp_mail( $to, $subject, $message );
    192175
    193176        $this->assertEquals('address@tld.com', $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]);
    194 
    195177        $this->assertEquals($message . "\n", $GLOBALS['phpmailer']->mock_sent[0]['body']);
    196         unset( $_SERVER['SERVER_NAME'] );
    197178    }
    198179
Note: See TracChangeset for help on using the changeset viewer.