WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/17/2014 07:16:26 PM (7 years ago)
Author:
wonderboymusic
Message:

wp_schedule_single_event() should not prevent scheduling a future duplicate event. It should only reject an event as a duplicate if there is already a similar event scheduled within 10 minutes of the given timestamp.

Adds unit tests, fixes existing cron test.

Props tellyworth.

See [9181], #6966.
Fixes #28213.

File:
1 edited

Legend:

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

    r25368 r29939  
    215215        // duplicate events far apart should work normally
    216216        $hook = rand_str();
    217         $args = array(rand_str());
    218         $ts1 = strtotime('+30 minutes');
    219         $ts2 = strtotime('+3 minutes');
     217        $args = array( rand_str() );
     218        $ts1 = strtotime( '+30 minutes' );
     219        $ts2 = strtotime( '+3 minutes' );
    220220
    221221        // first one works
     
    224224        wp_schedule_single_event( $ts2, $hook, $args );
    225225
    226         // the next event should be at +5 minutes, not +3
    227         $this->assertEquals( $ts2, wp_next_scheduled($hook, $args) );
     226        // the next event should be at +3 minutes, even though that one was scheduled second
     227        $this->assertEquals( $ts2, wp_next_scheduled( $hook, $args ) );
    228228        wp_unschedule_event( $ts2, $hook, $args );
     229        // following event at +30 minutes should be there too
     230        $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) );
     231    }
     232
     233    function test_not_duplicate_event_reversed() {
     234        // duplicate events far apart should work normally regardless of order
     235        $hook = rand_str();
     236        $args = array( rand_str() );
     237        $ts1 = strtotime( '+3 minutes' );
     238        $ts2 = strtotime( '+30 minutes' );
     239
     240        // first one works
     241        wp_schedule_single_event( $ts1, $hook, $args );
     242        // second works too
     243        wp_schedule_single_event( $ts2, $hook, $args );
     244
     245        // the next event should be at +3 minutes
     246        $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) );
     247        wp_unschedule_event( $ts1, $hook, $args );
    229248        // following event should be there too
    230         $this->assertEquals( $ts1, wp_next_scheduled($hook, $args) );
     249        $this->assertEquals( $ts2, wp_next_scheduled( $hook, $args ) );
    231250    }
    232251}
Note: See TracChangeset for help on using the changeset viewer.