Squashed 'libraries/action-scheduler/' content from commit a95f351
git-subtree-dir: libraries/action-scheduler git-subtree-split: a95f351058eada5e5281faa22e5a40865542e839
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class ActionScheduler_CronSchedule_Test
|
||||
* @group schedules
|
||||
*/
|
||||
class ActionScheduler_CronSchedule_Test extends ActionScheduler_UnitTestCase {
|
||||
public function test_creation() {
|
||||
$time = as_get_datetime_object( 'tomorrow' );
|
||||
$cron = CronExpression::factory( '@daily' );
|
||||
$start = clone $time;
|
||||
$start->modify( '-1 hour' );
|
||||
$schedule = new ActionScheduler_CronSchedule( $start, $cron );
|
||||
$this->assertEquals( $time, $schedule->get_date() );
|
||||
$this->assertEquals( $start, $schedule->get_first_date() );
|
||||
|
||||
// Test delaying for a future start date.
|
||||
$start->modify( '+1 week' );
|
||||
$time->modify( '+1 week' );
|
||||
|
||||
$schedule = new ActionScheduler_CronSchedule( $start, $cron );
|
||||
$this->assertEquals( $time, $schedule->get_date() );
|
||||
$this->assertEquals( $start, $schedule->get_first_date() );
|
||||
}
|
||||
|
||||
public function test_creation_with_first_date() {
|
||||
$time = as_get_datetime_object( 'tomorrow' );
|
||||
$cron = CronExpression::factory( '@daily' );
|
||||
$start = clone $time;
|
||||
$start->modify( '-1 hour' );
|
||||
$schedule = new ActionScheduler_CronSchedule( $start, $cron );
|
||||
$this->assertEquals( $time, $schedule->get_date() );
|
||||
$this->assertEquals( $start, $schedule->get_first_date() );
|
||||
|
||||
// Test delaying for a future start date.
|
||||
$first = clone $time;
|
||||
$first->modify( '-1 day' );
|
||||
$start->modify( '+1 week' );
|
||||
$time->modify( '+1 week' );
|
||||
|
||||
$schedule = new ActionScheduler_CronSchedule( $start, $cron, $first );
|
||||
$this->assertEquals( $time, $schedule->get_date() );
|
||||
$this->assertEquals( $first, $schedule->get_first_date() );
|
||||
}
|
||||
|
||||
public function test_next() {
|
||||
$time = as_get_datetime_object( '2013-06-14' );
|
||||
$cron = CronExpression::factory( '@daily' );
|
||||
$schedule = new ActionScheduler_CronSchedule( $time, $cron );
|
||||
$this->assertEquals( as_get_datetime_object( 'tomorrow' ), $schedule->get_next( as_get_datetime_object() ) );
|
||||
}
|
||||
|
||||
public function test_is_recurring() {
|
||||
$schedule = new ActionScheduler_CronSchedule( as_get_datetime_object( '2013-06-14' ), CronExpression::factory( '@daily' ) );
|
||||
$this->assertTrue( $schedule->is_recurring() );
|
||||
}
|
||||
|
||||
public function test_cron_format() {
|
||||
$time = as_get_datetime_object( '2014-01-01' );
|
||||
$cron = CronExpression::factory( '0 0 10 10 *' );
|
||||
$schedule = new ActionScheduler_CronSchedule( $time, $cron );
|
||||
$this->assertEquals( as_get_datetime_object( '2014-10-10' ), $schedule->get_date() );
|
||||
|
||||
$cron = CronExpression::factory( '0 0 L 1/2 *' );
|
||||
$schedule = new ActionScheduler_CronSchedule( $time, $cron );
|
||||
$this->assertEquals( as_get_datetime_object( '2014-01-31' ), $schedule->get_date() );
|
||||
$this->assertEquals( as_get_datetime_object( '2014-07-31' ), $schedule->get_next( as_get_datetime_object( '2014-06-01' ) ) );
|
||||
$this->assertEquals( as_get_datetime_object( '2028-11-30' ), $schedule->get_next( as_get_datetime_object( '2028-11-01' ) ) );
|
||||
|
||||
$cron = CronExpression::factory( '30 14 * * MON#3 *' );
|
||||
$schedule = new ActionScheduler_CronSchedule( $time, $cron );
|
||||
$this->assertEquals( as_get_datetime_object( '2014-01-20 14:30:00' ), $schedule->get_date() );
|
||||
$this->assertEquals( as_get_datetime_object( '2014-05-19 14:30:00' ), $schedule->get_next( as_get_datetime_object( '2014-05-01' ) ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class ActionScheduler_IntervalSchedule_Test
|
||||
* @group schedules
|
||||
*/
|
||||
class ActionScheduler_IntervalSchedule_Test extends ActionScheduler_UnitTestCase {
|
||||
public function test_creation() {
|
||||
$time = as_get_datetime_object();
|
||||
$schedule = new ActionScheduler_IntervalSchedule( $time, HOUR_IN_SECONDS );
|
||||
$this->assertEquals( $time, $schedule->get_date() );
|
||||
$this->assertEquals( $time, $schedule->get_first_date() );
|
||||
}
|
||||
|
||||
public function test_creation_with_first_date() {
|
||||
$first = as_get_datetime_object();
|
||||
$time = as_get_datetime_object( '+12 hours' );
|
||||
$schedule = new ActionScheduler_IntervalSchedule( $time, HOUR_IN_SECONDS, $first );
|
||||
$this->assertEquals( $time, $schedule->get_date() );
|
||||
$this->assertEquals( $first, $schedule->get_first_date() );
|
||||
}
|
||||
|
||||
public function test_next() {
|
||||
$now = time();
|
||||
$start = $now - 30;
|
||||
$schedule = new ActionScheduler_IntervalSchedule( as_get_datetime_object( "@$start" ), MINUTE_IN_SECONDS );
|
||||
$this->assertEquals( $start, $schedule->get_date()->getTimestamp() );
|
||||
$this->assertEquals( $now + MINUTE_IN_SECONDS, $schedule->get_next( as_get_datetime_object() )->getTimestamp() );
|
||||
$this->assertEquals( $start, $schedule->get_next( as_get_datetime_object( "@$start" ) )->getTimestamp() );
|
||||
}
|
||||
|
||||
public function test_is_recurring() {
|
||||
$start = time() - 30;
|
||||
$schedule = new ActionScheduler_IntervalSchedule( as_get_datetime_object( "@$start" ), MINUTE_IN_SECONDS );
|
||||
$this->assertTrue( $schedule->is_recurring() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class ActionScheduler_NullSchedule_Test
|
||||
* @group schedules
|
||||
*/
|
||||
class ActionScheduler_NullSchedule_Test extends ActionScheduler_UnitTestCase {
|
||||
public function test_null_schedule() {
|
||||
$schedule = new ActionScheduler_NullSchedule();
|
||||
$this->assertNull( $schedule->get_date() );
|
||||
}
|
||||
|
||||
public function test_is_recurring() {
|
||||
$schedule = new ActionScheduler_NullSchedule();
|
||||
$this->assertFalse( $schedule->is_recurring() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class ActionScheduler_SimpleSchedule_Test
|
||||
* @group schedules
|
||||
*/
|
||||
class ActionScheduler_SimpleSchedule_Test extends ActionScheduler_UnitTestCase {
|
||||
public function test_creation() {
|
||||
$time = as_get_datetime_object();
|
||||
$schedule = new ActionScheduler_SimpleSchedule( $time );
|
||||
$this->assertEquals( $time, $schedule->get_date() );
|
||||
}
|
||||
|
||||
public function test_past_date() {
|
||||
$time = as_get_datetime_object( '-1 day' );
|
||||
$schedule = new ActionScheduler_SimpleSchedule( $time );
|
||||
$this->assertEquals( $time, $schedule->get_date() );
|
||||
}
|
||||
|
||||
public function test_future_date() {
|
||||
$time = as_get_datetime_object( '+1 day' );
|
||||
$schedule = new ActionScheduler_SimpleSchedule( $time );
|
||||
$this->assertEquals( $time, $schedule->get_date() );
|
||||
}
|
||||
|
||||
public function test_grace_period_for_next() {
|
||||
$time = as_get_datetime_object( '3 seconds ago' );
|
||||
$schedule = new ActionScheduler_SimpleSchedule( $time );
|
||||
$this->assertEquals( $time, $schedule->get_date() );
|
||||
}
|
||||
|
||||
public function test_is_recurring() {
|
||||
$schedule = new ActionScheduler_SimpleSchedule( as_get_datetime_object( '+1 day' ) );
|
||||
$this->assertFalse( $schedule->is_recurring() );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user