From 82cb7933553628996c1dc527f05a6142dbece5ce Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 21 Oct 2015 23:51:45 +0000 Subject: [PATCH] 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 --- tests/phpunit/includes/bootstrap.php | 2 ++ tests/phpunit/includes/install.php | 3 +++ tests/phpunit/includes/testcase.php | 28 ---------------------------- tests/phpunit/tests/comment.php | 6 ------ tests/phpunit/tests/mail.php | 2 +- tests/phpunit/wp-mail-real-test.php | 1 - 6 files changed, 6 insertions(+), 36 deletions(-) diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index c65d88dec1..19aa9a446c 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -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' ) || diff --git a/tests/phpunit/includes/install.php b/tests/phpunit/includes/install.php index d05bc4443f..c94c5cb17c 100644 --- a/tests/phpunit/includes/install.php +++ b/tests/phpunit/includes/install.php @@ -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'; diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index da4d5b9143..84e7390a6d 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.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. * diff --git a/tests/phpunit/tests/comment.php b/tests/phpunit/tests/comment.php index 983c31a34b..8faa0b7fcf 100644 --- a/tests/phpunit/tests/comment.php +++ b/tests/phpunit/tests/comment.php @@ -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. */ diff --git a/tests/phpunit/tests/mail.php b/tests/phpunit/tests/mail.php index 667f9a29f8..96e510dccf 100644 --- a/tests/phpunit/tests/mail.php +++ b/tests/phpunit/tests/mail.php @@ -188,7 +188,7 @@ class Tests_Mail extends WP_UnitTestCase { $subject = "Testing"; $message = "Test Message"; $headers = "From: "; - $expected = "From: WordPress "; + $expected = "From: WordPress "; wp_mail( $to, $subject, $message, $headers ); diff --git a/tests/phpunit/wp-mail-real-test.php b/tests/phpunit/wp-mail-real-test.php index a3b4826b5a..75b7f317b7 100644 --- a/tests/phpunit/wp-mail-real-test.php +++ b/tests/phpunit/wp-mail-real-test.php @@ -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();