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/post.php

    r51587 r52010  
    3131    }
    3232
    33     function set_up() {
     33    public function set_up() {
    3434        parent::set_up();
    3535
     
    4343     * Helper function: return the timestamp(s) of cron jobs for the specified hook and post.
    4444     */
    45     function _next_schedule_for_post( $hook, $id ) {
     45    private function next_schedule_for_post( $hook, $id ) {
    4646        return wp_next_scheduled( 'publish_future_post', array( 0 => (int) $id ) );
    4747    }
     
    5050     * Helper function, unsets current user globally.
    5151     */
    52     function _unset_current_user() {
     52    private function unset_current_user() {
    5353        global $current_user, $user_ID;
    5454
     
    6060     * Test simple valid behavior: insert and get a post.
    6161     */
    62     function test_vb_insert_get_delete() {
     62    public function test_vb_insert_get_delete() {
    6363        register_post_type( 'cpt', array( 'taxonomies' => array( 'post_tag', 'ctax' ) ) );
    6464        register_taxonomy( 'ctax', 'cpt' );
     
    121121     * Insert a post with a future date, and make sure the status and cron schedule are correct.
    122122     */
    123     function test_vb_insert_future() {
     123    public function test_vb_insert_future() {
    124124        $future_date = strtotime( '+1 day' );
    125125
     
    149149
    150150        // There should be a publish_future_post hook scheduled on the future date.
    151         $this->assertSame( $future_date, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
     151        $this->assertSame( $future_date, $this->next_schedule_for_post( 'publish_future_post', $id ) );
    152152    }
    153153
     
    155155     * Insert a post with a future date, and make sure the status and cron schedule are correct.
    156156     */
    157     function test_vb_insert_future_over_dst() {
     157    public function test_vb_insert_future_over_dst() {
    158158        // Some magic days - one DST one not.
    159159        $future_date_1 = strtotime( 'June 21st +1 year' );
     
    178178
    179179        // Check that there's a publish_future_post job scheduled at the right time.
    180         $this->assertSame( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
     180        $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $id ) );
    181181
    182182        // Now save it again with a date further in the future.
     
    193193
    194194        // And the correct date on the cron job.
    195         $this->assertSame( $future_date_2, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
     195        $this->assertSame( $future_date_2, $this->next_schedule_for_post( 'publish_future_post', $id ) );
    196196    }
    197197
     
    201201     * @ticket 4710
    202202     */
    203     function test_vb_insert_future_edit_bug() {
     203    public function test_vb_insert_future_edit_bug() {
    204204        $future_date_1 = strtotime( '+1 day' );
    205205        $future_date_2 = strtotime( '+2 day' );
     
    223223
    224224        // Check that there's a publish_future_post job scheduled at the right time.
    225         $this->assertSame( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
     225        $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $id ) );
    226226
    227227        // Now save it again with a date further in the future.
     
    238238
    239239        // And the correct date on the cron job.
    240         $this->assertSame( $future_date_2, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
     240        $this->assertSame( $future_date_2, $this->next_schedule_for_post( 'publish_future_post', $id ) );
    241241    }
    242242
     
    244244     * Insert a draft post with a future date, and make sure no cron schedule is set.
    245245     */
    246     function test_vb_insert_future_draft() {
     246    public function test_vb_insert_future_draft() {
    247247        $future_date = strtotime( '+1 day' );
    248248
     
    272272
    273273        // There should be a publish_future_post hook scheduled on the future date.
    274         $this->assertFalse( $this->_next_schedule_for_post( 'publish_future_post', $id ) );
     274        $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $id ) );
    275275
    276276    }
     
    279279     * Insert a future post, then edit and change it to draft, and make sure cron gets it right.
    280280     */
    281     function test_vb_insert_future_change_to_draft() {
     281    public function test_vb_insert_future_change_to_draft() {
    282282        $future_date_1 = strtotime( '+1 day' );
    283283
     
    300300
    301301        // Check that there's a publish_future_post job scheduled at the right time.
    302         $this->assertSame( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
     302        $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $id ) );
    303303
    304304        // Now save it again with status set to draft.
     
    314314
    315315        // And the correct date on the cron job.
    316         $this->assertFalse( $this->_next_schedule_for_post( 'publish_future_post', $id ) );
     316        $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $id ) );
    317317    }
    318318
     
    320320     * Insert a future post, then edit and change the status, and make sure cron gets it right.
    321321     */
    322     function test_vb_insert_future_change_status() {
     322    public function test_vb_insert_future_change_status() {
    323323        $future_date_1 = strtotime( '+1 day' );
    324324
     
    344344
    345345            // Check that there's a publish_future_post job scheduled at the right time.
    346             $this->assertSame( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
     346            $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $id ) );
    347347
    348348            // Now save it again with status changed.
     
    358358
    359359            // And the correct date on the cron job.
    360             $this->assertFalse( $this->_next_schedule_for_post( 'publish_future_post', $id ) );
     360            $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $id ) );
    361361        }
    362362    }
     
    365365     * Insert a draft post with a future date, and make sure no cron schedule is set.
    366366     */
    367     function test_vb_insert_future_private() {
     367    public function test_vb_insert_future_private() {
    368368        $future_date = strtotime( '+1 day' );
    369369
     
    393393
    394394        // There should be a publish_future_post hook scheduled on the future date.
    395         $this->assertFalse( $this->_next_schedule_for_post( 'publish_future_post', $id ) );
     395        $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $id ) );
    396396    }
    397397
     
    401401     * @ticket 17180
    402402     */
    403     function test_vb_insert_invalid_date() {
     403    public function test_vb_insert_invalid_date() {
    404404        $post = array(
    405405            'post_author'  => self::$editor_id,
     
    422422     * Insert a future post, then edit and change it to private, and make sure cron gets it right.
    423423     */
    424     function test_vb_insert_future_change_to_private() {
     424    public function test_vb_insert_future_change_to_private() {
    425425        $future_date_1 = strtotime( '+1 day' );
    426426
     
    443443
    444444        // Check that there's a publish_future_post job scheduled at the right time.
    445         $this->assertSame( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
     445        $this->assertSame( $future_date_1, $this->next_schedule_for_post( 'publish_future_post', $id ) );
    446446
    447447        // Now save it again with status set to draft.
     
    457457
    458458        // And the correct date on the cron job.
    459         $this->assertFalse( $this->_next_schedule_for_post( 'publish_future_post', $id ) );
     459        $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $id ) );
    460460    }
    461461
     
    528528     * @ticket 5364
    529529     */
    530     function test_delete_future_post_cron() {
     530    public function test_delete_future_post_cron() {
    531531        $future_date = strtotime( '+1 day' );
    532532
     
    544544
    545545        // Check that there's a publish_future_post job scheduled at the right time.
    546         $this->assertSame( $future_date, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
     546        $this->assertSame( $future_date, $this->next_schedule_for_post( 'publish_future_post', $id ) );
    547547
    548548        // Now delete the post and make sure the cron entry is removed.
    549549        wp_delete_post( $id );
    550550
    551         $this->assertFalse( $this->_next_schedule_for_post( 'publish_future_post', $id ) );
     551        $this->assertFalse( $this->next_schedule_for_post( 'publish_future_post', $id ) );
    552552    }
    553553
     
    559559     * @ticket 5305
    560560     */
    561     function test_permalink_without_title() {
     561    public function test_permalink_without_title() {
    562562        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    563563
     
    580580    }
    581581
    582     function test_wp_publish_post() {
     582    public function test_wp_publish_post() {
    583583        $draft_id = self::factory()->post->create( array( 'post_status' => 'draft' ) );
    584584
     
    595595     * @ticket 22944
    596596     */
    597     function test_wp_insert_post_and_wp_publish_post_with_future_date() {
     597    public function test_wp_insert_post_and_wp_publish_post_with_future_date() {
    598598        $future_date = gmdate( 'Y-m-d H:i:s', time() + 10000000 );
    599599        $post_id     = self::factory()->post->create(
     
    618618     * @ticket 48145
    619619     */
    620     function test_wp_insert_post_should_default_to_publish_if_post_date_is_within_59_seconds_from_current_time() {
     620    public function test_wp_insert_post_should_default_to_publish_if_post_date_is_within_59_seconds_from_current_time() {
    621621        $future_date = gmdate( 'Y-m-d H:i:s', time() + 59 );
    622622        $post_id     = self::factory()->post->create(
     
    634634     * @ticket 22944
    635635     */
    636     function test_publish_post_with_content_filtering() {
     636    public function test_publish_post_with_content_filtering() {
    637637        kses_remove_filters();
    638638
     
    659659     * @ticket 22944
    660660     */
    661     function test_wp_publish_post_and_avoid_content_filtering() {
     661    public function test_wp_publish_post_and_avoid_content_filtering() {
    662662        kses_remove_filters();
    663663
     
    679679     * @ticket 23708
    680680     */
    681     function test_get_post_ancestors_within_loop() {
     681    public function test_get_post_ancestors_within_loop() {
    682682        global $post;
    683683        $parent_id = self::factory()->post->create();
     
    689689     * @ticket 23474
    690690     */
    691     function test_update_invalid_post_id() {
     691    public function test_update_invalid_post_id() {
    692692        $post_id = self::factory()->post->create( array( 'post_name' => 'get-page-uri-post-name' ) );
    693693        $post    = get_post( $post_id, ARRAY_A );
     
    703703    }
    704704
    705     function test_parse_post_content_single_page() {
     705    public function test_parse_post_content_single_page() {
    706706        global $multipage, $pages, $numpages;
    707707        $post_id = self::factory()->post->create( array( 'post_content' => 'Page 0' ) );
     
    714714    }
    715715
    716     function test_parse_post_content_multi_page() {
     716    public function test_parse_post_content_multi_page() {
    717717        global $multipage, $pages, $numpages;
    718718        $post_id = self::factory()->post->create( array( 'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3' ) );
     
    725725    }
    726726
    727     function test_parse_post_content_remaining_single_page() {
     727    public function test_parse_post_content_remaining_single_page() {
    728728        global $multipage, $pages, $numpages;
    729729        $post_id = self::factory()->post->create( array( 'post_content' => 'Page 0' ) );
     
    736736    }
    737737
    738     function test_parse_post_content_remaining_multi_page() {
     738    public function test_parse_post_content_remaining_multi_page() {
    739739        global $multipage, $pages, $numpages;
    740740        $post_id = self::factory()->post->create( array( 'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3' ) );
     
    750750     * @ticket 16746
    751751     */
    752     function test_parse_post_content_starting_with_nextpage() {
     752    public function test_parse_post_content_starting_with_nextpage() {
    753753        global $multipage, $pages, $numpages;
    754754        $post_id = self::factory()->post->create( array( 'post_content' => '<!--nextpage-->Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3' ) );
     
    764764     * @ticket 16746
    765765     */
    766     function test_parse_post_content_starting_with_nextpage_multi() {
     766    public function test_parse_post_content_starting_with_nextpage_multi() {
    767767        global $multipage, $pages, $numpages;
    768768        $post_id = self::factory()->post->create( array( 'post_content' => '<!--nextpage-->Page 0' ) );
     
    778778     * @ticket 19373
    779779     */
    780     function test_insert_programmatic_sanitized() {
    781         $this->_unset_current_user();
     780    public function test_insert_programmatic_sanitized() {
     781        $this->unset_current_user();
    782782
    783783        register_taxonomy( 'test_tax', 'post' );
     
    805805     * @ticket 24803
    806806     */
    807     function test_wp_count_posts() {
     807    public function test_wp_count_posts() {
    808808        $post_type = rand_str( 20 );
    809809        register_post_type( $post_type );
     
    820820    }
    821821
    822     function test_wp_count_posts_filtered() {
     822    public function test_wp_count_posts_filtered() {
    823823        $post_type = rand_str( 20 );
    824824        register_post_type( $post_type );
     
    840840    }
    841841
    842     function filter_wp_count_posts( $counts ) {
     842    public function filter_wp_count_posts( $counts ) {
    843843        $counts->publish = 2;
    844844        return $counts;
    845845    }
    846846
    847     function test_wp_count_posts_insert_invalidation() {
     847    public function test_wp_count_posts_insert_invalidation() {
    848848        $post_ids       = self::factory()->post->create_many( 3 );
    849849        $initial_counts = wp_count_posts();
     
    863863    }
    864864
    865     function test_wp_count_posts_trash_invalidation() {
     865    public function test_wp_count_posts_trash_invalidation() {
    866866        $post_ids       = self::factory()->post->create_many( 3 );
    867867        $initial_counts = wp_count_posts();
     
    884884     * @ticket 49685
    885885     */
    886     function test_wp_count_posts_status_changes_visible() {
     886    public function test_wp_count_posts_status_changes_visible() {
    887887        self::factory()->post->create_many( 3 );
    888888
     
    900900     * @ticket 25566
    901901     */
    902     function test_wp_tag_cloud_link_with_post_type() {
     902    public function test_wp_tag_cloud_link_with_post_type() {
    903903        $post_type = 'new_post_type';
    904904        $tax       = 'new_tag';
     
    933933     * @ticket 21212
    934934     */
    935     function test_utf8mb3_post_saves_with_emoji() {
     935    public function test_utf8mb3_post_saves_with_emoji() {
    936936        global $wpdb;
    937937
     
    969969     * @ticket 31168
    970970     */
    971     function test_wp_insert_post_default_comment_ping_status_open() {
     971    public function test_wp_insert_post_default_comment_ping_status_open() {
    972972        $post_id = self::factory()->post->create(
    973973            array(
     
    987987     * @ticket 31168
    988988     */
    989     function test_wp_insert_post_page_default_comment_ping_status_closed() {
     989    public function test_wp_insert_post_page_default_comment_ping_status_closed() {
    990990        $post_id = self::factory()->post->create(
    991991            array(
     
    10061006     * @ticket 31168
    10071007     */
    1008     function test_wp_insert_post_cpt_default_comment_ping_status_open() {
     1008    public function test_wp_insert_post_cpt_default_comment_ping_status_open() {
    10091009        $post_type = rand_str( 20 );
    10101010        register_post_type( $post_type, array( 'supports' => array( 'comments', 'trackbacks' ) ) );
     
    10281028     * @ticket 31168
    10291029     */
    1030     function test_wp_insert_post_cpt_default_comment_ping_status_closed() {
     1030    public function test_wp_insert_post_cpt_default_comment_ping_status_closed() {
    10311031        $post_type = rand_str( 20 );
    10321032        register_post_type( $post_type );
     
    10531053     * @ticket 24153
    10541054     */
    1055     function test_user_without_publish_cannot_affect_sticky() {
     1055    public function test_user_without_publish_cannot_affect_sticky() {
    10561056        wp_set_current_user( self::$grammarian_id );
    10571057
     
    10911091     * @ticket 24153
    10921092     */
    1093     function test_user_without_publish_cannot_affect_sticky_with_edit_post() {
     1093    public function test_user_without_publish_cannot_affect_sticky_with_edit_post() {
    10941094        // Create a sticky post.
    10951095        $post = self::factory()->post->create_and_get(
     
    11311131     * @ticket 35600
    11321132     */
    1133     function test_hooks_fire_when_post_gets_stuck_and_unstuck() {
     1133    public function test_hooks_fire_when_post_gets_stuck_and_unstuck() {
    11341134        $post_id = self::factory()->post->create();
    11351135        $a1      = new MockAction();
     
    11591159     * @ticket 34865
    11601160     */
    1161     function test_post_updates_without_slug_provided() {
     1161    public function test_post_updates_without_slug_provided() {
    11621162        $post_id = self::factory()->post->create(
    11631163            array(
     
    12001200     * @ticket 15946
    12011201     */
    1202     function test_wp_insert_post_should_respect_post_date_gmt() {
     1202    public function test_wp_insert_post_should_respect_post_date_gmt() {
    12031203        $post = array(
    12041204            'post_author'   => self::$editor_id,
     
    12211221    }
    12221222
    1223     function test_wp_delete_post_reassign_hierarchical_post_type() {
     1223    public function test_wp_delete_post_reassign_hierarchical_post_type() {
    12241224        $grandparent_page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
    12251225        $parent_page_id      = self::factory()->post->create(
     
    12481248     * @ticket 30937
    12491249     */
    1250     function test_wp_insert_post_for_customize_changeset_should_not_drop_post_name() {
     1250    public function test_wp_insert_post_for_customize_changeset_should_not_drop_post_name() {
    12511251
    12521252        $this->assertSame( 10, has_filter( 'wp_insert_post_data', '_wp_customize_changeset_filter_insert_post_data' ) );
     
    13011301     * @ticket 21112
    13021302     */
    1303     function test_pre_wp_unique_post_slug_filter() {
     1303    public function test_pre_wp_unique_post_slug_filter() {
    13041304        add_filter( 'pre_wp_unique_post_slug', array( $this, 'filter_pre_wp_unique_post_slug' ), 10, 6 );
    13051305
     
    13171317    }
    13181318
    1319     function filter_pre_wp_unique_post_slug( $default, $slug, $post_ID, $post_status, $post_type, $post_parent ) {
     1319    public function filter_pre_wp_unique_post_slug( $default, $slug, $post_ID, $post_status, $post_type, $post_parent ) {
    13201320        return 'override-slug-' . $post_type;
    13211321    }
     
    16071607     * @ticket 52187
    16081608     */
    1609     function test_wp_resolve_post_date() {
     1609    public function test_wp_resolve_post_date() {
    16101610        $post_date     = '2020-12-28 11:26:35';
    16111611        $post_date_gmt = '2020-12-29 10:11:45';
     
    16451645     * @covers ::stick_post
    16461646     */
    1647     function test_stick_post_updates_option() {
     1647    public function test_stick_post_updates_option() {
    16481648        stick_post( 1 );
    16491649        $this->assertSameSets( array( 1 ), get_option( 'sticky_posts' ) );
     
    16621662     * @param mixed $stick Value to pass to stick_post().
    16631663     */
    1664     function test_stick_post_does_not_duplicate_post_ids( $stick ) {
     1664    public function test_stick_post_does_not_duplicate_post_ids( $stick ) {
    16651665        update_option( 'sticky_posts', array( 1, 2 ) );
    16661666
     
    16781678     * }
    16791679     */
    1680     function data_stick_post_does_not_duplicate_post_ids() {
     1680    public function data_stick_post_does_not_duplicate_post_ids() {
    16811681        return array(
    16821682            array( 1 ),
     
    16941694     * @param mixed $stick Value to pass to stick_post().
    16951695     */
    1696     function test_stick_post_removes_duplicate_post_ids_when_adding_new_value() {
     1696    public function test_stick_post_removes_duplicate_post_ids_when_adding_new_value() {
    16971697        update_option( 'sticky_posts', array( 1, 1, 2, 2 ) );
    16981698
     
    17061706     * @covers ::unstick_post
    17071707     */
    1708     function test_unstick_post_updates_option() {
     1708    public function test_unstick_post_updates_option() {
    17091709        update_option( 'sticky_posts', array( 1 ) );
    17101710        unstick_post( 1 );
     
    17281728     * @param array $expected
    17291729     */
    1730     function test_unstick_post_removes_duplicate_post_ids( $starting_option, $unstick, $expected ) {
     1730    public function test_unstick_post_removes_duplicate_post_ids( $starting_option, $unstick, $expected ) {
    17311731        update_option( 'sticky_posts', $starting_option );
    17321732        unstick_post( $unstick );
     
    17451745     * }
    17461746     */
    1747     function data_unstick_post_removes_duplicate_post_ids() {
     1747    public function data_unstick_post_removes_duplicate_post_ids() {
    17481748        return array(
    17491749            array(
     
    17811781     * @covers ::stick_post
    17821782     */
    1783     function test_stick_post_with_duplicate_post_id_does_not_update_option() {
     1783    public function test_stick_post_with_duplicate_post_id_does_not_update_option() {
    17841784        update_option( 'sticky_posts', array( 1, 2, 2 ) );
    17851785        stick_post( 2 );
     
    17931793     * @covers ::unstick_post
    17941794     */
    1795     function test_unstick_post_with_non_sticky_post_id_does_not_update_option() {
     1795    public function test_unstick_post_with_non_sticky_post_id_does_not_update_option() {
    17961796        update_option( 'sticky_posts', array( 1, 2, 2 ) );
    17971797        unstick_post( 3 );
Note: See TracChangeset for help on using the changeset viewer.