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

    r46586 r47122  
    1919    function setUp() {
    2020        parent::setUp();
    21         // make sure the schedule is clear
     21        // Make sure the schedule is clear.
    2222        _set_cron_array( array() );
    2323        $this->preflight_cron_array = array();
     
    2626
    2727    function tearDown() {
    28         // make sure the schedule is clear
     28        // Make sure the schedule is clear.
    2929        _set_cron_array( array() );
    3030        parent::tearDown();
     
    3232
    3333    function test_wp_get_schedule_empty() {
    34         // nothing scheduled
     34        // Nothing scheduled.
    3535        $hook = __FUNCTION__;
    3636        $this->assertFalse( wp_get_schedule( $hook ) );
     
    3838
    3939    function test_schedule_event_single() {
    40         // schedule an event and make sure it's returned by wp_next_scheduled
     40        // Schedule an event and make sure it's returned by wp_next_scheduled().
    4141        $hook      = __FUNCTION__;
    4242        $timestamp = strtotime( '+1 hour' );
     
    4646        $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) );
    4747
    48         // it's a non recurring event
     48        // It's a non-recurring event.
    4949        $this->assertEquals( '', wp_get_schedule( $hook ) );
    5050
     
    5252
    5353    function test_schedule_event_single_args() {
    54         // schedule an event with arguments and make sure it's returned by wp_next_scheduled
     54        // Schedule an event with arguments and make sure it's returned by wp_next_scheduled().
    5555        $hook      = 'event';
    5656        $timestamp = strtotime( '+1 hour' );
     
    5959        $scheduled = wp_schedule_single_event( $timestamp, $hook, $args );
    6060        $this->assertTrue( $scheduled );
    61         // this returns the timestamp only if we provide matching args
     61        // This returns the timestamp only if we provide matching args.
    6262        $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) );
    63         // these don't match so return nothing
     63        // These don't match so return nothing.
    6464        $this->assertEquals( false, wp_next_scheduled( $hook ) );
    6565        $this->assertEquals( false, wp_next_scheduled( $hook, array( 'bar' ) ) );
    6666
    67         // it's a non recurring event
     67        // It's a non-recurring event.
    6868        $this->assertEquals( '', wp_get_schedule( $hook, $args ) );
    6969    }
    7070
    7171    function test_schedule_event() {
    72         // schedule an event and make sure it's returned by wp_next_scheduled
     72        // Schedule an event and make sure it's returned by wp_next_scheduled().
    7373        $hook      = __FUNCTION__;
    7474        $recur     = 'hourly';
     
    7777        $scheduled = wp_schedule_event( $timestamp, $recur, $hook );
    7878        $this->assertTrue( $scheduled );
    79         // it's scheduled for the right time
     79        // It's scheduled for the right time.
    8080        $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) );
    81         // it's a recurring event
     81        // It's a recurring event.
    8282        $this->assertEquals( $recur, wp_get_schedule( $hook ) );
    8383    }
    8484
    8585    function test_schedule_event_args() {
    86         // schedule an event and make sure it's returned by wp_next_scheduled
     86        // Schedule an event and make sure it's returned by wp_next_scheduled().
    8787        $hook      = 'event';
    8888        $timestamp = strtotime( '+1 hour' );
     
    9292        $scheduled = wp_schedule_event( $timestamp, 'hourly', $hook, $args );
    9393        $this->assertTrue( $scheduled );
    94         // this returns the timestamp only if we provide matching args
     94        // This returns the timestamp only if we provide matching args.
    9595        $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) );
    96         // these don't match so return nothing
     96        // These don't match so return nothing.
    9797        $this->assertEquals( false, wp_next_scheduled( $hook ) );
    9898        $this->assertEquals( false, wp_next_scheduled( $hook, array( 'bar' ) ) );
     
    103103
    104104    function test_unschedule_event() {
    105         // schedule an event and make sure it's returned by wp_next_scheduled
     105        // Schedule an event and make sure it's returned by wp_next_scheduled().
    106106        $hook      = __FUNCTION__;
    107107        $timestamp = strtotime( '+1 hour' );
     
    110110        $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) );
    111111
    112         // now unschedule it and make sure it's gone
     112        // Now unschedule it and make sure it's gone.
    113113        $unscheduled = wp_unschedule_event( $timestamp, $hook );
    114114        $this->assertTrue( $unscheduled );
     
    120120        $args = array( 'arg1' );
    121121
    122         // schedule several events with and without arguments
     122        // Schedule several events with and without arguments.
    123123        wp_schedule_single_event( strtotime( '+1 hour' ), $hook );
    124124        wp_schedule_single_event( strtotime( '+2 hour' ), $hook );
     
    126126        wp_schedule_single_event( strtotime( '+4 hour' ), $hook, $args );
    127127
    128         // make sure they're returned by wp_next_scheduled()
     128        // Make sure they're returned by wp_next_scheduled().
    129129        $this->assertTrue( wp_next_scheduled( $hook ) > 0 );
    130130        $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
    131131
    132         // clear the schedule for the no args events and make sure it's gone
     132        // Clear the schedule for the no args events and make sure it's gone.
    133133        $hook_unscheduled = wp_clear_scheduled_hook( $hook );
    134134        $this->assertSame( 2, $hook_unscheduled );
    135135        $this->assertFalse( wp_next_scheduled( $hook ) );
    136         // the args events should still be there
     136        // The args events should still be there.
    137137        $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
    138138
    139         // clear the schedule for the args events and make sure they're gone too
    140         // note: wp_clear_scheduled_hook() expects args passed directly, rather than as an array
     139        // Clear the schedule for the args events and make sure they're gone too.
     140        // Note: wp_clear_scheduled_hook() expects args passed directly, rather than as an array.
    141141        wp_clear_scheduled_hook( $hook, $args );
    142142        $this->assertFalse( wp_next_scheduled( $hook, $args ) );
     
    150150        wp_schedule_single_event( strtotime( '+2 hour' ), $hook, $args );
    151151
    152         // clear the schedule for no args events and ensure no events are cleared.
     152        // Clear the schedule for no args events and ensure no events are cleared.
    153153        $hook_unscheduled = wp_clear_scheduled_hook( $hook );
    154154        $this->assertSame( 0, $hook_unscheduled );
     
    159159        $args = array( 'arg1', 'arg2' );
    160160
    161         // schedule several events with and without arguments
     161        // Schedule several events with and without arguments.
    162162        wp_schedule_single_event( strtotime( '+1 hour' ), $hook );
    163163        wp_schedule_single_event( strtotime( '+2 hour' ), $hook );
     
    165165        wp_schedule_single_event( strtotime( '+4 hour' ), $hook, $args );
    166166
    167         // make sure they're returned by wp_next_scheduled()
     167        // Make sure they're returned by wp_next_scheduled().
    168168        $this->assertTrue( wp_next_scheduled( $hook ) > 0 );
    169169        $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
    170170
    171         // clear the schedule for the no args events and make sure it's gone
     171        // Clear the schedule for the no args events and make sure it's gone.
    172172        wp_clear_scheduled_hook( $hook );
    173173        $this->assertFalse( wp_next_scheduled( $hook ) );
    174         // the args events should still be there
     174        // The args events should still be there.
    175175        $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
    176176
    177         // clear the schedule for the args events and make sure they're gone too
    178         // note: wp_clear_scheduled_hook() used to expect args passed directly, rather than as an array pre WP 3.0
     177        // Clear the schedule for the args events and make sure they're gone too.
     178        // Note: wp_clear_scheduled_hook() used to expect args passed directly, rather than as an array pre WP 3.0.
    179179        wp_clear_scheduled_hook( $hook, $args );
    180180        $this->assertFalse( wp_next_scheduled( $hook, $args ) );
     
    190190        $multi_args = array( 'arg2', 'arg3' );
    191191
    192         // schedule several events with and without arguments
     192        // Schedule several events with and without arguments.
    193193        wp_schedule_single_event( strtotime( '+1 hour' ), $hook );
    194194        wp_schedule_single_event( strtotime( '+2 hour' ), $hook );
     
    198198        wp_schedule_single_event( strtotime( '+6 hour' ), $multi_hook, $multi_args );
    199199
    200         // make sure they're returned by wp_next_scheduled()
     200        // Make sure they're returned by wp_next_scheduled().
    201201        $this->assertTrue( wp_next_scheduled( $hook ) > 0 );
    202202        $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
    203203
    204         // clear the schedule for the no args events and make sure it's gone
     204        // Clear the schedule for the no args events and make sure it's gone.
    205205        wp_clear_scheduled_hook( $hook );
    206206        $this->assertFalse( wp_next_scheduled( $hook ) );
    207         // the args events should still be there
     207        // The args events should still be there.
    208208        $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
    209209
    210         // clear the schedule for the args events and make sure they're gone too
     210        // Clear the schedule for the args events and make sure they're gone too.
    211211        // wp_clear_scheduled_hook() should take args as an array like the other functions.
    212212        wp_clear_scheduled_hook( $hook, $args );
    213213        $this->assertFalse( wp_next_scheduled( $hook, $args ) );
    214214
    215         // clear the schedule for the args events and make sure they're gone too
    216         // wp_clear_scheduled_hook() should take args as an array like the other functions and does from WP 3.0
     215        // Clear the schedule for the args events and make sure they're gone too.
     216        // wp_clear_scheduled_hook() should take args as an array like the other functions and does from WP 3.0.
    217217        wp_clear_scheduled_hook( $multi_hook, $multi_args );
    218218        $this->assertFalse( wp_next_scheduled( $multi_hook, $multi_args ) );
     
    226226        $args = array( rand_str() );
    227227
    228         // schedule several events with and without arguments.
     228        // Schedule several events with and without arguments.
    229229        wp_schedule_single_event( strtotime( '+1 hour' ), $hook );
    230230        wp_schedule_single_event( strtotime( '+2 hour' ), $hook );
     
    232232        wp_schedule_single_event( strtotime( '+4 hour' ), $hook, $args );
    233233
    234         // make sure they're returned by wp_next_scheduled().
     234        // Make sure they're returned by wp_next_scheduled().
    235235        $this->assertTrue( wp_next_scheduled( $hook ) > 0 );
    236236        $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 );
    237237
    238         // clear the schedule and make sure it's gone.
     238        // Clear the schedule and make sure it's gone.
    239239        $unschedule_hook = wp_unschedule_hook( $hook );
    240240        $this->assertSame( 4, $unschedule_hook );
     
    264264     */
    265265    function test_duplicate_event() {
    266         // duplicate events close together should be skipped
     266        // Duplicate events close together should be skipped.
    267267        $hook = __FUNCTION__;
    268268        $args = array( 'arg1' );
     
    270270        $ts2  = strtotime( '+3 minutes' );
    271271
    272         // first one works
    273         $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) );
    274         // second one is ignored
     272        // First one works.
     273        $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) );
     274        // Second one is ignored.
    275275        $this->assertFalse( wp_schedule_single_event( $ts2, $hook, $args ) );
    276276
    277         // the next event should be at +5 minutes, not +3
     277        // The next event should be at +5 minutes, not +3.
    278278        $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) );
    279279    }
     
    283283     */
    284284    function test_not_duplicate_event() {
    285         // duplicate events far apart should work normally
     285        // Duplicate events far apart should work normally.
    286286        $hook = __FUNCTION__;
    287287        $args = array( 'arg1' );
     
    289289        $ts2  = strtotime( '+3 minutes' );
    290290
    291         // first one works
    292         $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) );
    293         // second works too
     291        // First one works.
     292        $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) );
     293        // Second works too.
    294294        $this->assertTrue( wp_schedule_single_event( $ts2, $hook, $args ) );
    295295
    296         // the next event should be at +3 minutes, even though that one was scheduled second
     296        // The next event should be at +3 minutes, even though that one was scheduled second.
    297297        $this->assertEquals( $ts2, wp_next_scheduled( $hook, $args ) );
    298298        wp_unschedule_event( $ts2, $hook, $args );
    299         // following event at +30 minutes should be there too
     299        // Following event at +30 minutes should be there too.
    300300        $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) );
    301301    }
    302302
    303303    function test_not_duplicate_event_reversed() {
    304         // duplicate events far apart should work normally regardless of order
     304        // Duplicate events far apart should work normally regardless of order.
    305305        $hook = __FUNCTION__;
    306306        $args = array( 'arg1' );
     
    308308        $ts2  = strtotime( '+30 minutes' );
    309309
    310         // first one works
    311         $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) );
    312         // second works too
     310        // First one works.
     311        $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) );
     312        // Second works too.
    313313        $this->assertTrue( wp_schedule_single_event( $ts2, $hook, $args ) );
    314314
    315         // the next event should be at +3 minutes
     315        // The next event should be at +3 minutes.
    316316        $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) );
    317317        wp_unschedule_event( $ts1, $hook, $args );
    318         // following event should be there too
     318        // Following event should be there too.
    319319        $this->assertEquals( $ts2, wp_next_scheduled( $hook, $args ) );
    320320    }
     
    382382        $ts1  = strtotime( '+30 minutes' );
    383383
    384         // Add an event
     384        // Add an event.
    385385        $this->assertTrue( wp_schedule_event( $ts1, 'hourly', $hook ) );
    386386        $expected = _get_cron_array();
     
    406406        $ts1  = strtotime( '+30 minutes' );
    407407
    408         // Add an event
     408        // Add an event.
    409409        $this->assertTrue( wp_schedule_event( $ts1, 'hourly', $hook ) );
    410410        $expected = _get_cron_array();
     
    430430        $ts1  = strtotime( '+30 minutes' );
    431431
    432         // Add an event
     432        // Add an event.
    433433        $this->assertTrue( wp_schedule_event( $ts1, 'hourly', $hook ) );
    434434        $expected = _get_cron_array();
     
    584584
    585585        // No scheduled events.
    586         // - With timestamp
     586        // - With timestamp.
    587587        $this->assertFalse( wp_get_scheduled_event( $hook, $args, $ts ) );
    588588        // - Get next, none scheduled.
     
    591591        // Schedule an event.
    592592        wp_schedule_event( $ts, $hook, $args );
    593         // - unregistered timestamp
     593        // - Unregistered timestamp.
    594594        $this->assertFalse( wp_get_scheduled_event( $hook, $args, strtotime( '+30 minutes' ) ) );
    595         // - invalid timestamp.
     595        // - Invalid timestamp.
    596596        $this->assertFalse( wp_get_scheduled_event( $hook, $args, 'Words Fail!' ) );
    597597
Note: See TracChangeset for help on using the changeset viewer.