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

View File

@@ -60,13 +60,13 @@ class Tests_User extends WP_UnitTestCase {
self::$_author = get_user_by( 'ID', self::$author_id );
}
function set_up() {
public function set_up() {
parent::set_up();
$this->author = clone self::$_author;
}
function test_get_users_of_blog() {
public function test_get_users_of_blog() {
// Add one of each user role.
$nusers = array(
self::$contrib_id,
@@ -92,7 +92,7 @@ class Tests_User extends WP_UnitTestCase {
}
// Simple get/set tests for user_option functions.
function test_user_option() {
public function test_user_option() {
$key = rand_str();
$val = rand_str();
@@ -112,7 +112,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* Simple tests for usermeta functions.
*/
function test_usermeta() {
public function test_usermeta() {
$key = 'key';
$val = 'value1';
@@ -146,7 +146,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* Test usermeta functions in array mode.
*/
function test_usermeta_array() {
public function test_usermeta_array() {
// Some values to set.
$vals = array(
rand_str() => 'val-' . rand_str(),
@@ -188,7 +188,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* Test property magic functions for property get/set/isset.
*/
function test_user_properties() {
public function test_user_properties() {
$user = new WP_User( self::$author_id );
foreach ( $user->data as $key => $data ) {
@@ -247,7 +247,7 @@ class Tests_User extends WP_UnitTestCase {
* @expectedDeprecated WP_User->id
* @ticket 20043
*/
function test_user_unset_lowercase_id( $user ) {
public function test_user_unset_lowercase_id( $user ) {
$id = $user->id;
unset( $user->id );
$this->assertSame( $id, $user->id );
@@ -260,7 +260,7 @@ class Tests_User extends WP_UnitTestCase {
* @depends test_user_unset_lowercase_id
* @ticket 20043
*/
function test_user_unset_uppercase_id( $user ) {
public function test_user_unset_uppercase_id( $user ) {
$this->assertNotEmpty( $user->ID );
unset( $user->ID );
$this->assertNotEmpty( $user->ID );
@@ -269,7 +269,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* Test meta property magic functions for property get/set/isset.
*/
function test_user_meta_properties() {
public function test_user_meta_properties() {
$user = new WP_User( self::$author_id );
update_user_option( self::$author_id, 'foo', 'foo', true );
@@ -282,7 +282,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* @expectedDeprecated WP_User->id
*/
function test_id_property_back_compat() {
public function test_id_property_back_compat() {
$user = new WP_User( self::$author_id );
$this->assertTrue( isset( $user->id ) );
@@ -294,7 +294,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 19265
*/
function test_user_level_property_back_compat() {
public function test_user_level_property_back_compat() {
$roles = array(
self::$admin_id => 10,
self::$editor_id => 7,
@@ -311,7 +311,7 @@ class Tests_User extends WP_UnitTestCase {
}
}
function test_construction() {
public function test_construction() {
$user = new WP_User( self::$author_id );
$this->assertInstanceOf( 'WP_User', $user );
$this->assertSame( self::$author_id, $user->ID );
@@ -350,7 +350,7 @@ class Tests_User extends WP_UnitTestCase {
$this->assertSame( $user->user_login, $user7->user_login );
}
function test_get() {
public function test_get() {
$user = new WP_User( self::$author_id );
$this->assertSame( 'author_login', $user->get( 'user_login' ) );
$this->assertSame( 'author@email.com', $user->get( 'user_email' ) );
@@ -361,7 +361,7 @@ class Tests_User extends WP_UnitTestCase {
$this->assertSame( 'abcdefg', $user->get( 'dashed-key' ) );
}
function test_has_prop() {
public function test_has_prop() {
$user = new WP_User( self::$author_id );
$this->assertTrue( $user->has_prop( 'user_email' ) );
$this->assertTrue( $user->has_prop( 'use_ssl' ) );
@@ -371,7 +371,7 @@ class Tests_User extends WP_UnitTestCase {
$this->assertTrue( $user->has_prop( 'dashed-key' ) );
}
function test_update_user() {
public function test_update_user() {
$user = new WP_User( self::$author_id );
update_user_meta( self::$author_id, 'description', 'about me' );
@@ -429,7 +429,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 19595
*/
function test_global_userdata() {
public function test_global_userdata() {
global $userdata, $wpdb;
wp_set_current_user( self::$sub_id );
@@ -445,13 +445,13 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 19769
*/
function test_global_userdata_is_null_when_logged_out() {
public function test_global_userdata_is_null_when_logged_out() {
global $userdata;
wp_set_current_user( 0 );
$this->assertNull( $userdata );
}
function test_exists() {
public function test_exists() {
$user = new WP_User( self::$author_id );
$this->assertTrue( $user->exists() );
@@ -465,7 +465,7 @@ class Tests_User extends WP_UnitTestCase {
$this->assertFalse( $user->exists() );
}
function test_global_authordata() {
public function test_global_authordata() {
global $authordata, $id;
$old_post_id = $id;
@@ -498,7 +498,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 13317
*/
function test_get_userdata() {
public function test_get_userdata() {
$this->assertFalse( get_userdata( 0 ) );
$this->assertFalse( get_userdata( '0' ) );
$this->assertFalse( get_userdata( 'string' ) );
@@ -508,7 +508,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 23480
*/
function test_user_get_data_by_id() {
public function test_user_get_data_by_id() {
$user = WP_User::get_data_by( 'id', self::$author_id );
$this->assertInstanceOf( 'stdClass', $user );
$this->assertEquals( self::$author_id, $user->ID );
@@ -547,7 +547,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 21431
*/
function test_count_many_users_posts() {
public function test_count_many_users_posts() {
$user_id_b = self::factory()->user->create( array( 'role' => 'author' ) );
$post_id_a = self::factory()->post->create( array( 'post_author' => self::$author_id ) );
$post_id_b = self::factory()->post->create( array( 'post_author' => $user_id_b ) );
@@ -580,7 +580,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 22858
*/
function test_wp_update_user_on_nonexistent_users() {
public function test_wp_update_user_on_nonexistent_users() {
$user_id = 1;
// Find me a non-existent user ID.
while ( get_userdata( $user_id ) ) {
@@ -594,7 +594,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 28435
*/
function test_wp_update_user_should_not_change_password_when_passed_WP_User_instance() {
public function test_wp_update_user_should_not_change_password_when_passed_WP_User_instance() {
$testuserid = 1;
$user = get_userdata( $testuserid );
$pwd_before = $user->user_pass;
@@ -609,7 +609,7 @@ class Tests_User extends WP_UnitTestCase {
* @ticket 45747
* @group ms-excluded
*/
function test_wp_update_user_should_not_mark_user_as_spam_on_single_site() {
public function test_wp_update_user_should_not_mark_user_as_spam_on_single_site() {
$u = wp_update_user(
array(
'ID' => self::$contrib_id,
@@ -633,7 +633,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 28315
*/
function test_user_meta_error() {
public function test_user_meta_error() {
$id1 = wp_insert_user(
array(
'user_login' => rand_str(),
@@ -664,7 +664,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 30647
*/
function test_user_update_email_error() {
public function test_user_update_email_error() {
$id1 = wp_insert_user(
array(
'user_login' => 'blackburn',
@@ -707,22 +707,22 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 27317
* @dataProvider _illegal_user_logins_data
* @dataProvider data_illegal_user_logins
*/
function test_illegal_user_logins_single( $user_login ) {
public function test_illegal_user_logins_single( $user_login ) {
$user_data = array(
'user_login' => $user_login,
'user_email' => 'testuser@example.com',
'user_pass' => wp_generate_password(),
);
add_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) );
add_filter( 'illegal_user_logins', array( $this, 'illegal_user_logins' ) );
$response = wp_insert_user( $user_data );
$this->assertInstanceOf( 'WP_Error', $response );
$this->assertSame( 'invalid_username', $response->get_error_code() );
remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) );
remove_filter( 'illegal_user_logins', array( $this, 'illegal_user_logins' ) );
$user_id = wp_insert_user( $user_data );
$user = get_user_by( 'id', $user_id );
@@ -731,18 +731,18 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 27317
* @dataProvider _illegal_user_logins_data
* @dataProvider data_illegal_user_logins
*/
function test_illegal_user_logins_single_wp_create_user( $user_login ) {
public function test_illegal_user_logins_single_wp_create_user( $user_login ) {
$user_email = 'testuser-' . $user_login . '@example.com';
add_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) );
add_filter( 'illegal_user_logins', array( $this, 'illegal_user_logins' ) );
$response = register_new_user( $user_login, $user_email );
$this->assertInstanceOf( 'WP_Error', $response );
$this->assertSame( 'invalid_username', $response->get_error_code() );
remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) );
remove_filter( 'illegal_user_logins', array( $this, 'illegal_user_logins' ) );
$response = register_new_user( $user_login, $user_email );
$user = get_user_by( 'id', $response );
@@ -753,26 +753,26 @@ class Tests_User extends WP_UnitTestCase {
* @ticket 27317
* @group ms-required
*/
function test_illegal_user_logins_multisite() {
public function test_illegal_user_logins_multisite() {
$user_data = array(
'user_login' => 'testuser',
'user_email' => 'testuser@example.com',
);
add_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) );
add_filter( 'illegal_user_logins', array( $this, 'illegal_user_logins' ) );
$response = wpmu_validate_user_signup( $user_data['user_login'], $user_data['user_email'] );
$this->assertInstanceOf( 'WP_Error', $response['errors'] );
$this->assertSame( 'user_name', $response['errors']->get_error_code() );
remove_filter( 'illegal_user_logins', array( $this, '_illegal_user_logins' ) );
remove_filter( 'illegal_user_logins', array( $this, 'illegal_user_logins' ) );
$response = wpmu_validate_user_signup( $user_data['user_login'], $user_data['user_email'] );
$this->assertInstanceOf( 'WP_Error', $response['errors'] );
$this->assertCount( 0, $response['errors']->get_error_codes() );
}
function _illegal_user_logins_data() {
public function data_illegal_user_logins() {
$data = array(
array( 'testuser' ),
);
@@ -784,7 +784,7 @@ class Tests_User extends WP_UnitTestCase {
return $data;
}
function _illegal_user_logins() {
public function illegal_user_logins() {
return array( 'testuser' );
}
@@ -1163,7 +1163,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 32158
*/
function test_email_case() {
public function test_email_case() {
// Alter the case of the email address (which stays the same).
$userdata = array(
'ID' => self::$editor_id,
@@ -1177,7 +1177,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 32158
*/
function test_email_change() {
public function test_email_change() {
// Change the email address.
$userdata = array(
'ID' => self::$editor_id,
@@ -1200,7 +1200,7 @@ class Tests_User extends WP_UnitTestCase {
* @ticket 33654
* @ticket 36009
*/
function test_wp_new_user_notification( $notify, $admin_email_sent_expected, $user_email_sent_expected ) {
public function test_wp_new_user_notification( $notify, $admin_email_sent_expected, $user_email_sent_expected ) {
reset_phpmailer_instance();
$was_admin_email_sent = false;
@@ -1243,7 +1243,7 @@ class Tests_User extends WP_UnitTestCase {
* }
* }
*/
function data_wp_new_user_notifications() {
public function data_wp_new_user_notifications() {
return array(
array(
'',
@@ -1280,7 +1280,7 @@ class Tests_User extends WP_UnitTestCase {
* @ticket 33654
* @expectedDeprecated wp_new_user_notification
*/
function test_wp_new_user_notification_old_signature_throws_deprecated_warning_but_sends() {
public function test_wp_new_user_notification_old_signature_throws_deprecated_warning_but_sends() {
reset_phpmailer_instance();
$was_admin_email_sent = false;
@@ -1305,7 +1305,7 @@ class Tests_User extends WP_UnitTestCase {
*
* @ticket 34377
*/
function test_wp_new_user_notification_old_signature_no_password() {
public function test_wp_new_user_notification_old_signature_no_password() {
reset_phpmailer_instance();
$was_admin_email_sent = false;
@@ -1330,7 +1330,7 @@ class Tests_User extends WP_UnitTestCase {
*
* @ticket 40015
*/
function test_new_admin_email_notification_html_entities_decoded() {
public function test_new_admin_email_notification_html_entities_decoded() {
reset_phpmailer_instance();
wp_set_current_user( self::$admin_id );
@@ -1363,7 +1363,7 @@ class Tests_User extends WP_UnitTestCase {
*
* @dataProvider data_user_admin_email_confirmation_emails
*/
function test_new_admin_email_confirmation_not_sent_when_email_invalid( $email, $message ) {
public function test_new_admin_email_confirmation_not_sent_when_email_invalid( $email, $message ) {
reset_phpmailer_instance();
update_option_new_admin_email( get_option( 'admin_email' ), $email );
@@ -1383,7 +1383,7 @@ class Tests_User extends WP_UnitTestCase {
* }
* }
*/
function data_user_admin_email_confirmation_emails() {
public function data_user_admin_email_confirmation_emails() {
return array(
array(
get_option( 'admin_email' ),
@@ -1404,7 +1404,7 @@ class Tests_User extends WP_UnitTestCase {
*
* @dataProvider data_user_change_email_confirmation_emails
*/
function test_profile_email_confirmation_not_sent_invalid_email( $email, $message ) {
public function test_profile_email_confirmation_not_sent_invalid_email( $email, $message ) {
$old_current = get_current_user_id();
@@ -1447,7 +1447,7 @@ class Tests_User extends WP_UnitTestCase {
* }
* }
*/
function data_user_change_email_confirmation_emails() {
public function data_user_change_email_confirmation_emails() {
return array(
array(
'email@test.dev',
@@ -1470,7 +1470,7 @@ class Tests_User extends WP_UnitTestCase {
* @ticket 35715
* @ticket 42766
*/
function test_edit_user_blank_password() {
public function test_edit_user_blank_password() {
$_POST = array();
$_GET = array();
$_REQUEST = array();
@@ -1544,14 +1544,14 @@ class Tests_User extends WP_UnitTestCase {
/**
* Check passwords action for test_edit_user_blank_password().
*/
function action_check_passwords_blank_password( $user_login, &$pass1 ) {
public function action_check_passwords_blank_password( $user_login, &$pass1 ) {
$pass1 = '';
}
/**
* @ticket 16470
*/
function test_send_confirmation_on_profile_email() {
public function test_send_confirmation_on_profile_email() {
reset_phpmailer_instance();
$was_confirmation_email_sent = false;
@@ -1586,7 +1586,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 16470
*/
function test_remove_send_confirmation_on_profile_email() {
public function test_remove_send_confirmation_on_profile_email() {
remove_action( 'personal_options_update', 'send_confirmation_on_profile_email' );
reset_phpmailer_instance();
@@ -1626,7 +1626,7 @@ class Tests_User extends WP_UnitTestCase {
* @ticket 16470
* @ticket 40015
*/
function test_send_confirmation_on_profile_email_html_entities_decoded() {
public function test_send_confirmation_on_profile_email_html_entities_decoded() {
$user_id = self::factory()->user->create(
array(
'role' => 'subscriber',
@@ -1662,7 +1662,7 @@ class Tests_User extends WP_UnitTestCase {
/**
* @ticket 42564
*/
function test_edit_user_role_update() {
public function test_edit_user_role_update() {
$_POST = array();
$_GET = array();
$_REQUEST = array();
@@ -1705,7 +1705,7 @@ class Tests_User extends WP_UnitTestCase {
*
* @ticket 43547
*/
function test_wp_user_personal_data_exporter_no_user() {
public function test_wp_user_personal_data_exporter_no_user() {
$actual = wp_user_personal_data_exporter( 'not-a-user-email@test.com' );
$expected = array(
@@ -1722,7 +1722,7 @@ class Tests_User extends WP_UnitTestCase {
*
* @ticket 43547
*/
function test_wp_user_personal_data_exporter() {
public function test_wp_user_personal_data_exporter() {
$test_user = new WP_User( self::$contrib_id );
$actual = wp_user_personal_data_exporter( $test_user->user_email );
@@ -1742,7 +1742,7 @@ class Tests_User extends WP_UnitTestCase {
*
* @ticket 43921
*/
function test_wp_community_events_location_ip_personal_data_exporter() {
public function test_wp_community_events_location_ip_personal_data_exporter() {
$test_user = new WP_User( self::$contrib_id );
$location_data = array( 'ip' => '0.0.0.0' );
@@ -1766,7 +1766,7 @@ class Tests_User extends WP_UnitTestCase {
*
* @ticket 43921
*/
function test_wp_community_events_location_city_personal_data_exporter() {
public function test_wp_community_events_location_city_personal_data_exporter() {
$test_user = new WP_User( self::$contrib_id );
$location_data = array(
@@ -1808,7 +1808,7 @@ class Tests_User extends WP_UnitTestCase {
*
* @ticket 45889
*/
function test_wp_session_tokens_personal_data_exporter() {
public function test_wp_session_tokens_personal_data_exporter() {
$test_user = new WP_User( self::$contrib_id );
$session_tokens_data = array(
@@ -1924,7 +1924,7 @@ class Tests_User extends WP_UnitTestCase {
*
* @ticket 47509
*/
function test_filter_wp_privacy_additional_user_profile_data() {
public function test_filter_wp_privacy_additional_user_profile_data() {
$test_user = new WP_User( self::$contrib_id );
add_filter( 'wp_privacy_additional_user_profile_data', array( $this, 'export_additional_user_profile_data' ) );