Make WordPress Core

Changeset 64733


Ignore:
Timestamp:
10/26/2026 05:52:43 PM (12 days ago)
Author:
lancewillett
Message:

Tests: Serve HTTP redirection tests from the local fixture server.

Copy the redirection fixture into the existing local HTTP server directory and use its URL for redirect and header checks. Retain the external fallback when the local fixture is unavailable, and clear the fixture URL during teardown.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14677

Props devmuhib, huzaifaalmesbah.
See #63914.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/http/base.php

    r64506 r64733  
    5151
    5252        /**
     53         * Local redirection fixture URL shared with instance tests after set_up_before_class().
     54         *
     55         * @var string|null
     56         */
     57        private static $redirection_fixture_url = null;
     58
     59        /**
    5360         * Skip reason when a fixture prerequisite is unavailable.
    5461         *
    … …  
    104111                        );
    105112                        return;
     113                }
     114
     115                $redirection_copied        = false;
     116                $redirection_script_source = DIR_TESTDATA . '/WPHTTP-testcase-redirection-script.php';
     117                if ( file_exists( $redirection_script_source ) ) {
     118                        $redirection_copied = copy( $redirection_script_source, $fixture_dir . '/redirection.php' );
    106119                }
    107120
    … …  
    208221                self::$file_stream_fixture_process = $process;
    209222                self::$file_stream_fixture_url     = $url;
     223                if ( $redirection_copied ) {
     224                        self::$redirection_fixture_url = 'http://127.0.0.1:' . $port . '/redirection.php';
     225                }
    210226        }
    211227
    … …  
    226242
    227243                self::$file_stream_fixture_url         = null;
     244                self::$redirection_fixture_url         = null;
    228245                self::$file_stream_fixture_skip_reason = null;
    229246                self::$file_stream_fixture_fail_reason = null;
    … …  
    274291                        $this->file_stream_url = self::$file_stream_fixture_url;
    275292                }
     293
     294                if ( self::$redirection_fixture_url ) {
     295                        $this->redirection_script = self::$redirection_fixture_url;
     296                }
    276297        }
    277298
    … …  
    437458         */
    438459        public function test_no_redirection_on_PUT() {
    439                 $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?201-location=1';
     460                $url = $this->redirection_script . '?201-location=1';
    440461
    441462                // Test 301 - POST to POST.
    … …  
    609630         */
    610631        public function test_post_redirect_to_method_300( $response_code, $method ) {
    611                 $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?post-redirect-to-method=1';
     632                $url = $this->redirection_script . '?post-redirect-to-method=1';
    612633
    613634                $res = $this->wp_remote_post( add_query_arg( 'response_code', $response_code, $url ), array( 'timeout' => 30 ) );
Note: See TracChangeset for help on using the changeset viewer.