Unify the initialisation of `$_SERVER` variables during test bootstrap. This abstracts the (re-)initialisation into a function that can be used inside of tests too, before assertions are performed.
See #35954 git-svn-id: https://develop.svn.wordpress.org/trunk@36715 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
fd03f6ec19
commit
6cf0caf13e
|
@ -22,6 +22,9 @@ if ( !is_readable( $config_file_path ) ) {
|
||||||
die( "ERROR: wp-tests-config.php is missing! Please use wp-tests-config-sample.php to create a config file.\n" );
|
die( "ERROR: wp-tests-config.php is missing! Please use wp-tests-config-sample.php to create a config file.\n" );
|
||||||
}
|
}
|
||||||
require_once $config_file_path;
|
require_once $config_file_path;
|
||||||
|
require_once dirname( __FILE__ ) . '/functions.php';
|
||||||
|
|
||||||
|
tests_reset_SERVER();
|
||||||
|
|
||||||
define( 'WP_TESTS_TABLE_PREFIX', $table_prefix );
|
define( 'WP_TESTS_TABLE_PREFIX', $table_prefix );
|
||||||
define( 'DIR_TESTDATA', dirname( __FILE__ ) . '/../data' );
|
define( 'DIR_TESTDATA', dirname( __FILE__ ) . '/../data' );
|
||||||
|
@ -37,12 +40,6 @@ define( 'DISABLE_WP_CRON', true );
|
||||||
define( 'WP_MEMORY_LIMIT', -1 );
|
define( 'WP_MEMORY_LIMIT', -1 );
|
||||||
define( 'WP_MAX_MEMORY_LIMIT', -1 );
|
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';
|
$PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php';
|
||||||
|
|
||||||
if ( "1" == getenv( 'WP_MULTISITE' ) ||
|
if ( "1" == getenv( 'WP_MULTISITE' ) ||
|
||||||
|
@ -68,8 +65,6 @@ if ( $multisite ) {
|
||||||
}
|
}
|
||||||
unset( $multisite );
|
unset( $multisite );
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/functions.php';
|
|
||||||
|
|
||||||
$GLOBALS['_wp_die_disabled'] = false;
|
$GLOBALS['_wp_die_disabled'] = false;
|
||||||
// Allow tests to override wp_die
|
// Allow tests to override wp_die
|
||||||
tests_add_filter( 'wp_die_handler', '_wp_die_handler_filter' );
|
tests_add_filter( 'wp_die_handler', '_wp_die_handler_filter' );
|
||||||
|
|
|
@ -1,5 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets various `$_SERVER` variables that can get altered during tests.
|
||||||
|
*/
|
||||||
|
function tests_reset_SERVER() {
|
||||||
|
$_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN;
|
||||||
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||||
|
$_SERVER['REQUEST_METHOD'] = 'GET';
|
||||||
|
$_SERVER['SERVER_NAME'] = WP_TESTS_DOMAIN;
|
||||||
|
$_SERVER['SERVER_PORT'] = '80';
|
||||||
|
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
|
||||||
|
|
||||||
|
unset( $_SERVER['HTTP_REFERER'] );
|
||||||
|
unset( $_SERVER['HTTPS'] );
|
||||||
|
}
|
||||||
|
|
||||||
// For adding hooks before loading WP
|
// For adding hooks before loading WP
|
||||||
function tests_add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
|
function tests_add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
|
||||||
global $wp_filter, $merged_filters;
|
global $wp_filter, $merged_filters;
|
||||||
|
|
|
@ -13,11 +13,7 @@ define( 'WP_INSTALLING', true );
|
||||||
require_once $config_file_path;
|
require_once $config_file_path;
|
||||||
require_once dirname( __FILE__ ) . '/functions.php';
|
require_once dirname( __FILE__ ) . '/functions.php';
|
||||||
|
|
||||||
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
|
tests_reset_SERVER();
|
||||||
$_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';
|
$PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue