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. git-svn-id: https://develop.svn.wordpress.org/trunk@32839 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
7ae03917a9
commit
9597066674
@ -53,6 +53,8 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
|
||||
$this->start_transaction();
|
||||
$this->expectDeprecated();
|
||||
add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
|
||||
|
||||
add_filter( 'wp_mail', array( $this, 'set_wp_mail_globals' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -569,4 +571,30 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
|
||||
$time_array = explode( ' ', $microtime );
|
||||
return array_sum( $time_array );
|
||||
}
|
||||
|
||||
/**
|
||||
* When `wp_mail()` is called, make sure `$_SERVER['SERVER_NAME']` is faked.
|
||||
*
|
||||
* @since 4.3.0
|
||||
*
|
||||
* @param array $args `wp_mail()` arguments.
|
||||
* @return array $args
|
||||
*/
|
||||
public function set_wp_mail_globals( $args ) {
|
||||
if ( ! isset( $_SERVER['SERVER_NAME'] ) ) {
|
||||
$_SERVER['SERVER_NAME'] = 'example.com';
|
||||
add_action( 'phpmailer_init', array( $this, 'tear_down_wp_mail_globals' ) );
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down the faked `$_SERVER['SERVER_NAME']` global used in `wp_mail()`.
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
public function tear_down_wp_mail_globals() {
|
||||
unset( $_SERVER['SERVER_NAME'] );
|
||||
}
|
||||
}
|
||||
|
@ -6,15 +6,9 @@
|
||||
class Tests_Mail extends WP_UnitTestCase {
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
$_SERVER['SERVER_NAME'] = 'example.com';
|
||||
unset( $GLOBALS['phpmailer']->mock_sent );
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
unset( $_SERVER['SERVER_NAME'] );
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
function test_wp_mail_custom_boundaries() {
|
||||
$to = 'user@example.com';
|
||||
$subject = 'Test email with custom boundaries';
|
||||
|
Loading…
Reference in New Issue
Block a user