From 4e4b4de3be05b93461d808bd775dd44d1d280168 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 15 Feb 2021 14:00:02 +0000 Subject: [PATCH] Tests: Add missing `@covers` tags for files in `phpunit/tests/http/`. Props patopaiar, jrf. See #39265. git-svn-id: https://develop.svn.wordpress.org/trunk@50344 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/http/base.php | 63 +++++++++++++++++++ tests/phpunit/tests/http/curl.php | 2 + tests/phpunit/tests/http/functions.php | 40 ++++++++++++ tests/phpunit/tests/http/getHttpHeaders.php | 1 + tests/phpunit/tests/http/http.php | 17 +++++ .../tests/http/remoteRetrieveHeaders.php | 1 + 6 files changed, 124 insertions(+) diff --git a/tests/phpunit/tests/http/base.php b/tests/phpunit/tests/http/base.php index c7cce5bad2..274a0a297d 100644 --- a/tests/phpunit/tests/http/base.php +++ b/tests/phpunit/tests/http/base.php @@ -51,6 +51,9 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { return $args; } + /** + * @covers ::wp_remote_request + */ function test_redirect_on_301() { // 5 : 5 & 301. $res = wp_remote_request( $this->redirection_script . '?code=301&rt=' . 5, array( 'redirection' => 5 ) ); @@ -60,6 +63,9 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { $this->assertSame( 200, (int) $res['response']['code'] ); } + /** + * @covers ::wp_remote_request + */ function test_redirect_on_302() { // 5 : 5 & 302. $res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 5 ) ); @@ -71,6 +77,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { /** * @ticket 16855 + * + * @covers ::wp_remote_request */ function test_redirect_on_301_no_redirect() { // 5 > 0 & 301. @@ -83,6 +91,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { /** * @ticket 16855 + * + * @covers ::wp_remote_request */ function test_redirect_on_302_no_redirect() { // 5 > 0 & 302. @@ -93,6 +103,9 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { $this->assertSame( 302, (int) $res['response']['code'] ); } + /** + * @covers ::wp_remote_request + */ function test_redirections_equal() { // 5 - 5. $res = wp_remote_request( $this->redirection_script . '?rt=' . 5, array( 'redirection' => 5 ) ); @@ -102,6 +115,9 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { $this->assertSame( 200, (int) $res['response']['code'] ); } + /** + * @covers ::wp_remote_request + */ function test_no_head_redirections() { // No redirections on HEAD request. $res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 1, array( 'method' => 'HEAD' ) ); @@ -113,6 +129,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { /** * @ticket 16855 + * + * @covers ::wp_remote_request */ function test_redirect_on_head() { // Redirections on HEAD request when Requested. @@ -129,6 +147,9 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { $this->assertSame( 200, (int) $res['response']['code'] ); } + /** + * @covers ::wp_remote_request + */ function test_redirections_greater() { // 10 > 5. $res = wp_remote_request( $this->redirection_script . '?rt=' . 10, array( 'redirection' => 5 ) ); @@ -137,6 +158,9 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { $this->assertWPError( $res ); } + /** + * @covers ::wp_remote_request + */ function test_redirections_greater_edgecase() { // 6 > 5 (close edge case). $res = wp_remote_request( $this->redirection_script . '?rt=' . 6, array( 'redirection' => 5 ) ); @@ -145,6 +169,9 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { $this->assertWPError( $res ); } + /** + * @covers ::wp_remote_request + */ function test_redirections_less_edgecase() { // 4 < 5 (close edge case). $res = wp_remote_request( $this->redirection_script . '?rt=' . 4, array( 'redirection' => 5 ) ); @@ -155,6 +182,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { /** * @ticket 16855 + * + * @covers ::wp_remote_request */ function test_redirections_zero_redirections_specified() { // 0 redirections asked for, should return the document? @@ -169,6 +198,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * Do not redirect on non 3xx status codes. * * @ticket 16889 + * + * @covers ::wp_remote_request */ function test_location_header_on_201() { // Prints PASS on initial load, FAIL if the client follows the specified redirection. @@ -183,6 +214,9 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * Test handling of PUT requests on redirects. * * @ticket 16889 + * + * @covers ::wp_remote_request + * @covers ::wp_remote_retrieve_body */ function test_no_redirection_on_PUT() { $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?201-location=1'; @@ -203,6 +237,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { /** * @ticket 11888 + * + * @covers ::wp_remote_request */ function test_send_headers() { // Test that the headers sent are received by the server. @@ -233,6 +269,9 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { // $this->assertTrue( isset( $headers['test3'] ) && '' === $headers['test3'] ); } + /** + * @covers ::wp_remote_request + */ function test_file_stream() { $url = $this->file_stream_url; $size = 153204; @@ -260,6 +299,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { /** * @ticket 26726 + * + * @covers ::wp_remote_request */ function test_file_stream_limited_size() { $url = $this->file_stream_url; @@ -289,6 +330,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * Tests limiting the response size when returning strings. * * @ticket 31172 + * + * @covers ::wp_remote_request */ function test_request_limited_size() { $url = $this->file_stream_url; @@ -313,6 +356,9 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * @dataProvider data_post_redirect_to_method_300 * * @ticket 17588 + * + * @covers ::wp_remote_post + * @covers ::wp_remote_retrieve_body */ function test_post_redirect_to_method_300( $response_code, $method ) { $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?post-redirect-to-method=1'; @@ -352,6 +398,9 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * Test HTTP Requests using an IP URL, with a HOST header specified. * * @ticket 24182 + * + * @covers ::wp_remote_get + * @covers ::wp_remote_retrieve_body */ function test_ip_url_with_host_header() { $ip = gethostbyname( 'api.wordpress.org' ); @@ -375,6 +424,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * Test HTTP requests where SSL verification is disabled but the CA bundle is still populated. * * @ticket 33978 + * + * @covers ::wp_remote_head */ function test_https_url_without_ssl_verification() { $url = 'https://wordpress.org/'; @@ -397,6 +448,11 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * Test HTTP Redirects with multiple Location headers specified. * * @ticket 16890 + * + * @covers ::wp_remote_head + * @covers ::wp_remote_retrieve_header + * @covers ::wp_remote_get + * @covers ::wp_remote_retrieve_body */ function test_multiple_location_headers() { $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?multiple-location-headers=1'; @@ -417,6 +473,9 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * Test HTTP Cookie handling. * * @ticket 21182 + * + * @covers ::wp_remote_get + * @covers ::wp_remote_retrieve_body */ function test_cookie_handling() { $url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?cookie-test=1'; @@ -432,6 +491,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { * * @group ssl * @ticket 25007 + * + * @covers ::wp_remote_get */ function test_ssl() { if ( ! wp_http_supports( array( 'ssl' ) ) ) { @@ -446,6 +507,8 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase { /** * @ticket 37733 + * + * @covers ::wp_remote_request */ function test_url_with_double_slashes_path() { $url = $this->redirection_script . '?rt=' . 0; diff --git a/tests/phpunit/tests/http/curl.php b/tests/phpunit/tests/http/curl.php index ceee347aa8..a7ea135010 100644 --- a/tests/phpunit/tests/http/curl.php +++ b/tests/phpunit/tests/http/curl.php @@ -11,6 +11,8 @@ class Tests_HTTP_curl extends WP_HTTP_UnitTestCase { /** * @ticket 39783 + * + * @covers ::wp_remote_request */ public function test_http_api_curl_stream_parameter_is_a_reference() { add_action( 'http_api_curl', array( $this, '_action_test_http_api_curl_stream_parameter_is_a_reference' ), 10, 3 ); diff --git a/tests/phpunit/tests/http/functions.php b/tests/phpunit/tests/http/functions.php index a01c032051..7e1d0e9515 100644 --- a/tests/phpunit/tests/http/functions.php +++ b/tests/phpunit/tests/http/functions.php @@ -7,6 +7,9 @@ */ class Tests_HTTP_Functions extends WP_UnitTestCase { + /** + * @covers ::wp_remote_head + */ function test_head_request() { // This URL gives a direct 200 response. $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg'; @@ -23,6 +26,9 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) ); } + /** + * @covers ::wp_remote_head + */ function test_head_redirect() { // This URL will 301 redirect. $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; @@ -32,6 +38,9 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { $this->assertSame( 301, wp_remote_retrieve_response_code( $response ) ); } + /** + * @covers ::wp_remote_head + */ function test_head_404() { $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg'; $response = wp_remote_head( $url ); @@ -40,6 +49,11 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { $this->assertSame( 404, wp_remote_retrieve_response_code( $response ) ); } + /** + * @covers ::wp_remote_get + * @covers ::wp_remote_retrieve_headers + * @covers ::wp_remote_retrieve_response_code + */ function test_get_request() { $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg'; @@ -57,6 +71,11 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) ); } + /** + * @covers ::wp_remote_get + * @covers ::wp_remote_retrieve_headers + * @covers ::wp_remote_retrieve_response_code + */ function test_get_redirect() { // This will redirect to asdftestblog1.files.wordpress.com. $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; @@ -73,6 +92,9 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) ); } + /** + * @covers ::wp_remote_get + */ function test_get_redirect_limit_exceeded() { // This will redirect to asdftestblog1.files.wordpress.com. $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; @@ -86,6 +108,11 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { /** * @ticket 33711 + * + * @covers ::wp_remote_head + * @covers ::wp_remote_retrieve_cookies + * @covers ::wp_remote_retrieve_cookie + * @covers ::wp_remote_retrieve_cookie_value */ function test_get_response_cookies() { $url = 'https://login.wordpress.org/wp-login.php'; @@ -115,6 +142,10 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { /** * @ticket 37437 + * + * @covers ::wp_remote_get + * @covers ::wp_remote_retrieve_cookies + * @covers ::wp_remote_retrieve_cookie */ function test_get_response_cookies_with_wp_http_cookie_object() { $url = 'http://example.org'; @@ -147,6 +178,10 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { /** * @ticket 37437 + * + * @covers ::wp_remote_get + * @covers ::wp_remote_retrieve_cookies + * @covers ::wp_remote_retrieve_cookie */ function test_get_response_cookies_with_name_value_array() { $url = 'http://example.org'; @@ -174,6 +209,11 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { /** * @ticket 43231 + * + * @covers WP_HTTP_Requests_Response::__construct + * @covers ::wp_remote_retrieve_cookies + * @covers ::wp_remote_retrieve_cookie + * @covers WP_Http */ function test_get_cookie_host_only() { // Emulate WP_Http::request() internals. diff --git a/tests/phpunit/tests/http/getHttpHeaders.php b/tests/phpunit/tests/http/getHttpHeaders.php index ccb6b4f545..ad8115ff15 100644 --- a/tests/phpunit/tests/http/getHttpHeaders.php +++ b/tests/phpunit/tests/http/getHttpHeaders.php @@ -2,6 +2,7 @@ /** * @group http + * @covers ::wp_get_http_headers */ class Tests_HTTP_GetHttpHeaders extends WP_UnitTestCase { diff --git a/tests/phpunit/tests/http/http.php b/tests/phpunit/tests/http/http.php index 4986f1719b..6799b12cd9 100644 --- a/tests/phpunit/tests/http/http.php +++ b/tests/phpunit/tests/http/http.php @@ -10,6 +10,8 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { /** * @dataProvider make_absolute_url_testcases + * + * @covers ::WP_Http::make_absolute_url */ function test_make_absolute_url( $relative_url, $absolute_url, $expected ) { $actual = WP_Http::make_absolute_url( $relative_url, $absolute_url ); @@ -69,6 +71,8 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { /** * @dataProvider parse_url_testcases + * + * @covers ::wp_parse_url */ function test_wp_parse_url( $url, $expected ) { $actual = wp_parse_url( $url ); @@ -180,6 +184,8 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { /** * @ticket 36356 + * + * @covers ::wp_parse_url */ function test_wp_parse_url_with_default_component() { $actual = wp_parse_url( self::FULL_TEST_URL, -1 ); @@ -202,6 +208,8 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { * @ticket 36356 * * @dataProvider parse_url_component_testcases + * + * @covers ::wp_parse_url */ function test_wp_parse_url_with_component( $url, $component, $expected ) { $actual = wp_parse_url( $url, $component ); @@ -261,6 +269,8 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { /** * @ticket 35426 + * + * @covers ::get_status_header_desc */ public function test_http_response_code_constants() { global $wp_header_to_desc; @@ -277,6 +287,8 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { /** * @ticket 37768 + * + * @covers WP_Http::normalize_cookies */ public function test_normalize_cookies_scalar_values() { $http = _wp_http_get_object(); @@ -312,6 +324,9 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { * @ticket 36356 * * @dataProvider get_component_from_parsed_url_array_testcases + * + * @covers ::wp_parse_url + * @covers ::_get_component_from_parsed_url_array */ function test_get_component_from_parsed_url_array( $url, $component, $expected ) { $parts = wp_parse_url( $url ); @@ -351,6 +366,8 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase { * @ticket 36356 * * @dataProvider wp_translate_php_url_constant_to_key_testcases + * + * @covers ::_wp_translate_php_url_constant_to_key */ function test_wp_translate_php_url_constant_to_key( $input, $expected ) { $actual = _wp_translate_php_url_constant_to_key( $input ); diff --git a/tests/phpunit/tests/http/remoteRetrieveHeaders.php b/tests/phpunit/tests/http/remoteRetrieveHeaders.php index 1d4e42f2e9..0d383131f7 100644 --- a/tests/phpunit/tests/http/remoteRetrieveHeaders.php +++ b/tests/phpunit/tests/http/remoteRetrieveHeaders.php @@ -2,6 +2,7 @@ /** * @group http + * @covers ::wp_remote_retrieve_headers */ class Tests_HTTP_RemoteRetrieveHeaders extends WP_UnitTestCase {