[wp-trac] [WordPress Trac] #57306: External HTTP test failures
WordPress Trac
noreply at wordpress.org
Mon Dec 12 00:03:57 UTC 2022
#57306: External HTTP test failures
------------------------------+-----------------------------
Reporter: SergeyBiryukov | Owner: SergeyBiryukov
Type: defect (bug) | Status: accepted
Priority: normal | Milestone: 6.2
Component: Build/Test Tools | Version:
Severity: normal | Resolution:
Keywords: dev-feedback | Focuses:
------------------------------+-----------------------------
Comment (by peterwilsoncc):
Is it possible to test the method directly rather than rely on
wordpress.org?
It's pretty rough but I am thinking of something like this with the test
moved out of the external-http group.
{{{#!php
<?php
public function test_multiple_location_headers() {
// Filter the response made by WP_HTTP::handle_redirects().
add_filter(
'pre_http_request',
function( $response, $args, $url ) {
// Assert the redirect URL is correct.
$this->assertSame(
$url,
'http://api.wordpress.org/core/tests/1.0/redirection.php?multiple-
location-headers=1&redirected=two'
);
return array(
'headers' => array(),
'body' => 'PASS',
'response' => array(
'code' => 200,
'message' => 'OK',
),
'cookies' => array(),
'filename' => null,
);
},
10,
3
);
$args = array(
'timeout' => 30,
'_redirection' => 3,
'redirection' => 2,
'method' => 'GET',
);
$headers = array(
'server' => 'nginx',
'date' => 'Sun, 11 Dec 2022 23:11:22 GMT',
'content-type' => 'text/html; charset=utf-8',
'location' => array(
'http://api.wordpress.org/core/tests/1.0/redirection.php?multiple-
location-headers=1&redirected=one',
'http://api.wordpress.org/core/tests/1.0/redirection.php?multiple-
location-headers=1&redirected=two',
),
);
// Test the tests: ensure multiple locations are passed to
WP_HTTP::handle_redirects().
$this->assertIsArray( $headers['location'] );
$this->assertCount( 2, $headers['location'] );
$response = WP_HTTP::handle_redirects(
'http://api.wordpress.org/core/tests/1.0/redirection.php
?multiple-location-headers=1',
$args,
array(
'headers' => $headers,
'body' => '',
'cookies' => array (),
'filename' => NULL,
'response' => array (
'code' => 302,
'message' => 'Found',
),
)
);
$this->assertSame( 'PASS', wp_remote_retrieve_body( $response ) );
}
}}}
It would still need to be backported.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57306#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list