Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardise the assertions for remote HTTP request tests #6503

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/phpunit/tests/http/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public function test_no_redirection_on_PUT() {
);

$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertSame( 'PASS', wp_remote_retrieve_body( $res ) );
$this->assertNotEmpty( $res['headers']['location'] );
}
Expand Down Expand Up @@ -356,6 +357,7 @@ public function test_post_redirect_to_method_300( $response_code, $method ) {
$res = wp_remote_post( add_query_arg( 'response_code', $response_code, $url ), array( 'timeout' => 30 ) );

$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertSame( $method, wp_remote_retrieve_body( $res ) );
}

Expand Down Expand Up @@ -406,6 +408,7 @@ public function test_ip_url_with_host_header() {
$res = wp_remote_get( $url, $args );

$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertSame( 'PASS', wp_remote_retrieve_body( $res ) );
}

Expand Down Expand Up @@ -447,6 +450,7 @@ public function test_cookie_handling() {
$res = wp_remote_get( $url );

$this->skipTestOnTimeout( $res );
$this->assertNotWPError( $res );
$this->assertSame( 'PASS', wp_remote_retrieve_body( $res ) );
}

Expand Down
17 changes: 11 additions & 6 deletions tests/phpunit/tests/http/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public function test_head_request() {
$response = wp_remote_head( $url );

$this->skipTestOnTimeout( $response );
$this->assertNotWPError( $response );

$headers = wp_remote_retrieve_headers( $response );

$this->assertIsArray( $response );

$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
$this->assertSame( 'image/png', $headers['Content-Type'] );
$this->assertSame( '153204', $headers['Content-Length'] );
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
}

/**
Expand All @@ -34,6 +34,7 @@ public function test_head_redirect() {
$response = wp_remote_head( $url );

$this->skipTestOnTimeout( $response );
$this->assertNotWPError( $response );
$this->assertSame( 301, wp_remote_retrieve_response_code( $response ) );
}

Expand All @@ -45,6 +46,7 @@ public function test_head_404() {
$response = wp_remote_head( $url );

$this->skipTestOnTimeout( $response );
$this->assertNotWPError( $response );
$this->assertSame( 404, wp_remote_retrieve_response_code( $response ) );
}

Expand All @@ -59,15 +61,14 @@ public function test_get_request() {
$response = wp_remote_get( $url );

$this->skipTestOnTimeout( $response );
$this->assertNotWPError( $response );

$headers = wp_remote_retrieve_headers( $response );

$this->assertIsArray( $response );

// Should return the same headers as a HEAD request.
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
$this->assertSame( 'image/png', $headers['Content-Type'] );
$this->assertSame( '153204', $headers['Content-Length'] );
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
}

/**
Expand All @@ -82,13 +83,14 @@ public function test_get_redirect() {
$response = wp_remote_get( $url );

$this->skipTestOnTimeout( $response );
$this->assertNotWPError( $response );

$headers = wp_remote_retrieve_headers( $response );

// Should return the same headers as a HEAD request.
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
$this->assertSame( 'image/png', $headers['Content-Type'] );
$this->assertSame( '153204', $headers['Content-Length'] );
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
}

/**
Expand Down Expand Up @@ -119,6 +121,7 @@ public function test_get_response_cookies() {
$response = wp_remote_head( $url );

$this->skipTestOnTimeout( $response );
$this->assertNotWPError( $response );

$cookies = wp_remote_retrieve_cookies( $response );

Expand Down Expand Up @@ -164,6 +167,7 @@ public function test_get_response_cookies_with_wp_http_cookie_object() {
);

$this->skipTestOnTimeout( $response );
$this->assertNotWPError( $response );

$cookies = wp_remote_retrieve_cookies( $response );

Expand Down Expand Up @@ -195,6 +199,7 @@ public function test_get_response_cookies_with_name_value_array() {
);

$this->skipTestOnTimeout( $response );
$this->assertNotWPError( $response );

$cookies = wp_remote_retrieve_cookies( $response );

Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/tests/readme.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function get_response_body( $url ) {
$response = wp_remote_get( $url );

$this->skipTestOnTimeout( $response );
$this->assertNotWPError( $response );

$response_code = wp_remote_retrieve_response_code( $response );
$response_body = wp_remote_retrieve_body( $response );
Expand Down
Loading