Make WordPress Core

Changeset 36715


Ignore:
Timestamp:
02/25/2016 09:59:56 PM (9 years ago)
Author:
johnbillion
Message:

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

Location:
trunk/tests/phpunit/includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/bootstrap.php

    r36563 r36715  
    2323}
    2424require_once $config_file_path;
     25require_once dirname( __FILE__ ) . '/functions.php';
     26
     27tests_reset_SERVER();
    2528
    2629define( 'WP_TESTS_TABLE_PREFIX', $table_prefix );
     
    3740define( 'WP_MEMORY_LIMIT', -1 );
    3841define( 'WP_MAX_MEMORY_LIMIT', -1 );
    39 
    40 $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
    41 $_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN;
    42 $_SERVER['SERVER_NAME'] = WP_TESTS_DOMAIN;
    43 $_SERVER['REQUEST_METHOD'] = 'GET';
    44 $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
    4542
    4643$PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php';
     
    6865}
    6966unset( $multisite );
    70 
    71 require_once dirname( __FILE__ ) . '/functions.php';
    7267
    7368$GLOBALS['_wp_die_disabled'] = false;
  • trunk/tests/phpunit/includes/functions.php

    r36565 r36715  
    11<?php
     2
     3/**
     4 * Resets various `$_SERVER` variables that can get altered during tests.
     5 */
     6function tests_reset_SERVER() {
     7    $_SERVER['HTTP_HOST']       = WP_TESTS_DOMAIN;
     8    $_SERVER['REMOTE_ADDR']     = '127.0.0.1';
     9    $_SERVER['REQUEST_METHOD']  = 'GET';
     10    $_SERVER['SERVER_NAME']     = WP_TESTS_DOMAIN;
     11    $_SERVER['SERVER_PORT']     = '80';
     12    $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
     13
     14    unset( $_SERVER['HTTP_REFERER'] );
     15    unset( $_SERVER['HTTPS'] );
     16}
    217
    318// For adding hooks before loading WP
  • trunk/tests/phpunit/includes/install.php

    r36055 r36715  
    1414require_once dirname( __FILE__ ) . '/functions.php';
    1515
    16 $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
    17 $_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN;
    18 $_SERVER['SERVER_NAME'] = WP_TESTS_DOMAIN;
    19 $_SERVER['REQUEST_METHOD'] = 'GET';
    20 $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
     16tests_reset_SERVER();
    2117
    2218$PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php';
Note: See TracChangeset for help on using the changeset viewer.