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/general/template.php

    r51586 r52010  
    1818    public $custom_logo_url;
    1919
    20     function set_up() {
     20    public function set_up() {
    2121        parent::set_up();
    2222
     
    2424    }
    2525
    26     function tear_down() {
     26    public function tear_down() {
    2727        global $wp_customize;
    28         $this->_remove_custom_logo();
    29         $this->_remove_site_icon();
     28        $this->remove_custom_logo();
     29        $this->remove_site_icon();
    3030        $wp_customize = null;
    3131
     
    3838     * @requires function imagejpeg
    3939     */
    40     function test_get_site_icon_url() {
     40    public function test_get_site_icon_url() {
    4141        $this->assertEmpty( get_site_icon_url() );
    4242
    43         $this->_set_site_icon();
     43        $this->set_site_icon();
    4444        $this->assertSame( $this->site_icon_url, get_site_icon_url() );
    4545
    46         $this->_remove_site_icon();
     46        $this->remove_site_icon();
    4747        $this->assertEmpty( get_site_icon_url() );
    4848    }
     
    5353     * @requires function imagejpeg
    5454     */
    55     function test_site_icon_url() {
     55    public function test_site_icon_url() {
    5656        $this->expectOutputString( '' );
    5757        site_icon_url();
    5858
    59         $this->_set_site_icon();
     59        $this->set_site_icon();
    6060        $this->expectOutputString( $this->site_icon_url );
    6161        site_icon_url();
     
    6767     * @requires function imagejpeg
    6868     */
    69     function test_has_site_icon() {
     69    public function test_has_site_icon() {
    7070        $this->assertFalse( has_site_icon() );
    7171
    72         $this->_set_site_icon();
     72        $this->set_site_icon();
    7373        $this->assertTrue( has_site_icon() );
    7474
    75         $this->_remove_site_icon();
     75        $this->remove_site_icon();
    7676        $this->assertFalse( has_site_icon() );
    7777    }
     
    8383     * @covers ::has_site_icon
    8484     */
    85     function test_has_site_icon_returns_true_when_called_for_other_site_with_site_icon_set() {
     85    public function test_has_site_icon_returns_true_when_called_for_other_site_with_site_icon_set() {
    8686        $blog_id = $this->factory->blog->create();
    8787        switch_to_blog( $blog_id );
    88         $this->_set_site_icon();
     88        $this->set_site_icon();
    8989        restore_current_blog();
    9090
     
    9898     * @covers ::has_site_icon
    9999     */
    100     function test_has_site_icon_returns_false_when_called_for_other_site_without_site_icon_set() {
     100    public function test_has_site_icon_returns_false_when_called_for_other_site_without_site_icon_set() {
    101101        $blog_id = $this->factory->blog->create();
    102102
     
    109109     * @requires function imagejpeg
    110110     */
    111     function test_wp_site_icon() {
     111    public function test_wp_site_icon() {
    112112        $this->expectOutputString( '' );
    113113        wp_site_icon();
    114114
    115         $this->_set_site_icon();
     115        $this->set_site_icon();
    116116        $output = array(
    117117            sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( get_site_icon_url( 32 ) ) ),
     
    132132     * @requires function imagejpeg
    133133     */
    134     function test_wp_site_icon_with_filter() {
     134    public function test_wp_site_icon_with_filter() {
    135135        $this->expectOutputString( '' );
    136136        wp_site_icon();
    137137
    138         $this->_set_site_icon();
     138        $this->set_site_icon();
    139139        $output = array(
    140140            sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( get_site_icon_url( 32 ) ) ),
     
    148148
    149149        $this->expectOutputString( $output );
    150         add_filter( 'site_icon_meta_tags', array( $this, '_custom_site_icon_meta_tag' ) );
     150        add_filter( 'site_icon_meta_tags', array( $this, 'custom_site_icon_meta_tag' ) );
    151151        wp_site_icon();
    152         remove_filter( 'site_icon_meta_tags', array( $this, '_custom_site_icon_meta_tag' ) );
     152        remove_filter( 'site_icon_meta_tags', array( $this, 'custom_site_icon_meta_tag' ) );
    153153    }
    154154
     
    158158     * @covers ::wp_site_icon
    159159     */
    160     function test_customize_preview_wp_site_icon_empty() {
     160    public function test_customize_preview_wp_site_icon_empty() {
    161161        global $wp_customize;
    162162        wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) );
     
    176176     * @covers ::wp_site_icon
    177177     */
    178     function test_customize_preview_wp_site_icon_dirty() {
     178    public function test_customize_preview_wp_site_icon_dirty() {
    179179        global $wp_customize;
    180180        wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) );
     
    185185        $wp_customize->start_previewing_theme();
    186186
    187         $attachment_id = $this->_insert_attachment();
     187        $attachment_id = $this->insert_attachment();
    188188        $wp_customize->set_post_value( 'site_icon', $attachment_id );
    189189        $wp_customize->get_setting( 'site_icon' )->preview();
     
    208208     * @return array
    209209     */
    210     function _custom_site_icon_meta_tag( $meta_tags ) {
     210    public function custom_site_icon_meta_tag( $meta_tags ) {
    211211        $meta_tags[] = sprintf( '<link rel="apple-touch-icon" sizes="150x150" href="%s" />', esc_url( get_site_icon_url( 150 ) ) );
    212212
     
    219219     * @since 4.3.0
    220220     */
    221     function _set_site_icon() {
     221    private function set_site_icon() {
    222222        if ( ! $this->site_icon_id ) {
    223223            add_filter( 'intermediate_image_sizes_advanced', array( $this->wp_site_icon, 'additional_sizes' ) );
    224             $this->_insert_attachment();
     224            $this->insert_attachment();
    225225            remove_filter( 'intermediate_image_sizes_advanced', array( $this->wp_site_icon, 'additional_sizes' ) );
    226226        }
     
    234234     * @since 4.3.0
    235235     */
    236     function _remove_site_icon() {
     236    private function remove_site_icon() {
    237237        delete_option( 'site_icon' );
    238238    }
     
    243243     * @since 4.3.0
    244244     */
    245     function _insert_attachment() {
     245    private function insert_attachment() {
    246246        $filename = DIR_TESTDATA . '/images/test-image.jpg';
    247247        $contents = file_get_contents( $filename );
     
    261261     * @since 4.5.0
    262262     */
    263     function test_has_custom_logo() {
     263    public function test_has_custom_logo() {
    264264        $this->assertFalse( has_custom_logo() );
    265265
    266         $this->_set_custom_logo();
     266        $this->set_custom_logo();
    267267        $this->assertTrue( has_custom_logo() );
    268268
    269         $this->_remove_custom_logo();
     269        $this->remove_custom_logo();
    270270        $this->assertFalse( has_custom_logo() );
    271271    }
     
    277277     * @covers ::has_custom_logo
    278278     */
    279     function test_has_custom_logo_returns_true_when_called_for_other_site_with_custom_logo_set() {
     279    public function test_has_custom_logo_returns_true_when_called_for_other_site_with_custom_logo_set() {
    280280        $blog_id = $this->factory->blog->create();
    281281        switch_to_blog( $blog_id );
    282         $this->_set_custom_logo();
     282        $this->set_custom_logo();
    283283        restore_current_blog();
    284284
     
    292292     * @covers ::has_custom_logo
    293293     */
    294     function test_has_custom_logo_returns_false_when_called_for_other_site_without_custom_logo_set() {
     294    public function test_has_custom_logo_returns_false_when_called_for_other_site_without_custom_logo_set() {
    295295        $blog_id = $this->factory->blog->create();
    296296
     
    304304     * @since 4.5.0
    305305     */
    306     function test_get_custom_logo() {
     306    public function test_get_custom_logo() {
    307307        $this->assertEmpty( get_custom_logo() );
    308308
    309         $this->_set_custom_logo();
     309        $this->set_custom_logo();
    310310        $custom_logo = get_custom_logo();
    311311        $this->assertNotEmpty( $custom_logo );
    312312        $this->assertIsString( $custom_logo );
    313313
    314         $this->_remove_custom_logo();
     314        $this->remove_custom_logo();
    315315        $this->assertEmpty( get_custom_logo() );
    316316    }
     
    322322     * @covers ::get_custom_logo
    323323     */
    324     function test_get_custom_logo_returns_logo_when_called_for_other_site_with_custom_logo_set() {
     324    public function test_get_custom_logo_returns_logo_when_called_for_other_site_with_custom_logo_set() {
    325325        $blog_id = $this->factory->blog->create();
    326326        switch_to_blog( $blog_id );
    327327
    328         $this->_set_custom_logo();
     328        $this->set_custom_logo();
    329329
    330330        $custom_logo_attr = array(
     
    353353     * @since 4.5.0
    354354     */
    355     function test_the_custom_logo() {
     355    public function test_the_custom_logo() {
    356356        $this->expectOutputString( '' );
    357357        the_custom_logo();
    358358
    359         $this->_set_custom_logo();
     359        $this->set_custom_logo();
    360360
    361361        $custom_logo_attr = array(
     
    381381     * @covers ::the_custom_logo
    382382     */
    383     function test_the_custom_logo_with_alt() {
    384         $this->_set_custom_logo();
     383    public function test_the_custom_logo_with_alt() {
     384        $this->set_custom_logo();
    385385
    386386        $image_alt = 'My alt attribute';
     
    407407     * @since 4.5.0
    408408     */
    409     function _set_custom_logo() {
     409    private function set_custom_logo() {
    410410        if ( ! $this->custom_logo_id ) {
    411             $this->_insert_custom_logo();
     411            $this->insert_custom_logo();
    412412        }
    413413
     
    420420     * @since 4.5.0
    421421     */
    422     function _remove_custom_logo() {
     422    private function remove_custom_logo() {
    423423        remove_theme_mod( 'custom_logo' );
    424424    }
     
    429429     * @since 4.5.0
    430430     */
    431     function _insert_custom_logo() {
     431    private function insert_custom_logo() {
    432432        $filename = DIR_TESTDATA . '/images/test-image.jpg';
    433433        $contents = file_get_contents( $filename );
     
    445445     * @covers ::get_site_icon_url
    446446     */
    447     function test_get_site_icon_url_preserves_switched_state() {
     447    public function test_get_site_icon_url_preserves_switched_state() {
    448448        $blog_id = $this->factory->blog->create();
    449449        switch_to_blog( $blog_id );
     
    465465     * @covers ::has_custom_logo
    466466     */
    467     function test_has_custom_logo_preserves_switched_state() {
     467    public function test_has_custom_logo_preserves_switched_state() {
    468468        $blog_id = $this->factory->blog->create();
    469469        switch_to_blog( $blog_id );
     
    485485     * @covers ::get_custom_logo
    486486     */
    487     function test_get_custom_logo_preserves_switched_state() {
     487    public function test_get_custom_logo_preserves_switched_state() {
    488488        $blog_id = $this->factory->blog->create();
    489489        switch_to_blog( $blog_id );
     
    505505     * @covers ::get_header
    506506     */
    507     function test_get_header_returns_nothing_on_success() {
     507    public function test_get_header_returns_nothing_on_success() {
    508508        $this->expectOutputRegex( '/Header/' );
    509509
     
    518518     * @covers ::get_footer
    519519     */
    520     function test_get_footer_returns_nothing_on_success() {
     520    public function test_get_footer_returns_nothing_on_success() {
    521521        $this->expectOutputRegex( '/Footer/' );
    522522
     
    531531     * @covers ::get_sidebar
    532532     */
    533     function test_get_sidebar_returns_nothing_on_success() {
     533    public function test_get_sidebar_returns_nothing_on_success() {
    534534        $this->expectOutputRegex( '/Sidebar/' );
    535535
     
    544544     * @covers ::get_template_part
    545545     */
    546     function test_get_template_part_returns_nothing_on_success() {
     546    public function test_get_template_part_returns_nothing_on_success() {
    547547        $this->expectOutputRegex( '/Template Part/' );
    548548
     
    557557     * @covers ::get_template_part
    558558     */
    559     function test_get_template_part_returns_false_on_failure() {
     559    public function test_get_template_part_returns_false_on_failure() {
    560560        $this->assertFalse( get_template_part( 'non-existing-template' ) );
    561561    }
     
    566566     * @covers ::get_template_part
    567567     */
    568     function test_get_template_part_passes_arguments_to_template() {
     568    public function test_get_template_part_passes_arguments_to_template() {
    569569        $this->expectOutputRegex( '/{"foo":"baz"}/' );
    570570
     
    577577     * @covers ::get_the_archive_title
    578578     */
    579     function test_get_the_archive_title_is_correct_for_author_queries() {
     579    public function test_get_the_archive_title_is_correct_for_author_queries() {
    580580        $user_with_posts    = $this->factory()->user->create_and_get(
    581581            array(
Note: See TracChangeset for help on using the changeset viewer.