Make WordPress Core


Ignore:
Timestamp:
11/04/2021 03:22:47 PM (5 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/general/wpResourceHints.php

    r51568 r52010  
    1111        private $old_wp_styles;
    1212
    13         function set_up() {
     13        public function set_up() {
    1414                parent::set_up();
    1515                $this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null;
     
    2525        }
    2626
    27         function tear_down() {
     27        public function tear_down() {
    2828                $GLOBALS['wp_scripts'] = $this->old_wp_scripts;
    2929                $GLOBALS['wp_styles']  = $this->old_wp_styles;
     
    3131        }
    3232
    33         function test_should_have_defaults_on_frontend() {
     33        public function test_should_have_defaults_on_frontend() {
    3434                $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
    3535
     
    3939        }
    4040
    41         function test_dns_prefetching() {
     41        public function test_dns_prefetching() {
    4242                $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
    4343                                        "<link rel='dns-prefetch' href='//wordpress.org' />\n" .
     
    4545                                        "<link rel='dns-prefetch' href='//make.wordpress.org' />\n";
    4646
    47                 add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_domains' ), 10, 2 );
    48 
    49                 $actual = get_echo( 'wp_resource_hints' );
    50 
    51                 remove_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_domains' ) );
    52 
    53                 $this->assertSame( $expected, $actual );
    54         }
    55 
    56         function _add_dns_prefetch_domains( $hints, $method ) {
     47                add_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch_domains' ), 10, 2 );
     48
     49                $actual = get_echo( 'wp_resource_hints' );
     50
     51                remove_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch_domains' ) );
     52
     53                $this->assertSame( $expected, $actual );
     54        }
     55
     56        public function add_dns_prefetch_domains( $hints, $method ) {
    5757                if ( 'dns-prefetch' === $method ) {
    5858                        $hints[] = 'http://wordpress.org';
     
    7070         * @ticket 37652
    7171         */
    72         function test_preconnect() {
     72        public function test_preconnect() {
    7373                $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
    7474                                        "<link rel='preconnect' href='//wordpress.org' />\n" .
     
    7777                                        "<link rel='preconnect' href='http://w.org' />\n";
    7878
    79                 add_filter( 'wp_resource_hints', array( $this, '_add_preconnect_domains' ), 10, 2 );
    80 
    81                 $actual = get_echo( 'wp_resource_hints' );
    82 
    83                 remove_filter( 'wp_resource_hints', array( $this, '_add_preconnect_domains' ) );
    84 
    85                 $this->assertSame( $expected, $actual );
    86         }
    87 
    88         function _add_preconnect_domains( $hints, $method ) {
     79                add_filter( 'wp_resource_hints', array( $this, 'add_preconnect_domains' ), 10, 2 );
     80
     81                $actual = get_echo( 'wp_resource_hints' );
     82
     83                remove_filter( 'wp_resource_hints', array( $this, 'add_preconnect_domains' ) );
     84
     85                $this->assertSame( $expected, $actual );
     86        }
     87
     88        public function add_preconnect_domains( $hints, $method ) {
    8989                if ( 'preconnect' === $method ) {
    9090                        $hints[] = '//wordpress.org';
     
    9898        }
    9999
    100         function test_prerender() {
     100        public function test_prerender() {
    101101                $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
    102102                                        "<link rel='prerender' href='https://make.wordpress.org/great-again' />\n" .
     
    104104                                        "<link rel='prerender' href='//core.trac.wordpress.org' />\n";
    105105
    106                 add_filter( 'wp_resource_hints', array( $this, '_add_prerender_urls' ), 10, 2 );
    107 
    108                 $actual = get_echo( 'wp_resource_hints' );
    109 
    110                 remove_filter( 'wp_resource_hints', array( $this, '_add_prerender_urls' ) );
    111 
    112                 $this->assertSame( $expected, $actual );
    113         }
    114 
    115         function _add_prerender_urls( $hints, $method ) {
     106                add_filter( 'wp_resource_hints', array( $this, 'add_prerender_urls' ), 10, 2 );
     107
     108                $actual = get_echo( 'wp_resource_hints' );
     109
     110                remove_filter( 'wp_resource_hints', array( $this, 'add_prerender_urls' ) );
     111
     112                $this->assertSame( $expected, $actual );
     113        }
     114
     115        public function add_prerender_urls( $hints, $method ) {
    116116                if ( 'prerender' === $method ) {
    117117                        $hints[] = 'https://make.wordpress.org/great-again';
     
    124124        }
    125125
    126         function test_parse_url_dns_prefetch() {
     126        public function test_parse_url_dns_prefetch() {
    127127                $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
    128128                                        "<link rel='dns-prefetch' href='//make.wordpress.org' />\n";
    129129
    130                 add_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_long_urls' ), 10, 2 );
    131 
    132                 $actual = get_echo( 'wp_resource_hints' );
    133 
    134                 remove_filter( 'wp_resource_hints', array( $this, '_add_dns_prefetch_long_urls' ) );
    135 
    136                 $this->assertSame( $expected, $actual );
    137         }
    138 
    139         function _add_dns_prefetch_long_urls( $hints, $method ) {
     130                add_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch_long_urls' ), 10, 2 );
     131
     132                $actual = get_echo( 'wp_resource_hints' );
     133
     134                remove_filter( 'wp_resource_hints', array( $this, 'add_dns_prefetch_long_urls' ) );
     135
     136                $this->assertSame( $expected, $actual );
     137        }
     138
     139        public function add_dns_prefetch_long_urls( $hints, $method ) {
    140140                if ( 'dns-prefetch' === $method ) {
    141141                        $hints[] = 'http://make.wordpress.org/wp-includes/css/editor.css';
     
    145145        }
    146146
    147         function test_dns_prefetch_styles() {
     147        public function test_dns_prefetch_styles() {
    148148                $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com' />\n" .
    149149                                        "<link rel='dns-prefetch' href='//s.w.org' />\n";
     
    164164        }
    165165
    166         function test_dns_prefetch_scripts() {
     166        public function test_dns_prefetch_scripts() {
    167167                $expected = "<link rel='dns-prefetch' href='//fonts.googleapis.com' />\n" .
    168168                                        "<link rel='dns-prefetch' href='//s.w.org' />\n";
     
    185185         * @ticket 37385
    186186         */
    187         function test_dns_prefetch_scripts_does_not_include_registered_only() {
     187        public function test_dns_prefetch_scripts_does_not_include_registered_only() {
    188188                $expected   = "<link rel='dns-prefetch' href='//s.w.org' />\n";
    189189                $unexpected = "<link rel='dns-prefetch' href='//wordpress.org' />\n";
     
    202202         * @ticket 37502
    203203         */
    204         function test_deregistered_scripts_are_ignored() {
     204        public function test_deregistered_scripts_are_ignored() {
    205205                $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
    206206
     
    215215         * @ticket 37652
    216216         */
    217         function test_malformed_urls() {
     217        public function test_malformed_urls() {
    218218                $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n";
    219219
    220220                // Errant colon.
    221                 add_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_errant_colon' ), 10, 2 );
    222                 $actual = get_echo( 'wp_resource_hints' );
    223                 remove_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_errant_colon' ) );
     221                add_filter( 'wp_resource_hints', array( $this, 'add_malformed_url_errant_colon' ), 10, 2 );
     222                $actual = get_echo( 'wp_resource_hints' );
     223                remove_filter( 'wp_resource_hints', array( $this, 'add_malformed_url_errant_colon' ) );
    224224                $this->assertSame( $expected, $actual );
    225225
    226226                // Unsupported Scheme.
    227                 add_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_unsupported_scheme' ), 10, 2 );
    228                 $actual = get_echo( 'wp_resource_hints' );
    229                 remove_filter( 'wp_resource_hints', array( $this, '_add_malformed_url_unsupported_scheme' ) );
    230                 $this->assertSame( $expected, $actual );
    231         }
    232 
    233         function _add_malformed_url_errant_colon( $hints, $method ) {
     227                add_filter( 'wp_resource_hints', array( $this, 'add_malformed_url_unsupported_scheme' ), 10, 2 );
     228                $actual = get_echo( 'wp_resource_hints' );
     229                remove_filter( 'wp_resource_hints', array( $this, 'add_malformed_url_unsupported_scheme' ) );
     230                $this->assertSame( $expected, $actual );
     231        }
     232
     233        public function add_malformed_url_errant_colon( $hints, $method ) {
    234234                if ( 'preconnect' === $method ) {
    235235                        $hints[] = '://core.trac.wordpress.org/ticket/37652';
     
    239239        }
    240240
    241         function _add_malformed_url_unsupported_scheme( $hints, $method ) {
     241        public function add_malformed_url_unsupported_scheme( $hints, $method ) {
    242242                if ( 'preconnect' === $method ) {
    243243                        $hints[] = 'git://develop.git.wordpress.org/';
     
    250250         * @ticket 38121
    251251         */
    252         function test_custom_attributes() {
     252        public function test_custom_attributes() {
    253253                $expected = "<link rel='dns-prefetch' href='//s.w.org' />\n" .
    254254                                        "<link rel='preconnect' href='https://make.wordpress.org' />\n" .
     
    257257                                        "<link href='http://wordpress.org' rel='prerender' />\n";
    258258
    259                 add_filter( 'wp_resource_hints', array( $this, '_add_url_with_attributes' ), 10, 2 );
    260 
    261                 $actual = get_echo( 'wp_resource_hints' );
    262 
    263                 remove_filter( 'wp_resource_hints', array( $this, '_add_url_with_attributes' ) );
    264 
    265                 $this->assertSame( $expected, $actual );
    266         }
    267 
    268         function _add_url_with_attributes( $hints, $method ) {
     259                add_filter( 'wp_resource_hints', array( $this, 'add_url_with_attributes' ), 10, 2 );
     260
     261                $actual = get_echo( 'wp_resource_hints' );
     262
     263                remove_filter( 'wp_resource_hints', array( $this, 'add_url_with_attributes' ) );
     264
     265                $this->assertSame( $expected, $actual );
     266        }
     267
     268        public function add_url_with_attributes( $hints, $method ) {
    269269                // Ignore hints with missing href attributes.
    270270                $hints[] = array(
Note: See TracChangeset for help on using the changeset viewer.