diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index 4e9a06ed26..b787ed6482 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -24,7 +24,7 @@ if ( !is_readable( $config_file_path ) ) { require_once $config_file_path; require_once dirname( __FILE__ ) . '/functions.php'; -tests_reset_SERVER(); +tests_reset__SERVER(); define( 'WP_TESTS_TABLE_PREFIX', $table_prefix ); define( 'DIR_TESTDATA', dirname( __FILE__ ) . '/../data' ); diff --git a/tests/phpunit/includes/functions.php b/tests/phpunit/includes/functions.php index e3f51dbef5..370d8374ce 100644 --- a/tests/phpunit/includes/functions.php +++ b/tests/phpunit/includes/functions.php @@ -3,10 +3,11 @@ /** * Resets various `$_SERVER` variables that can get altered during tests. */ -function tests_reset_SERVER() { +function tests_reset__SERVER() { $_SERVER['HTTP_HOST'] = WP_TESTS_DOMAIN; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $_SERVER['REQUEST_METHOD'] = 'GET'; + $_SERVER['REQUEST_URI'] = ''; $_SERVER['SERVER_NAME'] = WP_TESTS_DOMAIN; $_SERVER['SERVER_PORT'] = '80'; $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; diff --git a/tests/phpunit/includes/install.php b/tests/phpunit/includes/install.php index c62b8b943b..f2c5c158d7 100644 --- a/tests/phpunit/includes/install.php +++ b/tests/phpunit/includes/install.php @@ -13,7 +13,7 @@ define( 'WP_INSTALLING', true ); require_once $config_file_path; require_once dirname( __FILE__ ) . '/functions.php'; -tests_reset_SERVER(); +tests_reset__SERVER(); $PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php'; diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index a468deb9d8..4d7f1154d6 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -101,6 +101,7 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { $this->reset_post_types(); $this->reset_taxonomies(); $this->reset_post_statuses(); + $this->reset__SERVER(); if ( $wp_rewrite->permalink_structure ) { $this->set_permalink_structure( '' ); @@ -185,6 +186,13 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { } } + /** + * Reset `$_SERVER` variables + */ + protected function reset__SERVER() { + tests_reset__SERVER(); + } + /** * Saves the action and filter-related globals so they can be restored later. * diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index d00147b051..b7a6a155c8 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -1028,8 +1028,6 @@ class Tests_Multisite_Site extends WP_UnitTestCase { $is_ssl = is_ssl(); $address = parse_url( get_blogaddress_by_id( $blog ), PHP_URL_SCHEME ); - unset( $_SERVER['HTTPS'] ); - $this->assertTrue( $is_ssl ); $this->assertSame( 'http', $address ); } diff --git a/tests/phpunit/tests/post/attachments.php b/tests/phpunit/tests/post/attachments.php index 42c6f4accd..3df4ce4348 100644 --- a/tests/phpunit/tests/post/attachments.php +++ b/tests/phpunit/tests/post/attachments.php @@ -296,15 +296,10 @@ class Tests_Post_Attachments extends WP_UnitTestCase { // Set attachment ID. $attachment_id = $this->_make_attachment( $upload ); - // Save server data for cleanup. - $is_ssl = is_ssl(); $_SERVER['HTTPS'] = 'off'; $url = wp_get_attachment_url( $attachment_id ); - // Cleanup. - $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off'; - $this->assertSame( 'http', parse_url( $url, PHP_URL_SCHEME ) ); } @@ -326,15 +321,10 @@ class Tests_Post_Attachments extends WP_UnitTestCase { // Set attachment ID. $attachment_id = $this->_make_attachment( $upload ); - // Save server data for cleanup. - $is_ssl = is_ssl(); $_SERVER['HTTPS'] = 'off'; $url = wp_get_attachment_url( $attachment_id ); - // Cleanup. - $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off'; - $this->assertSame( 'http', parse_url( $url, PHP_URL_SCHEME ) ); } @@ -356,10 +346,6 @@ class Tests_Post_Attachments extends WP_UnitTestCase { // Set attachment ID $attachment_id = $this->_make_attachment( $upload ); - // Save server data for cleanup - $is_ssl = is_ssl(); - $http_host = $_SERVER['HTTP_HOST']; - $_SERVER['HTTPS'] = 'on'; // Ensure that server host matches the host of wp_upload_dir(). @@ -369,10 +355,6 @@ class Tests_Post_Attachments extends WP_UnitTestCase { // Test that wp_get_attachemt_url returns with https scheme. $url = wp_get_attachment_url( $attachment_id ); - // Cleanup. - $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off'; - $_SERVER['HTTP_HOST'] = $http_host; - $this->assertSame( 'https', parse_url( $url, PHP_URL_SCHEME ) ); } @@ -392,10 +374,6 @@ class Tests_Post_Attachments extends WP_UnitTestCase { // Set attachment ID. $attachment_id = $this->_make_attachment( $upload ); - // Save server data for cleanup. - $is_ssl = is_ssl(); - $http_host = $_SERVER['HTTP_HOST']; - $_SERVER['HTTPS'] = 'on'; // Ensure that server host matches the host of wp_upload_dir(). @@ -405,10 +383,6 @@ class Tests_Post_Attachments extends WP_UnitTestCase { // Test that wp_get_attachemt_url returns with https scheme. $url = wp_get_attachment_url( $attachment_id ); - // Cleanup. - $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off'; - $_SERVER['HTTP_HOST'] = $http_host; - $this->assertSame( 'https', parse_url( $url, PHP_URL_SCHEME ) ); } @@ -428,14 +402,12 @@ class Tests_Post_Attachments extends WP_UnitTestCase { // Set attachment ID $attachment_id = $this->_make_attachment( $upload ); - $is_ssl = is_ssl(); $_SERVER['HTTPS'] = 'on'; set_current_screen( 'dashboard' ); $url = wp_get_attachment_url( $attachment_id ); // Cleanup. - $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off'; set_current_screen( 'front' ); $this->assertSame( set_url_scheme( $url, 'http' ), $url ); @@ -457,14 +429,12 @@ class Tests_Post_Attachments extends WP_UnitTestCase { // Set attachment ID $attachment_id = $this->_make_attachment( $upload ); - $is_ssl = is_ssl(); $_SERVER['HTTPS'] = 'on'; set_current_screen( 'dashboard' ); $url = wp_get_attachment_url( $attachment_id ); // Cleanup. - $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off'; set_current_screen( 'front' ); remove_filter( 'upload_dir', '_upload_dir_https' ); diff --git a/tests/phpunit/tests/rest-api.php b/tests/phpunit/tests/rest-api.php index f417a93de2..392fe5d4cb 100644 --- a/tests/phpunit/tests/rest-api.php +++ b/tests/phpunit/tests/rest-api.php @@ -285,10 +285,6 @@ class Tests_REST_API extends WP_UnitTestCase { * @ticket 34299 */ public function test_rest_url_scheme() { - if ( isset( $_SERVER['HTTPS'] ) ) { - $_https = $_SERVER['HTTPS']; - } - $_name = $_SERVER['SERVER_NAME']; $_SERVER['SERVER_NAME'] = parse_url( home_url(), PHP_URL_HOST ); $_siteurl = get_option( 'siteurl' ); @@ -321,12 +317,6 @@ class Tests_REST_API extends WP_UnitTestCase { $this->assertSame( 'http', parse_url( $url, PHP_URL_SCHEME ) ); // Reset - if ( isset( $_https ) ) { - $_SERVER['HTTPS'] = $_https; - } else { - unset( $_SERVER['HTTPS'] ); - } - $_SERVER['SERVER_NAME'] = $_name; update_option( 'siteurl', $_siteurl ); set_current_screen( 'front' ); diff --git a/tests/phpunit/tests/rewrite.php b/tests/phpunit/tests/rewrite.php index 92f1564e0b..12b6e4292c 100644 --- a/tests/phpunit/tests/rewrite.php +++ b/tests/phpunit/tests/rewrite.php @@ -103,9 +103,6 @@ class Tests_Rewrite extends WP_UnitTestCase { } function test_url_to_postid_set_url_scheme_http_to_https() { - // Save server data for cleanup - $is_ssl = is_ssl(); - $_SERVER['HTTPS'] = 'on'; $post_id = self::factory()->post->create(); @@ -116,9 +113,6 @@ class Tests_Rewrite extends WP_UnitTestCase { $page_permalink = get_permalink( $page_id ); $page_url_to_id = url_to_postid( set_url_scheme( $page_permalink, 'http' ) ); - // Cleanup. - $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off'; - $this->assertEquals( $post_id, $post_url_to_id ); $this->assertEquals( $page_id, $page_url_to_id ); }