Make WordPress Core


Ignore:
Timestamp:
11/04/2021 03:22:47 PM (3 years ago)
Author:
hellofromTonya
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/capabilities.php

    r51568 r52010  
    5454    }
    5555
    56     function set_up() {
     56    public function set_up() {
    5757        parent::set_up();
    5858        // Keep track of users we create.
    59         $this->_flush_roles();
     59        $this->flush_roles();
    6060
    6161    }
     
    6666
    6767
    68     function _flush_roles() {
     68    private function flush_roles() {
    6969        // We want to make sure we're testing against the DB, not just in-memory data.
    7070        // This will flush everything and reload it from the DB.
     
    7474    }
    7575
    76     function _meta_yes_you_can( $can, $key, $post_id, $user_id, $cap, $caps ) {
     76    public function meta_yes_you_can( $can, $key, $post_id, $user_id, $cap, $caps ) {
    7777        return true;
    7878    }
    7979
    80     function _meta_no_you_cant( $can, $key, $post_id, $user_id, $cap, $caps ) {
     80    public function meta_no_you_cant( $can, $key, $post_id, $user_id, $cap, $caps ) {
    8181        return false;
    8282    }
    8383
    84     function _meta_filter( $meta_value, $meta_key, $meta_type ) {
     84    public function meta_filter( $meta_value, $meta_key, $meta_type ) {
    8585        return $meta_value;
    8686    }
     
    354354     * }
    355355     */
    356     function data_single_site_roles_to_check() {
     356    public function data_single_site_roles_to_check() {
    357357        return array(
    358358            array( 'anonymous' ),
     
    388388     * Test the tests.
    389389     */
    390     function test_single_and_multisite_cap_tests_match() {
     390    public function test_single_and_multisite_cap_tests_match() {
    391391        $single_primitive = array_keys( $this->_getSingleSitePrimitiveCaps() );
    392392        $multi_primitive  = array_keys( $this->_getMultiSitePrimitiveCaps() );
     
    405405     * Test the tests.
    406406     */
    407     function test_all_caps_of_users_are_being_tested() {
     407    public function test_all_caps_of_users_are_being_tested() {
    408408        $caps = $this->getPrimitiveCapsAndRoles();
    409409
     
    575575     * @dataProvider dataAllCapsAndRoles
    576576     */
    577     function test_default_caps_for_all_roles( $role, $cap ) {
     577    public function test_default_caps_for_all_roles( $role, $cap ) {
    578578        $user         = self::$users[ $role ];
    579579        $roles_by_cap = $this->getAllCapsAndRoles();
     
    593593     * @dataProvider data_single_site_roles_to_check
    594594     */
    595     function test_other_caps_for_all_roles( $role ) {
     595    public function test_other_caps_for_all_roles( $role ) {
    596596        $user   = self::$users[ $role ];
    597597        $old_id = wp_get_current_user()->ID;
     
    629629     * @dataProvider data_single_site_roles_to_check
    630630     */
    631     function test_user_exists_in_database( $role ) {
     631    public function test_user_exists_in_database( $role ) {
    632632        $user     = self::$users[ $role ];
    633633        $expected = true;
     
    698698     * Special case for the link manager.
    699699     */
    700     function test_link_manager_caps() {
     700    public function test_link_manager_caps() {
    701701        $caps = array(
    702702            'manage_links' => array( 'administrator', 'editor' ),
     
    736736     * Special case for unfiltered uploads.
    737737     */
    738     function test_unfiltered_upload_caps() {
     738    public function test_unfiltered_upload_caps() {
    739739        $this->assertFalse( defined( 'ALLOW_UNFILTERED_UPLOADS' ) );
    740740
     
    829829     * @group ms-required
    830830     */
    831     function test_super_admin_caps() {
     831    public function test_super_admin_caps() {
    832832        $caps = $this->getAllCapsAndRoles();
    833833        $user = self::$super_admin;
     
    854854     * A role that doesn't exist.
    855855     */
    856     function test_bogus_role() {
     856    public function test_bogus_role() {
    857857        $user = self::factory()->user->create_and_get( array( 'role' => 'invalid_role' ) );
    858858
     
    874874     * A user with multiple roles.
    875875     */
    876     function test_user_subscriber_contributor() {
     876    public function test_user_subscriber_contributor() {
    877877        $user = self::$users['subscriber'];
    878878
     
    906906     * Newly added empty role.
    907907     */
    908     function test_add_empty_role() {
     908    public function test_add_empty_role() {
    909909        global $wp_roles;
    910910
     
    912912        add_role( $role_name, 'Janitor', array() );
    913913
    914         $this->_flush_roles();
     914        $this->flush_roles();
    915915        $this->assertTrue( $wp_roles->is_role( $role_name ) );
    916916
     
    932932        // Clean up.
    933933        remove_role( $role_name );
    934         $this->_flush_roles();
     934        $this->flush_roles();
    935935        $this->assertFalse( $wp_roles->is_role( $role_name ) );
    936936    }
     
    939939     * Newly added role.
    940940     */
    941     function test_add_role() {
     941    public function test_add_role() {
    942942        global $wp_roles;
    943943
     
    951951        );
    952952        add_role( $role_name, 'Janitor', $expected_caps );
    953         $this->_flush_roles();
     953        $this->flush_roles();
    954954        $this->assertTrue( $wp_roles->is_role( $role_name ) );
    955955
     
    977977        // Clean up.
    978978        remove_role( $role_name );
    979         $this->_flush_roles();
     979        $this->flush_roles();
    980980        $this->assertFalse( $wp_roles->is_role( $role_name ) );
    981981    }
     
    985985     * is reflected in has_cap().
    986986     */
    987     function test_role_add_cap() {
     987    public function test_role_add_cap() {
    988988        global $wp_roles;
    989989        $role_name = 'janitor';
    990990        add_role( $role_name, 'Janitor', array( 'level_1' => true ) );
    991         $this->_flush_roles();
     991        $this->flush_roles();
    992992        $this->assertTrue( $wp_roles->is_role( $role_name ) );
    993993
     
    997997        // Now add a cap to the role.
    998998        $wp_roles->add_cap( $role_name, 'sweep_floor' );
    999         $this->_flush_roles();
     999        $this->flush_roles();
    10001000
    10011001        $user = new WP_User( $id );
     
    10181018        // Clean up.
    10191019        remove_role( $role_name );
    1020         $this->_flush_roles();
     1020        $this->flush_roles();
    10211021        $this->assertFalse( $wp_roles->is_role( $role_name ) );
    10221022
     
    10271027     * is reflected in has_cap().
    10281028     */
    1029     function test_role_remove_cap() {
     1029    public function test_role_remove_cap() {
    10301030        global $wp_roles;
    10311031        $role_name = 'janitor';
     
    10391039            )
    10401040        );
    1041         $this->_flush_roles();
     1041        $this->flush_roles();
    10421042        $this->assertTrue( $wp_roles->is_role( $role_name ) );
    10431043
     
    10471047        // Now remove a cap from the role.
    10481048        $wp_roles->remove_cap( $role_name, 'polish_doorknobs' );
    1049         $this->_flush_roles();
     1049        $this->flush_roles();
    10501050
    10511051        $user = new WP_User( $id );
     
    10631063        // Clean up.
    10641064        remove_role( $role_name );
    1065         $this->_flush_roles();
     1065        $this->flush_roles();
    10661066        $this->assertFalse( $wp_roles->is_role( $role_name ) );
    10671067
     
    10711071     * Add an extra capability to a user.
    10721072     */
    1073     function test_user_add_cap() {
     1073    public function test_user_add_cap() {
    10741074        // There are two contributors.
    10751075        $id_1 = self::$users['contributor']->ID;
     
    11101110     * Add an extra capability to a user then remove it.
    11111111     */
    1112     function test_user_remove_cap() {
     1112    public function test_user_remove_cap() {
    11131113        // There are two contributors.
    11141114        $id_1 = self::$users['contributor']->ID;
     
    11421142     * Make sure the user_level is correctly set and changed with the user's role.
    11431143     */
    1144     function test_user_level_update() {
     1144    public function test_user_level_update() {
    11451145        // User starts as an author.
    11461146        $id   = self::$users['author']->ID;
     
    11651165    }
    11661166
    1167     function test_user_remove_all_caps() {
     1167    public function test_user_remove_all_caps() {
    11681168        // User starts as an author.
    11691169        $id   = self::$users['author']->ID;
     
    12061206     * Simple tests for some common meta capabilities.
    12071207     */
    1208     function test_post_meta_caps() {
     1208    public function test_post_meta_caps() {
    12091209        // Get our author.
    12101210        $author = self::$users['author'];
     
    12811281            $this->assertFalse( $admin->has_cap( 'delete_post_meta', $post, '_protected' ) );
    12821282
    1283             register_meta( 'post', '_protected', array( $this, '_meta_filter' ), array( $this, '_meta_yes_you_can' ) );
     1283            register_meta( 'post', '_protected', array( $this, 'meta_filter' ), array( $this, 'meta_yes_you_can' ) );
    12841284            $this->assertTrue( $admin->has_cap( 'edit_post_meta', $post, '_protected' ) );
    12851285            $this->assertTrue( $admin->has_cap( 'add_post_meta', $post, '_protected' ) );
     
    12901290            $this->assertTrue( $admin->has_cap( 'delete_post_meta', $post, 'not_protected' ) );
    12911291
    1292             register_meta( 'post', 'not_protected', array( $this, '_meta_filter' ), array( $this, '_meta_no_you_cant' ) );
     1292            register_meta( 'post', 'not_protected', array( $this, 'meta_filter' ), array( $this, 'meta_no_you_cant' ) );
    12931293            $this->assertFalse( $admin->has_cap( 'edit_post_meta', $post, 'not_protected' ) );
    12941294            $this->assertFalse( $admin->has_cap( 'add_post_meta', $post, 'not_protected' ) );
     
    12971297    }
    12981298
    1299     function authorless_post_statuses() {
     1299    public function authorless_post_statuses() {
    13001300        return array( array( 'draft' ), array( 'private' ), array( 'publish' ) );
    13011301    }
     
    13051305     * @dataProvider authorless_post_statuses
    13061306     */
    1307     function test_authorless_post( $status ) {
     1307    public function test_authorless_post( $status ) {
    13081308        // Make a post without an author.
    13091309        $post = self::factory()->post->create(
     
    13351335     * @ticket 16714
    13361336     */
    1337     function test_create_posts_caps() {
     1337    public function test_create_posts_caps() {
    13381338        $admin       = self::$users['administrator'];
    13391339        $author      = self::$users['author'];
     
    14011401     * Simple tests for some common meta capabilities.
    14021402     */
    1403     function test_page_meta_caps() {
     1403    public function test_page_meta_caps() {
    14041404        // Get our author.
    14051405        $author = self::$users['author'];
     
    16051605     * @ticket 21786
    16061606     */
    1607     function test_negative_caps() {
     1607    public function test_negative_caps() {
    16081608        $author = self::$users['author'];
    16091609
     
    16201620     * @ticket 18932
    16211621     */
    1622     function test_set_role_same_role() {
     1622    public function test_set_role_same_role() {
    16231623        $user = self::$users['administrator'];
    16241624        $caps = $user->caps;
     
    16291629    }
    16301630
    1631     function test_current_user_can_for_blog() {
     1631    public function test_current_user_can_for_blog() {
    16321632        global $wpdb;
    16331633
     
    16571657     * @group ms-required
    16581658     */
    1659     function test_borked_current_user_can_for_blog() {
     1659    public function test_borked_current_user_can_for_blog() {
    16601660        $orig_blog_id = get_current_blog_id();
    16611661        $blog_id      = self::factory()->blog->create();
    16621662
    1663         $this->_nullify_current_user();
    1664 
    1665         add_action( 'switch_blog', array( $this, '_nullify_current_user_and_keep_nullifying_user' ) );
     1663        $this->nullify_current_user();
     1664
     1665        add_action( 'switch_blog', array( $this, 'nullify_current_user_and_keep_nullifying_user' ) );
    16661666
    16671667        current_user_can_for_blog( $blog_id, 'edit_posts' );
     
    16701670    }
    16711671
    1672     function _nullify_current_user() {
     1672    public function nullify_current_user() {
    16731673        // Prevents fatal errors in ::tearDown()'s and other uses of restore_current_blog().
    16741674        $function_stack = wp_debug_backtrace_summary( null, 0, false );
     
    16791679    }
    16801680
    1681     function _nullify_current_user_and_keep_nullifying_user() {
    1682         add_action( 'set_current_user', array( $this, '_nullify_current_user' ) );
     1681    public function nullify_current_user_and_keep_nullifying_user() {
     1682        add_action( 'set_current_user', array( $this, 'nullify_current_user' ) );
    16831683    }
    16841684
     
    16861686     * @ticket 28374
    16871687     */
    1688     function test_current_user_edit_caps() {
     1688    public function test_current_user_edit_caps() {
    16891689        $user = self::$users['contributor'];
    16901690        wp_set_current_user( $user->ID );
     
    17031703    }
    17041704
    1705     function test_subscriber_cant_edit_posts() {
     1705    public function test_subscriber_cant_edit_posts() {
    17061706        $user = self::$users['subscriber'];
    17071707        wp_set_current_user( $user->ID );
     
    17161716     * @group ms-required
    17171717     */
    1718     function test_multisite_administrator_can_not_edit_users() {
     1718    public function test_multisite_administrator_can_not_edit_users() {
    17191719        $user       = self::$users['administrator'];
    17201720        $other_user = self::$users['subscriber'];
     
    17251725    }
    17261726
    1727     function test_user_can_edit_self() {
     1727    public function test_user_can_edit_self() {
    17281728        foreach ( self::$users as $role => $user ) {
    17291729            wp_set_current_user( $user->ID );
     
    17861786     * @ticket 33694
    17871787     */
    1788     function test_contributor_cannot_edit_scheduled_post() {
     1788    public function test_contributor_cannot_edit_scheduled_post() {
    17891789
    17901790        // Add a contributor.
     
    18201820     * @group ms-required
    18211821     */
    1822     function test_multisite_administrator_with_manage_network_users_can_edit_users() {
     1822    public function test_multisite_administrator_with_manage_network_users_can_edit_users() {
    18231823        $user = self::$users['administrator'];
    18241824        $user->add_cap( 'manage_network_users' );
     
    18371837     * @group ms-required
    18381838     */
    1839     function test_multisite_administrator_with_manage_network_users_can_not_edit_super_admin() {
     1839    public function test_multisite_administrator_with_manage_network_users_can_not_edit_super_admin() {
    18401840        $user = self::$users['administrator'];
    18411841        $user->add_cap( 'manage_network_users' );
     
    18541854     * @expectedIncorrectUsage map_meta_cap
    18551855     */
    1856     function test_require_edit_others_posts_if_post_type_doesnt_exist() {
     1856    public function test_require_edit_others_posts_if_post_type_doesnt_exist() {
    18571857        register_post_type( 'existed' );
    18581858        $post_id = self::factory()->post->create( array( 'post_type' => 'existed' ) );
     
    18771877     * @expectedIncorrectUsage map_meta_cap
    18781878     */
    1879     function test_require_edit_others_posts_if_post_status_doesnt_exist() {
     1879    public function test_require_edit_others_posts_if_post_status_doesnt_exist() {
    18801880        register_post_status( 'existed' );
    18811881        $post_id = self::factory()->post->create( array( 'post_status' => 'existed' ) );
     
    18991899     * @ticket 17253
    19001900     */
    1901     function test_cpt_with_page_capability_type() {
     1901    public function test_cpt_with_page_capability_type() {
    19021902        register_post_type(
    19031903            'page_capability',
     
    19681968     * @ticket 35488
    19691969     */
    1970     function test_wp_logout_should_clear_current_user() {
     1970    public function test_wp_logout_should_clear_current_user() {
    19711971        $user_id = self::$users['author']->ID;
    19721972        wp_set_current_user( $user_id );
     
    21172117     * @group ms-required
    21182118     */
    2119     function test_init_user_caps_for_different_site() {
     2119    public function test_init_user_caps_for_different_site() {
    21202120        global $wpdb;
    21212121
     
    21452145     * @group ms-required
    21462146     */
    2147     function test_init_user_caps_for_different_site_by_user_switch() {
     2147    public function test_init_user_caps_for_different_site_by_user_switch() {
    21482148        global $wpdb;
    21492149
     
    21742174     * @ticket 36961
    21752175     */
    2176     function test_get_caps_data() {
     2176    public function test_get_caps_data() {
    21772177        global $wpdb;
    21782178
     
    21922192     * @ticket 36961
    21932193     */
    2194     function test_user_get_site_id_default() {
     2194    public function test_user_get_site_id_default() {
    21952195        $user = new WP_User( self::$users['subscriber']->ID );
    21962196        $this->assertSame( get_current_blog_id(), $user->get_site_id() );
     
    22002200     * @ticket 36961
    22012201     */
    2202     function test_user_get_site_id() {
     2202    public function test_user_get_site_id() {
    22032203        global $wpdb;
    22042204
     
    22162216     * @group ms-required
    22172217     */
    2218     function test_init_roles_for_different_site() {
     2218    public function test_init_roles_for_different_site() {
    22192219        global $wpdb;
    22202220
     
    22442244     * @ticket 38645
    22452245     */
    2246     function test_get_roles_data() {
     2246    public function test_get_roles_data() {
    22472247        global $wpdb;
    22482248
     
    22672267     * @ticket 38645
    22682268     */
    2269     function test_roles_get_site_id_default() {
     2269    public function test_roles_get_site_id_default() {
    22702270        $roles = new WP_Roles();
    22712271        $this->assertSame( get_current_blog_id(), $roles->get_site_id() );
     
    22752275     * @ticket 38645
    22762276     */
    2277     function test_roles_get_site_id() {
     2277    public function test_roles_get_site_id() {
    22782278        global $wpdb;
    22792279
     
    22902290     * @dataProvider data_block_caps
    22912291     */
    2292     function test_block_caps( $role, $cap, $use_post, $expected ) {
     2292    public function test_block_caps( $role, $cap, $use_post, $expected ) {
    22932293        if ( $use_post ) {
    22942294            $this->assertSame( $expected, self::$users[ $role ]->has_cap( $cap, self::$block_id ) );
     
    22982298    }
    22992299
    2300     function data_block_caps() {
     2300    public function data_block_caps() {
    23012301        $post_caps = array(
    23022302            'edit_block',
Note: See TracChangeset for help on using the changeset viewer.