Initialise $_SERVER['SERVER_NAME']
during the test bootstrap to avoid individual tests having to do it.
Fixes #34394 git-svn-id: https://develop.svn.wordpress.org/trunk@35350 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
2e1b898077
commit
82cb793355
@ -37,8 +37,10 @@ define( 'WP_MAX_MEMORY_LIMIT', -1 );
|
||||
|
||||
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
|
||||
$_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN;
|
||||
$_SERVER['SERVER_NAME'] = WP_TESTS_DOMAIN;
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
|
||||
$PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php';
|
||||
|
||||
if ( "1" == getenv( 'WP_MULTISITE' ) ||
|
||||
|
@ -15,7 +15,10 @@ require_once dirname( __FILE__ ) . '/functions.php';
|
||||
|
||||
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
|
||||
$_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN;
|
||||
$_SERVER['SERVER_NAME'] = WP_TESTS_DOMAIN;
|
||||
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
|
||||
$PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php';
|
||||
|
||||
require_once ABSPATH . '/wp-settings.php';
|
||||
|
@ -110,8 +110,6 @@ 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' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -668,32 +666,6 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase {
|
||||
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'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Multisite-agnostic way to delete a user from the database.
|
||||
*
|
||||
|
@ -379,12 +379,6 @@ class Tests_Comment extends WP_UnitTestCase {
|
||||
* @access public
|
||||
*/
|
||||
public function setup_notify_comment(){
|
||||
/**
|
||||
* Mock some server variables.
|
||||
*/
|
||||
$_SERVER['SERVER_NAME'] = 'phpunit.wordpress.dev';
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
|
||||
/**
|
||||
* Prevent flood alert from firing.
|
||||
*/
|
||||
|
@ -188,7 +188,7 @@ class Tests_Mail extends WP_UnitTestCase {
|
||||
$subject = "Testing";
|
||||
$message = "Test Message";
|
||||
$headers = "From: ";
|
||||
$expected = "From: WordPress <wordpress@example.com>";
|
||||
$expected = "From: WordPress <wordpress@" . WP_TESTS_DOMAIN . ">";
|
||||
|
||||
wp_mail( $to, $subject, $message, $headers );
|
||||
|
||||
|
@ -72,7 +72,6 @@ $message = "My RFC822 Test Message";
|
||||
$headers[] = "From: {$from}";
|
||||
$headers[] = "CC: {$cc}";
|
||||
|
||||
$_SERVER['SERVER_NAME'] = 'example.com';
|
||||
wp_mail( $to, $subject, $message, $headers );
|
||||
|
||||
$headers = array();
|
||||
|
Loading…
Reference in New Issue
Block a user