Make WordPress Core

Changeset 32839


Ignore:
Timestamp:
06/18/2015 01:52:29 PM (11 years ago)
Author:
boonebgorges
Message:

Make sure $_SERVER['SERVER_NAME'] is set whenever wp_mail() is called in PHPUnit tests.

This eliminates PHP notices when wp_mail() needs to determine its own From header.

See [25381] for a previous fix, which focused only on the mail-specific tests.

Fixes #32702.

Location:
trunk/tests/phpunit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase.php

    r31515 r32839  
    5454                $this->expectDeprecated();
    5555                add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
     56
     57                add_filter( 'wp_mail', array( $this, 'set_wp_mail_globals' ) );
    5658        }
    5759
     
    570572                return array_sum( $time_array );
    571573        }
     574
     575        /**
     576         * When `wp_mail()` is called, make sure `$_SERVER['SERVER_NAME']` is faked.
     577         *
     578         * @since 4.3.0
     579         *
     580         * @param array $args `wp_mail()` arguments.
     581         * @return array $args
     582         */
     583        public function set_wp_mail_globals( $args ) {
     584                if ( ! isset( $_SERVER['SERVER_NAME'] ) ) {
     585                        $_SERVER['SERVER_NAME'] = 'example.com';
     586                        add_action( 'phpmailer_init', array( $this, 'tear_down_wp_mail_globals' ) );
     587                }
     588
     589                return $args;
     590        }
     591
     592        /**
     593         * Tear down the faked `$_SERVER['SERVER_NAME']` global used in `wp_mail()`.
     594         *
     595         * @since 4.3.0
     596         */
     597        public function tear_down_wp_mail_globals() {
     598                unset( $_SERVER['SERVER_NAME'] );
     599        }
    572600}
  • trunk/tests/phpunit/tests/mail.php

    r32070 r32839  
    77        function setUp() {
    88                parent::setUp();
    9                 $_SERVER['SERVER_NAME'] = 'example.com';
    109                unset( $GLOBALS['phpmailer']->mock_sent );
    11         }
    12 
    13         function tearDown() {
    14                 unset( $_SERVER['SERVER_NAME'] );
    15                 parent::tearDown();
    1610        }
    1711
Note: See TracChangeset for help on using the changeset viewer.