Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post.php

    r46969 r47122  
    4040    }
    4141
    42     // helper function: return the timestamp(s) of cron jobs for the specified hook and post
     42    /**
     43     * Helper function: return the timestamp(s) of cron jobs for the specified hook and post.
     44     */
    4345    function _next_schedule_for_post( $hook, $id ) {
    4446        return wp_next_scheduled( 'publish_future_post', array( 0 => intval( $id ) ) );
    4547    }
    4648
    47     // helper function, unsets current user globally
     49    /**
     50     * Helper function, unsets current user globally.
     51     */
    4852    function _unset_current_user() {
    4953        global $current_user, $user_ID;
     
    5357    }
    5458
    55     // test simple valid behavior: insert and get a post
     59    /**
     60     * Test simple valid behavior: insert and get a post.
     61     */
    5662    function test_vb_insert_get_delete() {
    5763        register_post_type( 'cpt', array( 'taxonomies' => array( 'post_tag', 'ctax' ) ) );
     
    7278            );
    7379
    74             // insert a post and make sure the ID is ok
     80            // Insert a post and make sure the ID is OK.
    7581            $id = wp_insert_post( $post );
    7682            $this->assertTrue( is_numeric( $id ) );
    7783            $this->assertTrue( $id > 0 );
    7884
    79             // fetch the post and make sure it matches
     85            // Fetch the post and make sure it matches.
    8086            $out = get_post( $id );
    8187
     
    8591            $this->assertEquals( $post['post_author'], $out->post_author );
    8692
    87             // test cache state
     93            // Test cache state.
    8894            $pcache = wp_cache_get( $id, 'posts' );
    8995            $this->assertInstanceOf( 'stdClass', $pcache );
     
    112118    }
    113119
     120    /**
     121     * Insert a post with a future date, and make sure the status and cron schedule are correct.
     122     */
    114123    function test_vb_insert_future() {
    115         // insert a post with a future date, and make sure the status and cron schedule are correct
    116 
    117124        $future_date = strtotime( '+1 day' );
    118125
     
    125132        );
    126133
    127         // insert a post and make sure the ID is ok
     134        // Insert a post and make sure the ID is OK.
    128135        $id               = wp_insert_post( $post );
    129136        $this->post_ids[] = $id;
    130         #dmp(_get_cron_array());
     137        // dmp( _get_cron_array() );
    131138        $this->assertTrue( is_numeric( $id ) );
    132139        $this->assertTrue( $id > 0 );
    133140
    134         // fetch the post and make sure it matches
     141        // Fetch the post and make sure it matches.
    135142        $out = get_post( $id );
    136143
     
    141148        $this->assertEquals( $post['post_date'], $out->post_date );
    142149
    143         // there should be a publish_future_post hook scheduled on the future date
     150        // There should be a publish_future_post hook scheduled on the future date.
    144151        $this->assertEquals( $future_date, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
    145152    }
    146153
     154    /**
     155     * Insert a post with a future date, and make sure the status and cron schedule are correct.
     156     */
    147157    function test_vb_insert_future_over_dst() {
    148         // insert a post with a future date, and make sure the status and cron schedule are correct
    149 
    150         // Some magic days - one dst one not
     158        // Some magic days - one DST one not.
    151159        $future_date_1 = strtotime( 'June 21st +1 year' );
    152160        $future_date_2 = strtotime( 'Jan 11th +1 year' );
     
    160168        );
    161169
    162         // insert a post and make sure the ID is ok
     170        // Insert a post and make sure the ID is OK.
    163171        $id               = wp_insert_post( $post );
    164172        $this->post_ids[] = $id;
    165173
    166         // fetch the post and make sure has the correct date and status
     174        // Fetch the post and make sure has the correct date and status.
    167175        $out = get_post( $id );
    168176        $this->assertEquals( 'future', $out->post_status );
    169177        $this->assertEquals( $post['post_date'], $out->post_date );
    170178
    171         // check that there's a publish_future_post job scheduled at the right time
     179        // Check that there's a publish_future_post job scheduled at the right time.
    172180        $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
    173181
    174         // now save it again with a date further in the future
     182        // Now save it again with a date further in the future.
    175183
    176184        $post['ID']            = $id;
     
    179187        wp_update_post( $post );
    180188
    181         // fetch the post again and make sure it has the new post_date
     189        // Fetch the post again and make sure it has the new post_date.
    182190        $out = get_post( $id );
    183191        $this->assertEquals( 'future', $out->post_status );
    184192        $this->assertEquals( $post['post_date'], $out->post_date );
    185193
    186         // and the correct date on the cron job
     194        // And the correct date on the cron job.
    187195        $this->assertEquals( $future_date_2, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
    188196    }
    189197
     198    /**
     199     * Future post bug: posts get published at the wrong time if you edit the timestamp.
     200     *
     201     * @ticket 4710
     202     */
    190203    function test_vb_insert_future_edit_bug() {
    191         // future post bug: posts get published at the wrong time if you edit the timestamp
    192         // https://core.trac.wordpress.org/ticket/4710
    193 
    194204        $future_date_1 = strtotime( '+1 day' );
    195205        $future_date_2 = strtotime( '+2 day' );
     
    203213        );
    204214
    205         // insert a post and make sure the ID is ok
     215        // Insert a post and make sure the ID is OK.
    206216        $id               = wp_insert_post( $post );
    207217        $this->post_ids[] = $id;
    208218
    209         // fetch the post and make sure has the correct date and status
     219        // Fetch the post and make sure has the correct date and status.
    210220        $out = get_post( $id );
    211221        $this->assertEquals( 'future', $out->post_status );
    212222        $this->assertEquals( $post['post_date'], $out->post_date );
    213223
    214         // check that there's a publish_future_post job scheduled at the right time
     224        // Check that there's a publish_future_post job scheduled at the right time.
    215225        $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
    216226
    217         // now save it again with a date further in the future
     227        // Now save it again with a date further in the future.
    218228
    219229        $post['ID']            = $id;
     
    222232        wp_update_post( $post );
    223233
    224         // fetch the post again and make sure it has the new post_date
     234        // Fetch the post again and make sure it has the new post_date.
    225235        $out = get_post( $id );
    226236        $this->assertEquals( 'future', $out->post_status );
    227237        $this->assertEquals( $post['post_date'], $out->post_date );
    228238
    229         // and the correct date on the cron job
     239        // And the correct date on the cron job.
    230240        $this->assertEquals( $future_date_2, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
    231241    }
    232242
     243    /**
     244     * Insert a draft post with a future date, and make sure no cron schedule is set.
     245     */
    233246    function test_vb_insert_future_draft() {
    234         // insert a draft post with a future date, and make sure no cron schedule is set
    235 
    236247        $future_date = strtotime( '+1 day' );
    237248
     
    244255        );
    245256
    246         // insert a post and make sure the ID is ok
     257        // Insert a post and make sure the ID is OK.
    247258        $id               = wp_insert_post( $post );
    248259        $this->post_ids[] = $id;
    249         #dmp(_get_cron_array());
     260        // dmp( _get_cron_array() );
    250261        $this->assertTrue( is_numeric( $id ) );
    251262        $this->assertTrue( $id > 0 );
    252263
    253         // fetch the post and make sure it matches
     264        // Fetch the post and make sure it matches.
    254265        $out = get_post( $id );
    255266
     
    260271        $this->assertEquals( $post['post_date'], $out->post_date );
    261272
    262         // there should be a publish_future_post hook scheduled on the future date
     273        // There should be a publish_future_post hook scheduled on the future date.
    263274        $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
    264275
    265276    }
    266277
     278    /**
     279     * Insert a future post, then edit and change it to draft, and make sure cron gets it right.
     280     */
    267281    function test_vb_insert_future_change_to_draft() {
    268         // insert a future post, then edit and change it to draft, and make sure cron gets it right
    269282        $future_date_1 = strtotime( '+1 day' );
    270283
     
    277290        );
    278291
    279         // insert a post and make sure the ID is ok
     292        // Insert a post and make sure the ID is OK.
    280293        $id               = wp_insert_post( $post );
    281294        $this->post_ids[] = $id;
    282295
    283         // fetch the post and make sure has the correct date and status
     296        // Fetch the post and make sure has the correct date and status.
    284297        $out = get_post( $id );
    285298        $this->assertEquals( 'future', $out->post_status );
    286299        $this->assertEquals( $post['post_date'], $out->post_date );
    287300
    288         // check that there's a publish_future_post job scheduled at the right time
     301        // Check that there's a publish_future_post job scheduled at the right time.
    289302        $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
    290303
    291         // now save it again with status set to draft
     304        // Now save it again with status set to draft.
    292305
    293306        $post['ID']          = $id;
     
    295308        wp_update_post( $post );
    296309
    297         // fetch the post again and make sure it has the new post_date
     310        // Fetch the post again and make sure it has the new post_date.
    298311        $out = get_post( $id );
    299312        $this->assertEquals( 'draft', $out->post_status );
    300313        $this->assertEquals( $post['post_date'], $out->post_date );
    301314
    302         // and the correct date on the cron job
     315        // And the correct date on the cron job.
    303316        $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
    304317    }
    305318
     319    /**
     320     * Insert a future post, then edit and change the status, and make sure cron gets it right.
     321     */
    306322    function test_vb_insert_future_change_status() {
    307         // insert a future post, then edit and change the status, and make sure cron gets it right
    308323        $future_date_1 = strtotime( '+1 day' );
    309324
     
    319334            );
    320335
    321             // insert a post and make sure the ID is ok
     336            // Insert a post and make sure the ID is OK.
    322337            $id               = wp_insert_post( $post );
    323338            $this->post_ids[] = $id;
    324339
    325             // fetch the post and make sure has the correct date and status
     340            // Fetch the post and make sure has the correct date and status.
    326341            $out = get_post( $id );
    327342            $this->assertEquals( 'future', $out->post_status );
    328343            $this->assertEquals( $post['post_date'], $out->post_date );
    329344
    330             // check that there's a publish_future_post job scheduled at the right time
     345            // Check that there's a publish_future_post job scheduled at the right time.
    331346            $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
    332347
    333             // now save it again with status changed
     348            // Now save it again with status changed.
    334349
    335350            $post['ID']          = $id;
     
    337352            wp_update_post( $post );
    338353
    339             // fetch the post again and make sure it has the new post_date
     354            // Fetch the post again and make sure it has the new post_date.
    340355            $out = get_post( $id );
    341356            $this->assertEquals( $status, $out->post_status );
    342357            $this->assertEquals( $post['post_date'], $out->post_date );
    343358
    344             // and the correct date on the cron job
     359            // And the correct date on the cron job.
    345360            $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
    346361        }
    347362    }
    348363
     364    /**
     365     * Insert a draft post with a future date, and make sure no cron schedule is set.
     366     */
    349367    function test_vb_insert_future_private() {
    350         // insert a draft post with a future date, and make sure no cron schedule is set
    351 
    352368        $future_date = strtotime( '+1 day' );
    353369
     
    360376        );
    361377
    362         // insert a post and make sure the ID is ok
     378        // Insert a post and make sure the ID is OK.
    363379        $id               = wp_insert_post( $post );
    364380        $this->post_ids[] = $id;
    365         #dmp(_get_cron_array());
     381        // dmp( _get_cron_array() );
    366382        $this->assertTrue( is_numeric( $id ) );
    367383        $this->assertTrue( $id > 0 );
    368384
    369         // fetch the post and make sure it matches
     385        // Fetch the post and make sure it matches.
    370386        $out = get_post( $id );
    371387
     
    376392        $this->assertEquals( $post['post_date'], $out->post_date );
    377393
    378         // there should be a publish_future_post hook scheduled on the future date
     394        // There should be a publish_future_post hook scheduled on the future date.
    379395        $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
    380396    }
    381397
    382398    /**
     399     * Insert a post with an invalid date, make sure it fails.
     400     *
    383401     * @ticket 17180
    384402     */
    385403    function test_vb_insert_invalid_date() {
    386         // insert a post with an invalid date, make sure it fails
    387 
    388404        $post = array(
    389405            'post_author'  => self::$editor_id,
     
    394410        );
    395411
    396         // Test both return paths with or without WP_Error
     412        // Test both return paths with or without WP_Error.
    397413        $insert_post = wp_insert_post( $post, true );
    398414        $this->assertWPError( $insert_post );
     
    403419    }
    404420
     421    /**
     422     * Insert a future post, then edit and change it to private, and make sure cron gets it right.
     423     */
    405424    function test_vb_insert_future_change_to_private() {
    406         // insert a future post, then edit and change it to private, and make sure cron gets it right
    407425        $future_date_1 = strtotime( '+1 day' );
    408426
     
    415433        );
    416434
    417         // insert a post and make sure the ID is ok
     435        // Insert a post and make sure the ID is OK.
    418436        $id               = wp_insert_post( $post );
    419437        $this->post_ids[] = $id;
    420438
    421         // fetch the post and make sure has the correct date and status
     439        // Fetch the post and make sure has the correct date and status.
    422440        $out = get_post( $id );
    423441        $this->assertEquals( 'future', $out->post_status );
    424442        $this->assertEquals( $post['post_date'], $out->post_date );
    425443
    426         // check that there's a publish_future_post job scheduled at the right time
     444        // Check that there's a publish_future_post job scheduled at the right time.
    427445        $this->assertEquals( $future_date_1, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
    428446
    429         // now save it again with status set to draft
     447        // Now save it again with status set to draft.
    430448
    431449        $post['ID']          = $id;
     
    433451        wp_update_post( $post );
    434452
    435         // fetch the post again and make sure it has the new post_date
     453        // Fetch the post again and make sure it has the new post_date.
    436454        $out = get_post( $id );
    437455        $this->assertEquals( 'private', $out->post_status );
    438456        $this->assertEquals( $post['post_date'], $out->post_date );
    439457
    440         // and the correct date on the cron job
     458        // And the correct date on the cron job.
    441459        $this->assertEquals( false, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
    442460    }
     
    506524
    507525    /**
     526     * "When I delete a future post using wp_delete_post( $post->ID ) it does not update the cron correctly."
     527     *
    508528     * @ticket 5364
    509529     */
    510530    function test_delete_future_post_cron() {
    511         // "When I delete a future post using wp_delete_post($post->ID) it does not update the cron correctly."
    512531        $future_date = strtotime( '+1 day' );
    513532
     
    520539        );
    521540
    522         // insert a post and make sure the ID is ok
     541        // Insert a post and make sure the ID is OK.
    523542        $id               = wp_insert_post( $post );
    524543        $this->post_ids[] = $id;
    525544
    526         // check that there's a publish_future_post job scheduled at the right time
     545        // Check that there's a publish_future_post job scheduled at the right time.
    527546        $this->assertEquals( $future_date, $this->_next_schedule_for_post( 'publish_future_post', $id ) );
    528547
    529         // now delete the post and make sure the cron entry is removed
     548        // Now delete the post and make sure the cron entry is removed.
    530549        wp_delete_post( $id );
    531550
     
    534553
    535554    /**
     555     * Bug: permalink doesn't work if post title is empty.
     556     *
     557     * Might only fail if the post ID is greater than four characters.
     558     *
    536559     * @ticket 5305
    537560     */
    538561    function test_permalink_without_title() {
    539         // bug: permalink doesn't work if post title is empty
    540         // might only fail if the post ID is greater than four characters
    541 
    542562        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    543563
     
    550570        );
    551571
    552         // insert a post and make sure the ID is ok
     572        // Insert a post and make sure the ID is OK.
    553573        $id               = wp_insert_post( $post );
    554574        $this->post_ids[] = $id;
     
    556576        $plink = get_permalink( $id );
    557577
    558         // permalink should include the post ID at the end
     578        // Permalink should include the post ID at the end.
    559579        $this->assertEquals( get_option( 'siteurl' ) . '/2007/10/31/' . $id . '/', $plink );
    560580    }
     
    11071127        wp_set_current_user( self::$grammarian_id );
    11081128
    1109         // Sanity Check.
     1129        // Sanity check.
    11101130        $this->assertFalse( current_user_can( 'publish_posts' ) );
    11111131        $this->assertTrue( current_user_can( 'edit_others_posts' ) );
     
    11211141        stick_post( $post->ID );
    11221142
    1123         // Sanity Check.
     1143        // Sanity check.
    11241144        $this->assertTrue( is_sticky( $post->ID ) );
    11251145
     
    11521172        stick_post( $post->ID );
    11531173
    1154         // Sanity Check.
     1174        // Sanity check.
    11551175        $this->assertTrue( is_sticky( $post->ID ) );
    11561176
    11571177        wp_set_current_user( self::$grammarian_id );
    11581178
    1159         // Sanity Check.
     1179        // Sanity check.
    11601180        $this->assertFalse( current_user_can( 'publish_posts' ) );
    11611181        $this->assertTrue( current_user_can( 'edit_others_posts' ) );
    11621182        $this->assertTrue( current_user_can( 'edit_published_posts' ) );
    11631183
    1164         // Edit the post - The key 'sticky' is intentionally unset.
     1184        // Edit the post - the key 'sticky' is intentionally unset.
    11651185        $data = array(
    11661186            'post_ID'      => $post->ID,
     
    11701190        edit_post( $data );
    11711191
    1172         // Make sure it's still sticky
     1192        // Make sure it's still sticky.
    11731193        $saved_post = get_post( $post->ID );
    11741194        $this->assertTrue( is_sticky( $saved_post->ID ) );
     
    12601280        );
    12611281
    1262         // insert a post and make sure the ID is ok
     1282        // Insert a post and make sure the ID is OK.
    12631283        $id = wp_insert_post( $post );
    12641284
Note: See TracChangeset for help on using the changeset viewer.