Skip to content

Commit

Permalink
Coding Standards: Add visibility to methods in tests/phpunit/tests/.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hellofromtonya committed Nov 4, 2021
1 parent 80380cd commit 40ac5de
Show file tree
Hide file tree
Showing 327 changed files with 3,656 additions and 3,969 deletions.
56 changes: 28 additions & 28 deletions tests/phpunit/tests/actions.php
Expand Up @@ -10,7 +10,7 @@ class Tests_Actions extends WP_UnitTestCase {
/**
* @covers ::do_action
*/
function test_simple_action() {
public function test_simple_action() {
$a = new MockAction();
$tag = __FUNCTION__;

Expand All @@ -30,7 +30,7 @@ function test_simple_action() {
/**
* @covers ::remove_action
*/
function test_remove_action() {
public function test_remove_action() {
$a = new MockAction();
$tag = __FUNCTION__;

Expand All @@ -52,7 +52,7 @@ function test_remove_action() {
/**
* @covers ::has_action
*/
function test_has_action() {
public function test_has_action() {
$tag = __FUNCTION__;
$func = __FUNCTION__ . '_func';

Expand All @@ -71,7 +71,7 @@ function test_has_action() {
*
* @covers ::do_action
*/
function test_multiple_actions() {
public function test_multiple_actions() {
$a1 = new MockAction();
$a2 = new MockAction();
$tag = __FUNCTION__;
Expand All @@ -92,7 +92,7 @@ function test_multiple_actions() {
*
* @covers ::do_action
*/
function test_action_args_1() {
public function test_action_args_1() {
$a = new MockAction();
$tag = __FUNCTION__;
$val = __FUNCTION__ . '_val';
Expand All @@ -112,7 +112,7 @@ function test_action_args_1() {
*
* @covers ::do_action
*/
function test_action_args_2() {
public function test_action_args_2() {
$a1 = new MockAction();
$a2 = new MockAction();
$tag = __FUNCTION__;
Expand Down Expand Up @@ -146,7 +146,7 @@ function test_action_args_2() {
*
* @covers ::do_action
*/
function test_action_args_3() {
public function test_action_args_3() {
$a1 = new MockAction();
$a2 = new MockAction();
$a3 = new MockAction();
Expand Down Expand Up @@ -185,7 +185,7 @@ function test_action_args_3() {
*
* @covers ::do_action
*/
function test_action_args_with_php4_syntax() {
public function test_action_args_with_php4_syntax() {
$a = new MockAction();
$tag = __FUNCTION__;
$val = new stdClass();
Expand All @@ -199,7 +199,7 @@ function test_action_args_with_php4_syntax() {
$this->assertSame( array( $val ), array_pop( $argsvar ) );
}

function test_action_priority() {
public function test_action_priority() {
$a = new MockAction();
$tag = __FUNCTION__;

Expand Down Expand Up @@ -231,7 +231,7 @@ function test_action_priority() {
/**
* @covers ::did_action
*/
function test_did_action() {
public function test_did_action() {
$tag1 = 'action1';
$tag2 = 'action2';

Expand All @@ -255,7 +255,7 @@ function test_did_action() {
/**
* @covers ::do_action
*/
function test_all_action() {
public function test_all_action() {
$a = new MockAction();
$tag1 = __FUNCTION__ . '_1';
$tag2 = __FUNCTION__ . '_2';
Expand All @@ -282,7 +282,7 @@ function test_all_action() {
/**
* @covers ::remove_action
*/
function test_remove_all_action() {
public function test_remove_all_action() {
$a = new MockAction();
$tag = __FUNCTION__;

Expand All @@ -305,7 +305,7 @@ function test_remove_all_action() {
/**
* @covers ::do_action_ref_array
*/
function test_action_ref_array() {
public function test_action_ref_array() {
$obj = new stdClass();
$a = new MockAction();
$tag = __FUNCTION__;
Expand All @@ -326,7 +326,7 @@ function test_action_ref_array() {
*
* @covers ::do_action
*/
function test_action_keyed_array() {
public function test_action_keyed_array() {
$a = new MockAction();

$tag = __FUNCTION__;
Expand All @@ -353,13 +353,13 @@ function test_action_keyed_array() {
/**
* @covers ::remove_action
*/
function test_action_self_removal() {
public function test_action_self_removal() {
add_action( 'test_action_self_removal', array( $this, 'action_self_removal' ) );
do_action( 'test_action_self_removal' );
$this->assertSame( 1, did_action( 'test_action_self_removal' ) );
}

function action_self_removal() {
public function action_self_removal() {
remove_action( 'test_action_self_removal', array( $this, 'action_self_removal' ) );
}

Expand All @@ -368,7 +368,7 @@ function action_self_removal() {
*
* @covers ::do_action
*/
function test_action_recursion() {
public function test_action_recursion() {
$tag = __FUNCTION__;
$a = new MockAction();
$b = new MockAction();
Expand All @@ -385,7 +385,7 @@ function test_action_recursion() {
/**
* @covers ::do_action
*/
function action_that_causes_recursion( $tag ) {
public function action_that_causes_recursion( $tag ) {
static $recursing = false;
if ( ! $recursing ) {
$recursing = true;
Expand All @@ -401,7 +401,7 @@ function action_that_causes_recursion( $tag ) {
* @covers ::remove_action
* @covers ::add_action
*/
function test_action_callback_manipulation_while_running() {
public function test_action_callback_manipulation_while_running() {
$tag = __FUNCTION__;
$a = new MockAction();
$b = new MockAction();
Expand All @@ -423,7 +423,7 @@ function test_action_callback_manipulation_while_running() {
$this->assertSame( 1, $e->get_call_count(), 'callback added by later priority callback should not get called' );
}

function action_that_manipulates_a_running_hook( $tag, $mocks ) {
public function action_that_manipulates_a_running_hook( $tag, $mocks ) {
remove_action( $tag, array( $mocks[1], 'action' ), 12, 2 );
add_action( $tag, array( $mocks[2], 'action' ), 12, 2 );
add_action( $tag, array( $mocks[3], 'action' ), 13, 2 );
Expand All @@ -438,7 +438,7 @@ function action_that_manipulates_a_running_hook( $tag, $mocks ) {
*
* @covers ::remove_filter
*/
function test_remove_anonymous_callback() {
public function test_remove_anonymous_callback() {
$tag = __FUNCTION__;
$a = new MockAction();
add_action( $tag, array( $a, 'action' ), 12, 1 );
Expand Down Expand Up @@ -475,7 +475,7 @@ function test_remove_anonymous_callback() {
* @covers WP_Hook::offsetSet
* @covers WP_Hook::offsetUnset
*/
function test_array_access_of_wp_filter_global() {
public function test_array_access_of_wp_filter_global() {
global $wp_filter;
$tag = __FUNCTION__;

Expand Down Expand Up @@ -503,7 +503,7 @@ function test_array_access_of_wp_filter_global() {
*
* @covers ::current_action
*/
function test_current_action() {
public function test_current_action() {
global $wp_current_filter;
$wp_current_filter[] = 'first';
$wp_current_filter[] = 'second'; // Let's say a second action was invoked.
Expand All @@ -516,7 +516,7 @@ function test_current_action() {
*
* @covers ::doing_filter
*/
function test_doing_filter() {
public function test_doing_filter() {
global $wp_current_filter;
$wp_current_filter = array(); // Set to an empty array first.

Expand All @@ -537,7 +537,7 @@ function test_doing_filter() {
*
* @covers ::doing_filter
*/
function test_doing_action() {
public function test_doing_action() {
global $wp_current_filter;
$wp_current_filter = array(); // Set to an empty array first.

Expand All @@ -558,7 +558,7 @@ function test_doing_action() {
*
* @covers ::doing_filter
*/
function test_doing_filter_real() {
public function test_doing_filter_real() {
$this->assertFalse( doing_filter() ); // No filter is passed in, and no filter is being processed.
$this->assertFalse( doing_filter( 'testing' ) ); // Filter is passed in but not being processed.

Expand All @@ -575,7 +575,7 @@ function test_doing_filter_real() {
$this->assertFalse( doing_filter( 'testing' ) ); // No longer doing this filter.
}

function apply_testing_filter() {
public function apply_testing_filter() {
$this->apply_testing_filter = true;

$this->assertTrue( doing_filter() );
Expand All @@ -596,7 +596,7 @@ function apply_testing_filter() {
$this->assertFalse( doing_filter( 'testing_nested' ) );
}

function apply_testing_nested_filter() {
public function apply_testing_nested_filter() {
$this->apply_testing_nested_filter = true;
$this->assertTrue( doing_filter() );
$this->assertTrue( doing_filter( 'testing' ) );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/actions/callbacks.php
Expand Up @@ -10,7 +10,7 @@ class Tests_Actions_Callbacks extends WP_UnitTestCase {
*
* @covers ::add_action
*/
function test_callback_representations() {
public function test_callback_representations() {
$tag = __FUNCTION__;

$this->assertFalse( has_action( $tag ) );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/actions/closures.php
Expand Up @@ -14,7 +14,7 @@ class Tests_Actions_Closures extends WP_UnitTestCase {
* @covers ::has_action
* @covers ::do_action
*/
function test_action_closure() {
public function test_action_closure() {
$tag = 'test_action_closure';
$closure = static function( $a, $b ) {
$GLOBALS[ $a ] = $b;
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/admin/includesFile.php
Expand Up @@ -11,7 +11,7 @@ class Tests_Admin_IncludesFile extends WP_UnitTestCase {
*
* @covers ::get_home_path
*/
function test_get_home_path() {
public function test_get_home_path() {
$home = get_option( 'home' );
$siteurl = get_option( 'siteurl' );
$sfn = $_SERVER['SCRIPT_FILENAME'];
Expand Down
24 changes: 12 additions & 12 deletions tests/phpunit/tests/admin/includesPlugin.php
Expand Up @@ -12,7 +12,7 @@ public static function wpTearDownAfterClass() {
self::_restore_mu_plugins();
}

function test_get_plugin_data() {
public function test_get_plugin_data() {
$data = get_plugin_data( DIR_TESTDATA . '/plugins/hello.php' );

$default_headers = array(
Expand All @@ -35,7 +35,7 @@ function test_get_plugin_data() {
}
}

function test_menu_page_url() {
public function test_menu_page_url() {
$current_user = get_current_user_id();
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
update_option( 'siteurl', 'http://example.com' );
Expand Down Expand Up @@ -77,7 +77,7 @@ function test_menu_page_url() {
*
* @dataProvider data_submenu_position
*/
function test_submenu_position( $position, $expected_position ) {
public function test_submenu_position( $position, $expected_position ) {
global $submenu;
global $menu;
$current_user = get_current_user_id();
Expand Down Expand Up @@ -125,7 +125,7 @@ function test_submenu_position( $position, $expected_position ) {
*
* @dataProvider data_submenu_position
*/
function test_submenu_helpers_position( $position, $expected_position ) {
public function test_submenu_helpers_position( $position, $expected_position ) {
global $submenu;
global $menu;

Expand Down Expand Up @@ -227,7 +227,7 @@ function test_submenu_helpers_position( $position, $expected_position ) {
* }
* }
*/
function submenus_to_add() {
private function submenus_to_add() {
return array(
array( 'Submenu Position', 'Submenu Position', 'manage_options', 'sub-page', '' ),
array( 'Submenu Position 2', 'Submenu Position 2', 'manage_options', 'sub-page2', '' ),
Expand All @@ -249,7 +249,7 @@ function submenus_to_add() {
* }
* }
*/
function data_submenu_position() {
public function data_submenu_position() {
$menu_count = count( $this->submenus_to_add() );
return array(
array( null, $menu_count ), // Insert at the end of the menu if null is passed. Default behavior.
Expand All @@ -268,7 +268,7 @@ function data_submenu_position() {
*
* @ticket 48599
*/
function test_position_when_parent_slug_child_slug_are_the_same() {
public function test_position_when_parent_slug_child_slug_are_the_same() {
global $submenu, $menu;

// Reset menus.
Expand Down Expand Up @@ -300,7 +300,7 @@ function test_position_when_parent_slug_child_slug_are_the_same() {
*
* @ticket 48599
*/
function test_passing_string_as_position_fires_doing_it_wrong() {
public function test_passing_string_as_position_fires_doing_it_wrong() {
$this->setExpectedIncorrectUsage( 'add_submenu_page' );
global $submenu, $menu;

Expand All @@ -324,27 +324,27 @@ function test_passing_string_as_position_fires_doing_it_wrong() {
$this->assertSame( 'submenu_page_1', $submenu['main_slug'][1][2] );
}

function test_is_plugin_active_true() {
public function test_is_plugin_active_true() {
activate_plugin( 'hello.php' );
$test = is_plugin_active( 'hello.php' );
$this->assertTrue( $test );

deactivate_plugins( 'hello.php' );
}

function test_is_plugin_active_false() {
public function test_is_plugin_active_false() {
deactivate_plugins( 'hello.php' );
$test = is_plugin_active( 'hello.php' );
$this->assertFalse( $test );
}

function test_is_plugin_inactive_true() {
public function test_is_plugin_inactive_true() {
deactivate_plugins( 'hello.php' );
$test = is_plugin_inactive( 'hello.php' );
$this->assertTrue( $test );
}

function test_is_plugin_inactive_false() {
public function test_is_plugin_inactive_false() {
activate_plugin( 'hello.php' );
$test = is_plugin_inactive( 'hello.php' );
$this->assertFalse( $test );
Expand Down

0 comments on commit 40ac5de

Please sign in to comment.