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/multisite/site.php

    r51587 r52010  
    1818        protected static $uninitialized_site_id;
    1919
    20         function set_up() {
     20        public function set_up() {
    2121            global $wpdb;
    2222            parent::set_up();
     
    2424        }
    2525
    26         function tear_down() {
     26        public function tear_down() {
    2727            global $wpdb;
    2828            $wpdb->suppress_errors( $this->suppress );
     
    8989        }
    9090
    91         function test_switch_restore_blog() {
     91        public function test_switch_restore_blog() {
    9292            global $_wp_switched_stack, $wpdb;
    9393
     
    137137         * Test the cache keys and database tables setup through the creation of a site.
    138138         */
    139         function test_created_site_details() {
     139        public function test_created_site_details() {
    140140            global $wpdb;
    141141
     
    222222         * When a site is flagged as 'deleted', its data should be cleared from cache.
    223223         */
    224         function test_data_in_cache_after_wpmu_delete_blog_drop_false() {
     224        public function test_data_in_cache_after_wpmu_delete_blog_drop_false() {
    225225            $blog_id = self::factory()->blog->create();
    226226
     
    240240         * When a site is flagged as 'deleted', its data should remain in the database.
    241241         */
    242         function test_data_in_tables_after_wpmu_delete_blog_drop_false() {
     242        public function test_data_in_tables_after_wpmu_delete_blog_drop_false() {
    243243            global $wpdb;
    244244
     
    263263         * When a site is fully deleted, its data should be cleared from cache.
    264264         */
    265         function test_data_in_cache_after_wpmu_delete_blog_drop_true() {
     265        public function test_data_in_cache_after_wpmu_delete_blog_drop_true() {
    266266            $blog_id = self::factory()->blog->create();
    267267
     
    281281         * When a site is fully deleted, its data should be removed from the database.
    282282         */
    283         function test_data_in_tables_after_wpmu_delete_blog_drop_true() {
     283        public function test_data_in_tables_after_wpmu_delete_blog_drop_true() {
    284284            global $wpdb;
    285285
     
    304304         * When the main site of a network is fully deleted, its data should be cleared from cache.
    305305         */
    306         function test_data_in_cache_after_wpmu_delete_blog_main_site_drop_true() {
     306        public function test_data_in_cache_after_wpmu_delete_blog_main_site_drop_true() {
    307307            $blog_id = 1; // The main site in our test suite has an ID of 1.
    308308
     
    322322         * When the main site of a network is fully deleted, its data should remain in the database.
    323323         */
    324         function test_data_in_tables_after_wpmu_delete_blog_main_site_drop_true() {
     324        public function test_data_in_tables_after_wpmu_delete_blog_main_site_drop_true() {
    325325            global $wpdb;
    326326
     
    345345         * The site count of a network should change when a site is flagged as 'deleted'.
    346346         */
    347         function test_network_count_after_wpmu_delete_blog_drop_false() {
     347        public function test_network_count_after_wpmu_delete_blog_drop_false() {
    348348            $blog_id = self::factory()->blog->create();
    349349
     
    359359         * The site count of a network should change when a site is fully deleted.
    360360         */
    361         function test_blog_count_after_wpmu_delete_blog_drop_true() {
     361        public function test_blog_count_after_wpmu_delete_blog_drop_true() {
    362362            $blog_id = self::factory()->blog->create();
    363363
     
    375375         * should change with upload directories.
    376376         */
    377         function test_upload_directories_after_multiple_wpmu_delete_blog() {
     377        public function test_upload_directories_after_multiple_wpmu_delete_blog() {
    378378            $filename = __FUNCTION__ . '.jpg';
    379379            $contents = __FUNCTION__ . '_contents';
     
    401401        }
    402402
    403         function test_wpmu_update_blogs_date() {
     403        public function test_wpmu_update_blogs_date() {
    404404            global $wpdb;
    405405
     
    416416         * Provide a counter to determine that hooks are firing when intended.
    417417         */
    418         function _action_counter_cb() {
     418        public function action_counter_cb() {
    419419            global $test_action_counter;
    420420            $test_action_counter++;
     
    426426         * @ticket 23405
    427427         */
    428         function test_get_blog_details_when_site_does_not_exist() {
     428        public function test_get_blog_details_when_site_does_not_exist() {
    429429            // Create an unused site so that we can then assume an invalid site ID.
    430430            $blog_id = self::factory()->blog->create();
     
    452452         * Updating a field returns the sme value that was passed.
    453453         */
    454         function test_update_blog_status() {
     454        public function test_update_blog_status() {
    455455            $result = update_blog_status( 1, 'spam', 0 );
    456456            $this->assertSame( 0, $result );
     
    460460         * Updating an invalid field returns the same value that was passed.
    461461         */
    462         function test_update_blog_status_invalid_status() {
     462        public function test_update_blog_status_invalid_status() {
    463463            $result = update_blog_status( 1, 'doesnotexist', 'invalid' );
    464464            $this->assertSame( 'invalid', $result );
    465465        }
    466466
    467         function test_update_blog_status_make_ham_blog_action() {
     467        public function test_update_blog_status_make_ham_blog_action() {
    468468            global $test_action_counter;
    469469            $test_action_counter = 0;
     
    472472            update_blog_details( $blog_id, array( 'spam' => 1 ) );
    473473
    474             add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 );
     474            add_action( 'make_ham_blog', array( $this, 'action_counter_cb' ), 10 );
    475475            update_blog_status( $blog_id, 'spam', 0 );
    476476            $blog = get_site( $blog_id );
     
    486486            $this->assertSame( 1, $test_action_counter );
    487487
    488             remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 );
    489         }
    490 
    491         function test_content_from_spam_blog_is_not_available() {
     488            remove_action( 'make_ham_blog', array( $this, 'action_counter_cb' ), 10 );
     489        }
     490
     491        public function test_content_from_spam_blog_is_not_available() {
    492492            $spam_blog_id = self::factory()->blog->create();
    493493            switch_to_blog( $spam_blog_id );
     
    519519        }
    520520
    521         function test_update_blog_status_make_spam_blog_action() {
     521        public function test_update_blog_status_make_spam_blog_action() {
    522522            global $test_action_counter;
    523523            $test_action_counter = 0;
     
    525525            $blog_id = self::factory()->blog->create();
    526526
    527             add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 );
     527            add_action( 'make_spam_blog', array( $this, 'action_counter_cb' ), 10 );
    528528            update_blog_status( $blog_id, 'spam', 1 );
    529529            $blog = get_site( $blog_id );
     
    539539            $this->assertSame( 1, $test_action_counter );
    540540
    541             remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 );
    542         }
    543 
    544         function test_update_blog_status_archive_blog_action() {
     541            remove_action( 'make_spam_blog', array( $this, 'action_counter_cb' ), 10 );
     542        }
     543
     544        public function test_update_blog_status_archive_blog_action() {
    545545            global $test_action_counter;
    546546            $test_action_counter = 0;
     
    548548            $blog_id = self::factory()->blog->create();
    549549
    550             add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 );
     550            add_action( 'archive_blog', array( $this, 'action_counter_cb' ), 10 );
    551551            update_blog_status( $blog_id, 'archived', 1 );
    552552            $blog = get_site( $blog_id );
     
    562562            $this->assertSame( 1, $test_action_counter );
    563563
    564             remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 );
    565         }
    566 
    567         function test_update_blog_status_unarchive_blog_action() {
     564            remove_action( 'archive_blog', array( $this, 'action_counter_cb' ), 10 );
     565        }
     566
     567        public function test_update_blog_status_unarchive_blog_action() {
    568568            global $test_action_counter;
    569569            $test_action_counter = 0;
     
    572572            update_blog_details( $blog_id, array( 'archived' => 1 ) );
    573573
    574             add_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 );
     574            add_action( 'unarchive_blog', array( $this, 'action_counter_cb' ), 10 );
    575575            update_blog_status( $blog_id, 'archived', 0 );
    576576            $blog = get_site( $blog_id );
     
    585585            $this->assertSame( 1, $test_action_counter );
    586586
    587             remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 );
    588         }
    589 
    590         function test_update_blog_status_make_delete_blog_action() {
     587            remove_action( 'unarchive_blog', array( $this, 'action_counter_cb' ), 10 );
     588        }
     589
     590        public function test_update_blog_status_make_delete_blog_action() {
    591591            global $test_action_counter;
    592592            $test_action_counter = 0;
     
    594594            $blog_id = self::factory()->blog->create();
    595595
    596             add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 );
     596            add_action( 'make_delete_blog', array( $this, 'action_counter_cb' ), 10 );
    597597            update_blog_status( $blog_id, 'deleted', 1 );
    598598            $blog = get_site( $blog_id );
     
    608608            $this->assertSame( 1, $test_action_counter );
    609609
    610             remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 );
    611         }
    612 
    613         function test_update_blog_status_make_undelete_blog_action() {
     610            remove_action( 'make_delete_blog', array( $this, 'action_counter_cb' ), 10 );
     611        }
     612
     613        public function test_update_blog_status_make_undelete_blog_action() {
    614614            global $test_action_counter;
    615615            $test_action_counter = 0;
     
    618618            update_blog_details( $blog_id, array( 'deleted' => 1 ) );
    619619
    620             add_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 );
     620            add_action( 'make_undelete_blog', array( $this, 'action_counter_cb' ), 10 );
    621621            update_blog_status( $blog_id, 'deleted', 0 );
    622622            $blog = get_site( $blog_id );
     
    632632            $this->assertSame( 1, $test_action_counter );
    633633
    634             remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 );
    635         }
    636 
    637         function test_update_blog_status_mature_blog_action() {
     634            remove_action( 'make_undelete_blog', array( $this, 'action_counter_cb' ), 10 );
     635        }
     636
     637        public function test_update_blog_status_mature_blog_action() {
    638638            global $test_action_counter;
    639639            $test_action_counter = 0;
     
    641641            $blog_id = self::factory()->blog->create();
    642642
    643             add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 );
     643            add_action( 'mature_blog', array( $this, 'action_counter_cb' ), 10 );
    644644            update_blog_status( $blog_id, 'mature', 1 );
    645645            $blog = get_site( $blog_id );
     
    655655            $this->assertSame( 1, $test_action_counter );
    656656
    657             remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 );
    658         }
    659 
    660         function test_update_blog_status_unmature_blog_action() {
     657            remove_action( 'mature_blog', array( $this, 'action_counter_cb' ), 10 );
     658        }
     659
     660        public function test_update_blog_status_unmature_blog_action() {
    661661            global $test_action_counter;
    662662            $test_action_counter = 0;
     
    665665            update_blog_details( $blog_id, array( 'mature' => 1 ) );
    666666
    667             add_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 );
     667            add_action( 'unmature_blog', array( $this, 'action_counter_cb' ), 10 );
    668668            update_blog_status( $blog_id, 'mature', 0 );
    669669
     
    679679            $this->assertSame( 1, $test_action_counter );
    680680
    681             remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 );
    682         }
    683 
    684         function test_update_blog_status_update_blog_public_action() {
     681            remove_action( 'unmature_blog', array( $this, 'action_counter_cb' ), 10 );
     682        }
     683
     684        public function test_update_blog_status_update_blog_public_action() {
    685685            global $test_action_counter;
    686686            $test_action_counter = 0;
     
    688688            $blog_id = self::factory()->blog->create();
    689689
    690             add_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10 );
     690            add_action( 'update_blog_public', array( $this, 'action_counter_cb' ), 10 );
    691691            update_blog_status( $blog_id, 'public', 0 );
    692692
     
    702702            $this->assertSame( 1, $test_action_counter );
    703703
    704             remove_action( 'update_blog_public', array( $this, '_action_counter_cb' ), 10 );
     704            remove_action( 'update_blog_public', array( $this, 'action_counter_cb' ), 10 );
    705705        }
    706706
     
    708708         * @ticket 27952
    709709         */
    710         function test_posts_count() {
     710        public function test_posts_count() {
    711711            self::factory()->post->create();
    712712            $post2 = self::factory()->post->create();
     
    720720         * @ticket 26410
    721721         */
    722         function test_blog_details_cache_invalidation() {
     722        public function test_blog_details_cache_invalidation() {
    723723            update_option( 'blogname', 'foo' );
    724724            $details = get_site( get_current_blog_id() );
     
    734734         * the blog ID is requested through get_blog_id_from_url().
    735735         */
    736         function test_get_blog_id_from_url() {
     736        public function test_get_blog_id_from_url() {
    737737            $blog_id = self::factory()->blog->create();
    738738            $details = get_site( $blog_id );
     
    747747         * Test the case insensitivity of the site lookup.
    748748         */
    749         function test_get_blog_id_from_url_is_case_insensitive() {
     749        public function test_get_blog_id_from_url_is_case_insensitive() {
    750750            $blog_id = self::factory()->blog->create(
    751751                array(
     
    762762         * Test the first and cached responses for a site that does not exist.
    763763         */
    764         function test_get_blog_id_from_url_that_does_not_exist() {
     764        public function test_get_blog_id_from_url_that_does_not_exist() {
    765765            $blog_id = self::factory()->blog->create( array( 'path' => '/xyz' ) );
    766766            $details = get_site( $blog_id );
     
    774774         * behavior would be expected if passing `false` explicitly to `wpmu_delete_blog()`.
    775775         */
    776         function test_get_blog_id_from_url_with_deleted_flag() {
     776        public function test_get_blog_id_from_url_with_deleted_flag() {
    777777            $blog_id = self::factory()->blog->create();
    778778            $details = get_site( $blog_id );
     
    788788         * -1 after an attempt at `get_blog_id_from_url()` is made.
    789789         */
    790         function test_get_blog_id_from_url_after_dropped() {
     790        public function test_get_blog_id_from_url_after_dropped() {
    791791            $blog_id = self::factory()->blog->create();
    792792            $details = get_site( $blog_id );
     
    802802         * Test with default parameter of site_id as null.
    803803         */
    804         function test_is_main_site() {
     804        public function test_is_main_site() {
    805805            $this->assertTrue( is_main_site() );
    806806        }
     
    810810         * default parameter tested above.
    811811         */
    812         function test_current_blog_id_is_main_site() {
     812        public function test_current_blog_id_is_main_site() {
    813813            $this->assertTrue( is_main_site( get_current_blog_id() ) );
    814814        }
     
    817817         * Test with a site ID other than the main site to ensure a false response.
    818818         */
    819         function test_is_main_site_is_false_with_other_blog_id() {
     819        public function test_is_main_site_is_false_with_other_blog_id() {
    820820            $blog_id = self::factory()->blog->create();
    821821
     
    826826         * Test with no passed ID after switching to another site ID.
    827827         */
    828         function test_is_main_site_is_false_after_switch_to_blog() {
     828        public function test_is_main_site_is_false_after_switch_to_blog() {
    829829            $blog_id = self::factory()->blog->create();
    830830            switch_to_blog( $blog_id );
     
    835835        }
    836836
    837         function test_switch_upload_dir() {
     837        public function test_switch_upload_dir() {
    838838            $this->assertTrue( is_main_site() );
    839839
     
    868868         * another site on the network.
    869869         */
    870         function test_get_blog_post_from_another_site_on_network() {
     870        public function test_get_blog_post_from_another_site_on_network() {
    871871            $blog_id = self::factory()->blog->create();
    872872            $post_id = self::factory()->post->create(); // Create a post on the primary site, ID 1.
     
    883883         * If get_blog_post() is used on the same site, it should still work.
    884884         */
    885         function test_get_blog_post_from_same_site() {
     885        public function test_get_blog_post_from_same_site() {
    886886            $post_id = self::factory()->post->create();
    887887
     
    892892         * A null response should be returned if an invalid post is requested.
    893893         */
    894         function test_get_blog_post_invalid_returns_null() {
     894        public function test_get_blog_post_invalid_returns_null() {
    895895            $this->assertNull( get_blog_post( 1, 999999 ) );
    896896        }
     
    900900         * the testing of the filter and for a test which does not need the database.
    901901         */
    902         function _domain_exists_cb( $exists, $domain, $path, $site_id ) {
     902        public function domain_exists_cb( $exists, $domain, $path, $site_id ) {
    903903            if ( 'foo' === $domain && 'bar/' === $path ) {
    904904                return 1234;
     
    908908        }
    909909
    910         function test_domain_exists_with_default_site_id() {
     910        public function test_domain_exists_with_default_site_id() {
    911911            $details = get_site( 1 );
    912912
     
    914914        }
    915915
    916         function test_domain_exists_with_specified_site_id() {
     916        public function test_domain_exists_with_specified_site_id() {
    917917            $details = get_site( 1 );
    918918
     
    924924         * it is marked as not existing.
    925925         */
    926         function test_domain_does_not_exist_with_invalid_site_id() {
     926        public function test_domain_does_not_exist_with_invalid_site_id() {
    927927            $details = get_site( 1 );
    928928
     
    930930        }
    931931
    932         function test_invalid_domain_does_not_exist_with_default_site_id() {
     932        public function test_invalid_domain_does_not_exist_with_default_site_id() {
    933933            $this->assertNull( domain_exists( 'foo', 'bar' ) );
    934934        }
    935935
    936         function test_domain_filtered_to_exist() {
    937             add_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
     936        public function test_domain_filtered_to_exist() {
     937            add_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
    938938            $exists = domain_exists( 'foo', 'bar' );
    939             remove_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
     939            remove_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
    940940            $this->assertSame( 1234, $exists );
    941941        }
     
    945945         * value with or without the slash should result in the same return value.
    946946         */
    947         function test_slashed_path_in_domain_exists() {
    948             add_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
     947        public function test_slashed_path_in_domain_exists() {
     948            add_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
    949949            $exists1 = domain_exists( 'foo', 'bar' );
    950950            $exists2 = domain_exists( 'foo', 'bar/' );
    951             remove_filter( 'domain_exists', array( $this, '_domain_exists_cb' ), 10, 4 );
     951            remove_filter( 'domain_exists', array( $this, 'domain_exists_cb' ), 10, 4 );
    952952
    953953            // Make sure the same result is returned with or without a trailing slash.
     
    958958         * Tests returning an address for a given valid ID.
    959959         */
    960         function test_get_blogaddress_by_id_with_valid_id() {
     960        public function test_get_blogaddress_by_id_with_valid_id() {
    961961            $blogaddress = get_blogaddress_by_id( 1 );
    962962            $this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/', $blogaddress );
     
    966966         * Tests returning the appropriate response for a invalid id given.
    967967         */
    968         function test_get_blogaddress_by_id_with_invalid_id() {
     968        public function test_get_blogaddress_by_id_with_invalid_id() {
    969969            $blogaddress = get_blogaddress_by_id( 42 );
    970970            $this->assertSame( '', $blogaddress );
     
    974974         * @ticket 14867
    975975         */
    976         function test_get_blogaddress_by_id_scheme_reflects_blog_scheme() {
     976        public function test_get_blogaddress_by_id_scheme_reflects_blog_scheme() {
    977977            $blog = self::factory()->blog->create();
    978978
     
    987987         * @ticket 14867
    988988         */
    989         function test_get_blogaddress_by_id_scheme_is_unaffected_by_request() {
     989        public function test_get_blogaddress_by_id_scheme_is_unaffected_by_request() {
    990990            $blog = self::factory()->blog->create();
    991991
     
    10061006         * @dataProvider data_new_blog_url_schemes
    10071007         */
    1008         function test_new_blog_url_schemes( $home_scheme, $siteurl_scheme, $force_ssl_admin ) {
     1008        public function test_new_blog_url_schemes( $home_scheme, $siteurl_scheme, $force_ssl_admin ) {
    10091009            $current_site = get_current_site();
    10101010
     
    10321032        }
    10331033
    1034         function data_new_blog_url_schemes() {
     1034        public function data_new_blog_url_schemes() {
    10351035            return array(
    10361036                array(
     
    10651065         * @ticket 36918
    10661066         */
    1067         function test_new_blog_locale() {
     1067        public function test_new_blog_locale() {
    10681068            $current_site = get_current_site();
    10691069
     
    11001100         * @ticket 40503
    11011101         */
    1102         function test_different_network_language() {
     1102        public function test_different_network_language() {
    11031103            $network = get_network( self::$network_ids['make.wordpress.org/'] );
    11041104
     
    11211121         * @return string The orginal value.
    11221122         */
    1123         function filter_allow_unavailable_languages( $value, $option, $original_value ) {
     1123        public function filter_allow_unavailable_languages( $value, $option, $original_value ) {
    11241124            return $original_value;
    11251125        }
Note: See TracChangeset for help on using the changeset viewer.