Initialise $_SERVER[ 'REMOTE_ADDR' ] during the test bootstrap so individual tests need not.

Fixes #33877
Fixes #25162


git-svn-id: https://develop.svn.wordpress.org/trunk@34172 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2015-09-15 08:04:33 +00:00
parent c95d6b3ec8
commit c29412abf9
9 changed files with 1 additions and 42 deletions

View File

@@ -38,6 +38,7 @@ define( 'WP_MAX_MEMORY_LIMIT', -1 );
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
$_SERVER['HTTP_HOST'] = 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' ) ||

View File

@@ -38,8 +38,6 @@ class Tests_Ajax_ReplytoComment extends WP_Ajax_UnitTestCase {
$post_id = $this->factory->post->create( array( 'post_status' => 'draft' ) );
$this->_draft_post = get_post( $post_id );
$_SERVER['REMOTE_ADDR'] = '';
}
public function tearDown() {

View File

@@ -77,13 +77,6 @@ class Tests_Comment extends WP_UnitTestCase {
* @ticket 14279
*/
public function test_wp_new_comment_respects_dates() {
// `wp_new_comment()` checks REMOTE_ADDR, so we fake it to avoid PHP notices.
if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
$remote_addr = $_SERVER['REMOTE_ADDR'];
} else {
$_SERVER['REMOTE_ADDR'] = '';
}
$u = $this->factory->user->create();
$post_id = $this->factory->post->create( array( 'post_author' => $u ) );
@@ -104,13 +97,6 @@ class Tests_Comment extends WP_UnitTestCase {
$this->assertEquals( $data['comment_date'], $comment->comment_date );
$this->assertEquals( $data['comment_date_gmt'], $comment->comment_date_gmt );
// Cleanup.
if ( isset( $remote_addr ) ) {
$_SERVER['REMOTE_ADDR'] = $remote_addr;
} else {
unset( $_SERVER['REMOTE_ADDR'] );
}
}
/**
@@ -238,13 +224,6 @@ class Tests_Comment extends WP_UnitTestCase {
public function test_comment_field_lengths() {
// `wp_new_comment()` checks REMOTE_ADDR, so we fake it to avoid PHP notices.
if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
$remote_addr = $_SERVER['REMOTE_ADDR'];
} else {
$_SERVER['REMOTE_ADDR'] = '';
}
$u = $this->factory->user->create();
$post_id = $this->factory->post->create( array( 'post_author' => $u ) );
@@ -264,13 +243,6 @@ class Tests_Comment extends WP_UnitTestCase {
$comment = get_comment( $id );
$this->assertEquals( strlen( $comment->comment_content ), 65535 );
// Cleanup.
if ( isset( $remote_addr ) ) {
$_SERVER['REMOTE_ADDR'] = $remote_addr;
} else {
unset( $_SERVER['REMOTE_ADDR'] );
}
}
/**

View File

@@ -14,8 +14,6 @@ class Tests_Multisite extends WP_UnitTestCase {
global $wpdb;
parent::setUp();
$this->suppress = $wpdb->suppress_errors();
$_SERVER['REMOTE_ADDR'] = '';
}
function tearDown() {

View File

@@ -15,8 +15,6 @@ class Tests_Multisite_Bootstrap extends WP_UnitTestCase {
global $wpdb;
parent::setUp();
$this->suppress = $wpdb->suppress_errors();
$_SERVER[ 'REMOTE_ADDR' ] = '';
}
function tearDown() {

View File

@@ -19,8 +19,6 @@ class Tests_Multisite_MS_Files_Rewriting extends WP_UnitTestCase {
parent::setUp();
$this->suppress = $wpdb->suppress_errors();
$_SERVER[ 'REMOTE_ADDR' ] = '';
update_site_option( 'ms_files_rewriting', 1 );
ms_upload_constants();
}

View File

@@ -16,8 +16,6 @@ class Tests_Multisite_Network extends WP_UnitTestCase {
global $wpdb;
parent::setUp();
$this->suppress = $wpdb->suppress_errors();
$_SERVER[ 'REMOTE_ADDR' ] = '';
}
function tearDown() {

View File

@@ -16,8 +16,6 @@ class Tests_Multisite_Option extends WP_UnitTestCase {
global $wpdb;
parent::setUp();
$this->suppress = $wpdb->suppress_errors();
$_SERVER['REMOTE_ADDR'] = null;
}
function tearDown() {

View File

@@ -16,8 +16,6 @@ class Tests_Multisite_User extends WP_UnitTestCase {
global $wpdb;
parent::setUp();
$this->suppress = $wpdb->suppress_errors();
$_SERVER[ 'REMOTE_ADDR' ] = '';
}
function tearDown() {