Coding Standards: Add visibility to methods in tests/phpunit/tests/.

Adds a `public` visibility to test fixtures, tests, data providers, and callbacks methods.

Adds a `private` visibility to helper methods within test classes.

Renames callbacks and helpers that previously started with a `_` prefix. Why? For consistency and to leverage using the method visibility. Further naming standardizations is beyond the scope of this commit.

Props costdev, jrf, hellofromTonya.
Fixes #54177.

git-svn-id: https://develop.svn.wordpress.org/trunk@52010 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Tonya Mork
2021-11-04 15:22:47 +00:00
parent 80380cd374
commit 40ac5de838
327 changed files with 3656 additions and 3969 deletions
+26 -26
View File
@@ -17,7 +17,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
protected $http_request_args;
function set_up() {
public function set_up() {
parent::set_up();
$class = 'WP_Http_' . ucfirst( $this->transport );
@@ -34,7 +34,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
}
}
function filter_http_request_args( array $args ) {
public function filter_http_request_args( array $args ) {
$this->http_request_args = $args;
return $args;
}
@@ -42,7 +42,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
/**
* @covers ::wp_remote_request
*/
function test_redirect_on_301() {
public function test_redirect_on_301() {
// 5 : 5 & 301.
$res = wp_remote_request( $this->redirection_script . '?code=301&rt=' . 5, array( 'redirection' => 5 ) );
@@ -54,7 +54,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
/**
* @covers ::wp_remote_request
*/
function test_redirect_on_302() {
public function test_redirect_on_302() {
// 5 : 5 & 302.
$res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 5 ) );
@@ -68,7 +68,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
*
* @covers ::wp_remote_request
*/
function test_redirect_on_301_no_redirect() {
public function test_redirect_on_301_no_redirect() {
// 5 > 0 & 301.
$res = wp_remote_request( $this->redirection_script . '?code=301&rt=' . 5, array( 'redirection' => 0 ) );
@@ -82,7 +82,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
*
* @covers ::wp_remote_request
*/
function test_redirect_on_302_no_redirect() {
public function test_redirect_on_302_no_redirect() {
// 5 > 0 & 302.
$res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 0 ) );
@@ -94,7 +94,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
/**
* @covers ::wp_remote_request
*/
function test_redirections_equal() {
public function test_redirections_equal() {
// 5 - 5.
$res = wp_remote_request( $this->redirection_script . '?rt=' . 5, array( 'redirection' => 5 ) );
@@ -106,7 +106,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
/**
* @covers ::wp_remote_request
*/
function test_no_head_redirections() {
public function test_no_head_redirections() {
// No redirections on HEAD request.
$res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 1, array( 'method' => 'HEAD' ) );
@@ -120,7 +120,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
*
* @covers ::wp_remote_request
*/
function test_redirect_on_head() {
public function test_redirect_on_head() {
// Redirections on HEAD request when Requested.
$res = wp_remote_request(
$this->redirection_script . '?rt=' . 5,
@@ -138,7 +138,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
/**
* @covers ::wp_remote_request
*/
function test_redirections_greater() {
public function test_redirections_greater() {
// 10 > 5.
$res = wp_remote_request( $this->redirection_script . '?rt=' . 10, array( 'redirection' => 5 ) );
@@ -149,7 +149,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
/**
* @covers ::wp_remote_request
*/
function test_redirections_greater_edgecase() {
public function test_redirections_greater_edgecase() {
// 6 > 5 (close edge case).
$res = wp_remote_request( $this->redirection_script . '?rt=' . 6, array( 'redirection' => 5 ) );
@@ -160,7 +160,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
/**
* @covers ::wp_remote_request
*/
function test_redirections_less_edgecase() {
public function test_redirections_less_edgecase() {
// 4 < 5 (close edge case).
$res = wp_remote_request( $this->redirection_script . '?rt=' . 4, array( 'redirection' => 5 ) );
@@ -173,7 +173,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
*
* @covers ::wp_remote_request
*/
function test_redirections_zero_redirections_specified() {
public function test_redirections_zero_redirections_specified() {
// 0 redirections asked for, should return the document?
$res = wp_remote_request( $this->redirection_script . '?code=302&rt=' . 5, array( 'redirection' => 0 ) );
@@ -189,7 +189,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
*
* @covers ::wp_remote_request
*/
function test_location_header_on_201() {
public function test_location_header_on_201() {
// Prints PASS on initial load, FAIL if the client follows the specified redirection.
$res = wp_remote_request( $this->redirection_script . '?201-location=true' );
@@ -206,7 +206,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
* @covers ::wp_remote_request
* @covers ::wp_remote_retrieve_body
*/
function test_no_redirection_on_PUT() {
public function test_no_redirection_on_PUT() {
$url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?201-location=1';
// Test 301 - POST to POST.
@@ -228,7 +228,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
*
* @covers ::wp_remote_request
*/
function test_send_headers() {
public function test_send_headers() {
// Test that the headers sent are received by the server.
$headers = array(
'test1' => 'test',
@@ -263,7 +263,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
/**
* @covers ::wp_remote_request
*/
function test_file_stream() {
public function test_file_stream() {
$url = $this->file_stream_url;
$size = 153204;
$res = wp_remote_request(
@@ -293,7 +293,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
*
* @covers ::wp_remote_request
*/
function test_file_stream_limited_size() {
public function test_file_stream_limited_size() {
$url = $this->file_stream_url;
$size = 10000;
$res = wp_remote_request(
@@ -324,7 +324,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
*
* @covers ::wp_remote_request
*/
function test_request_limited_size() {
public function test_request_limited_size() {
$url = $this->file_stream_url;
$size = 10000;
@@ -351,7 +351,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
* @covers ::wp_remote_post
* @covers ::wp_remote_retrieve_body
*/
function test_post_redirect_to_method_300( $response_code, $method ) {
public 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';
$res = wp_remote_post( add_query_arg( 'response_code', $response_code, $url ), array( 'timeout' => 30 ) );
@@ -393,7 +393,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
* @covers ::wp_remote_get
* @covers ::wp_remote_retrieve_body
*/
function test_ip_url_with_host_header() {
public function test_ip_url_with_host_header() {
$ip = gethostbyname( 'api.wordpress.org' );
$url = 'http://' . $ip . '/core/tests/1.0/redirection.php?print-pass=1';
$args = array(
@@ -418,7 +418,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
*
* @covers ::wp_remote_head
*/
function test_https_url_without_ssl_verification() {
public function test_https_url_without_ssl_verification() {
$url = 'https://wordpress.org/';
$args = array(
'sslverify' => false,
@@ -445,7 +445,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
* @covers ::wp_remote_get
* @covers ::wp_remote_retrieve_body
*/
function test_multiple_location_headers() {
public function test_multiple_location_headers() {
$url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?multiple-location-headers=1';
$res = wp_remote_head( $url, array( 'timeout' => 30 ) );
@@ -468,7 +468,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
* @covers ::wp_remote_get
* @covers ::wp_remote_retrieve_body
*/
function test_cookie_handling() {
public function test_cookie_handling() {
$url = 'http://api.wordpress.org/core/tests/1.0/redirection.php?cookie-test=1';
$res = wp_remote_get( $url );
@@ -485,7 +485,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
*
* @covers ::wp_remote_get
*/
function test_ssl() {
public function test_ssl() {
if ( ! wp_http_supports( array( 'ssl' ) ) ) {
$this->fail( 'This installation of PHP does not support SSL.' );
}
@@ -501,7 +501,7 @@ abstract class WP_HTTP_UnitTestCase extends WP_UnitTestCase {
*
* @covers ::wp_remote_request
*/
function test_url_with_double_slashes_path() {
public function test_url_with_double_slashes_path() {
$url = $this->redirection_script . '?rt=' . 0;
$path = parse_url( $url, PHP_URL_PATH );
+10 -10
View File
@@ -9,7 +9,7 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
/**
* @covers ::wp_remote_head
*/
function test_head_request() {
public 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';
$response = wp_remote_head( $url );
@@ -28,7 +28,7 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
/**
* @covers ::wp_remote_head
*/
function test_head_redirect() {
public function test_head_redirect() {
// This URL will 301 redirect.
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_head( $url );
@@ -40,7 +40,7 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
/**
* @covers ::wp_remote_head
*/
function test_head_404() {
public function test_head_404() {
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
$response = wp_remote_head( $url );
@@ -53,7 +53,7 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
* @covers ::wp_remote_retrieve_headers
* @covers ::wp_remote_retrieve_response_code
*/
function test_get_request() {
public function test_get_request() {
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
$response = wp_remote_get( $url );
@@ -75,7 +75,7 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
* @covers ::wp_remote_retrieve_headers
* @covers ::wp_remote_retrieve_response_code
*/
function test_get_redirect() {
public 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';
@@ -94,7 +94,7 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
/**
* @covers ::wp_remote_get
*/
function test_get_redirect_limit_exceeded() {
public 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';
@@ -113,7 +113,7 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
* @covers ::wp_remote_retrieve_cookie
* @covers ::wp_remote_retrieve_cookie_value
*/
function test_get_response_cookies() {
public function test_get_response_cookies() {
$url = 'https://login.wordpress.org/wp-login.php';
$response = wp_remote_head( $url );
@@ -146,7 +146,7 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
* @covers ::wp_remote_retrieve_cookies
* @covers ::wp_remote_retrieve_cookie
*/
function test_get_response_cookies_with_wp_http_cookie_object() {
public function test_get_response_cookies_with_wp_http_cookie_object() {
$url = 'http://example.org';
$response = wp_remote_get(
@@ -182,7 +182,7 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
* @covers ::wp_remote_retrieve_cookies
* @covers ::wp_remote_retrieve_cookie
*/
function test_get_response_cookies_with_name_value_array() {
public function test_get_response_cookies_with_name_value_array() {
$url = 'http://example.org';
$response = wp_remote_get(
@@ -214,7 +214,7 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
* @covers ::wp_remote_retrieve_cookie
* @covers WP_Http
*/
function test_get_cookie_host_only() {
public function test_get_cookie_host_only() {
// Emulate WP_Http::request() internals.
$requests_response = new Requests_Response();
+11 -11
View File
@@ -13,12 +13,12 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase {
*
* @covers WP_Http::make_absolute_url
*/
function test_make_absolute_url( $relative_url, $absolute_url, $expected ) {
public function test_make_absolute_url( $relative_url, $absolute_url, $expected ) {
$actual = WP_Http::make_absolute_url( $relative_url, $absolute_url );
$this->assertSame( $expected, $actual );
}
function make_absolute_url_testcases() {
public function make_absolute_url_testcases() {
// 0: The Location header, 1: The current URL, 3: The expected URL.
return array(
// Absolute URL provided.
@@ -74,12 +74,12 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase {
*
* @covers ::wp_parse_url
*/
function test_wp_parse_url( $url, $expected ) {
public function test_wp_parse_url( $url, $expected ) {
$actual = wp_parse_url( $url );
$this->assertSame( $expected, $actual );
}
function parse_url_testcases() {
public function parse_url_testcases() {
// 0: The URL, 1: The expected resulting structure.
return array(
array(
@@ -187,7 +187,7 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase {
*
* @covers ::wp_parse_url
*/
function test_wp_parse_url_with_default_component() {
public function test_wp_parse_url_with_default_component() {
$actual = wp_parse_url( self::FULL_TEST_URL, -1 );
$this->assertSame(
array(
@@ -211,12 +211,12 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase {
*
* @covers ::wp_parse_url
*/
function test_wp_parse_url_with_component( $url, $component, $expected ) {
public function test_wp_parse_url_with_component( $url, $component, $expected ) {
$actual = wp_parse_url( $url, $component );
$this->assertSame( $expected, $actual );
}
function parse_url_component_testcases() {
public function parse_url_component_testcases() {
// 0: The URL, 1: The requested component, 2: The expected resulting structure.
return array(
array( self::FULL_TEST_URL, PHP_URL_SCHEME, 'http' ),
@@ -328,13 +328,13 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase {
* @covers ::wp_parse_url
* @covers ::_get_component_from_parsed_url_array
*/
function test_get_component_from_parsed_url_array( $url, $component, $expected ) {
public function test_get_component_from_parsed_url_array( $url, $component, $expected ) {
$parts = wp_parse_url( $url );
$actual = _get_component_from_parsed_url_array( $parts, $component );
$this->assertSame( $expected, $actual );
}
function get_component_from_parsed_url_array_testcases() {
public function get_component_from_parsed_url_array_testcases() {
// 0: A URL, 1: PHP URL constant, 2: The expected result.
return array(
array(
@@ -369,12 +369,12 @@ class Tests_HTTP_HTTP extends WP_UnitTestCase {
*
* @covers ::_wp_translate_php_url_constant_to_key
*/
function test_wp_translate_php_url_constant_to_key( $input, $expected ) {
public function test_wp_translate_php_url_constant_to_key( $input, $expected ) {
$actual = _wp_translate_php_url_constant_to_key( $input );
$this->assertSame( $expected, $actual );
}
function wp_translate_php_url_constant_to_key_testcases() {
public function wp_translate_php_url_constant_to_key_testcases() {
// 0: PHP URL constant, 1: The expected result.
return array(
array( PHP_URL_SCHEME, 'scheme' ),
@@ -9,7 +9,7 @@ class Tests_HTTP_wpRemoteRetrieveHeaders extends WP_UnitTestCase {
/**
* Valid response
*/
function test_remote_retrieve_headers_valid_response() {
public function test_remote_retrieve_headers_valid_response() {
$headers = 'headers_data';
$response = array( 'headers' => $headers );
@@ -20,7 +20,7 @@ class Tests_HTTP_wpRemoteRetrieveHeaders extends WP_UnitTestCase {
/**
* Response is a WP_Error
*/
function test_remote_retrieve_headers_is_error() {
public function test_remote_retrieve_headers_is_error() {
$response = new WP_Error( 'Some error' );
$result = wp_remote_retrieve_headers( $response );
@@ -30,7 +30,7 @@ class Tests_HTTP_wpRemoteRetrieveHeaders extends WP_UnitTestCase {
/**
* Response does not contain 'headers'
*/
function test_remote_retrieve_headers_invalid_response() {
public function test_remote_retrieve_headers_invalid_response() {
$response = array( 'no_headers' => 'set' );
$result = wp_remote_retrieve_headers( $response );