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

@@ -6,27 +6,27 @@
class Tests_Meta extends WP_UnitTestCase {
protected $updated_mids = array();
function set_up() {
public function set_up() {
parent::set_up();
$this->author = new WP_User( self::factory()->user->create( array( 'role' => 'author' ) ) );
$this->meta_id = add_metadata( 'user', $this->author->ID, 'meta_key', 'meta_value' );
$this->delete_meta_id = add_metadata( 'user', $this->author->ID, 'delete_meta_key', 'delete_meta_value' );
}
function _meta_sanitize_cb( $meta_value, $meta_key, $meta_type ) {
public function meta_sanitize_cb( $meta_value, $meta_key, $meta_type ) {
return 'sanitized';
}
function test_sanitize_meta() {
public function test_sanitize_meta() {
$meta = sanitize_meta( 'some_meta', 'unsanitized', 'post' );
$this->assertSame( 'unsanitized', $meta );
register_meta( 'post', 'some_meta', array( $this, '_meta_sanitize_cb' ) );
register_meta( 'post', 'some_meta', array( $this, 'meta_sanitize_cb' ) );
$meta = sanitize_meta( 'some_meta', 'unsanitized', 'post' );
$this->assertSame( 'sanitized', $meta );
}
function test_delete_metadata_by_mid() {
public function test_delete_metadata_by_mid() {
// Let's try and delete a non-existing ID, non existing meta.
$this->assertFalse( delete_metadata_by_mid( 'user', 0 ) );
$this->assertFalse( delete_metadata_by_mid( 'non_existing_meta', $this->delete_meta_id ) );
@@ -41,7 +41,7 @@ class Tests_Meta extends WP_UnitTestCase {
$this->assertFalse( (bool) get_user_meta( $this->author->ID, 'delete_meta_key' ) );
}
function test_update_metadata_by_mid() {
public function test_update_metadata_by_mid() {
// Setup.
$meta = get_metadata_by_mid( 'user', $this->meta_id );
@@ -104,7 +104,7 @@ class Tests_Meta extends WP_UnitTestCase {
}
}
function test_metadata_exists() {
public function test_metadata_exists() {
$this->assertFalse( metadata_exists( 'user', $this->author->ID, 'foobarbaz' ) );
$this->assertTrue( metadata_exists( 'user', $this->author->ID, 'meta_key' ) );
$this->assertFalse( metadata_exists( 'user', 1234567890, 'foobarbaz' ) );
@@ -114,7 +114,7 @@ class Tests_Meta extends WP_UnitTestCase {
/**
* @ticket 22746
*/
function test_metadata_exists_with_filter() {
public function test_metadata_exists_with_filter() {
// Let's see if it returns the correct value when adding a filter.
add_filter( 'get_user_metadata', '__return_zero' );
$this->assertFalse( metadata_exists( 'user', $this->author->ID, 'meta_key' ) ); // Existing meta key.
@@ -125,7 +125,7 @@ class Tests_Meta extends WP_UnitTestCase {
/**
* @ticket 18158
*/
function test_user_metadata_not_exists() {
public function test_user_metadata_not_exists() {
$u = get_users(
array(
'meta_query' => array(
@@ -198,7 +198,7 @@ class Tests_Meta extends WP_UnitTestCase {
);
}
function test_metadata_slashes() {
public function test_metadata_slashes() {
$key = __FUNCTION__;
$value = 'Test\\singleslash';
$expected = 'Testsingleslash';
@@ -231,7 +231,7 @@ class Tests_Meta extends WP_UnitTestCase {
/**
* @ticket 16814
*/
function test_meta_type_cast() {
public function test_meta_type_cast() {
$post_id1 = self::factory()->post->create();
add_post_meta( $post_id1, 'num_as_longtext', 123 );
add_post_meta( $post_id1, 'num_as_longtext_desc', 10 );
@@ -301,7 +301,7 @@ class Tests_Meta extends WP_UnitTestCase {
$this->assertSame( 2, substr_count( $posts->request, 'CAST(' ) );
}
function test_meta_cache_order_asc() {
public function test_meta_cache_order_asc() {
$post_id = self::factory()->post->create();
$colors = array( 'red', 'blue', 'yellow', 'green' );
foreach ( $colors as $color ) {
@@ -321,7 +321,7 @@ class Tests_Meta extends WP_UnitTestCase {
/**
* @ticket 28315
*/
function test_non_numeric_object_id() {
public function test_non_numeric_object_id() {
$this->assertFalse( add_metadata( 'user', array( 1 ), 'meta_key', 'meta_value' ) );
$this->assertFalse( update_metadata( 'user', array( 1 ), 'meta_key', 'meta_new_value' ) );
$this->assertFalse( delete_metadata( 'user', array( 1 ), 'meta_key' ) );
@@ -332,7 +332,7 @@ class Tests_Meta extends WP_UnitTestCase {
/**
* @ticket 28315
*/
function test_non_numeric_meta_id() {
public function test_non_numeric_meta_id() {
$this->assertFalse( get_metadata_by_mid( 'user', array( 1 ) ) );
$this->assertFalse( update_metadata_by_mid( 'user', array( 1 ), 'meta_new_value' ) );
$this->assertFalse( delete_metadata_by_mid( 'user', array( 1 ) ) );
@@ -341,7 +341,7 @@ class Tests_Meta extends WP_UnitTestCase {
/**
* @ticket 37746
*/
function test_negative_meta_id() {
public function test_negative_meta_id() {
$negative_mid = $this->meta_id * -1;
$this->assertLessThan( 0, $negative_mid );
@@ -353,7 +353,7 @@ class Tests_Meta extends WP_UnitTestCase {
/**
* @ticket 37746
*/
function test_floating_meta_id() {
public function test_floating_meta_id() {
$floating_mid = $this->meta_id + 0.1337;
$this->assertTrue( floor( $floating_mid ) !== $floating_mid );
@@ -365,7 +365,7 @@ class Tests_Meta extends WP_UnitTestCase {
/**
* @ticket 37746
*/
function test_string_point_zero_meta_id() {
public function test_string_point_zero_meta_id() {
$meta_id = add_metadata( 'user', $this->author->ID, 'meta_key', 'meta_value_2' );
$string_mid = "{$meta_id}.0";