You are here

class UltimateCronRulesUnitTestCase in Ultimate Cron 7

Same name and namespace in other branches
  1. 8 tests/rules.test \UltimateCronRulesUnitTestCase
  2. 6 tests/rules.test \UltimateCronRulesUnitTestCase
  3. 7.2 tests/rules.test \UltimateCronRulesUnitTestCase

@file

Tests for Ultimate Cron's cron parser

Hierarchy

Expanded class hierarchy of UltimateCronRulesUnitTestCase

File

tests/rules.test, line 8
Tests for Ultimate Cron's cron parser

View source
class UltimateCronRulesUnitTestCase extends DrupalUnitTestCase {
  function setUp() {
    parent::setUp('ultimate_cron');
    module_load_include('module', 'ultimate_cron');
  }
  public static function getInfo() {
    return array(
      'name' => 'Rules',
      'description' => 'Test crontab rules parser.',
      'group' => 'Cron',
    );
  }
  private function getIntervals($rule) {

    // Generate result message
    require_once dirname(__FILE__) . '/../CronRule.class.php';
    $message = array();
    $cron = new CronRule($rule);
    return $cron
      ->getIntervals();
  }
  private function runTest($options) {

    // Setup values
    $options['rules'] = is_array($options['rules']) ? $options['rules'] : array(
      $options['rules'],
    );
    $options['catch_up'] = isset($options['catch_up']) ? $options['catch_up'] : 86400 * 365;

    // @todo Adapting Elysia Cron test cases with a catchup of 1 year
    // Generate result message
    require_once dirname(__FILE__) . '/../CronRule.class.php';
    $message = array();
    foreach ($options['rules'] as $rule) {
      $cron = new CronRule($rule);
      $intervals = $cron
        ->getIntervals();
      $parsed_rule = '';
      foreach ($intervals as $key => $value) {
        $parsed_rule .= "{$key}: " . implode(',', $value) . "\n";
      }

      #$parsed_rule = str_replace(" ", "\n", $cron->rebuildRule($cron->getIntervals()));
      $last_scheduled = $cron
        ->getLastRan(strtotime($options['now']));
      $message[] = "<span title=\"{$parsed_rule}\">{$rule}</span> @ " . date('Y-m-d H:i:s', $last_scheduled);
    }
    $message[] = 'now      @ ' . $options['now'];
    $message[] = 'last-run @ ' . $options['last_run'];
    $message[] = 'catch-up @ ' . $options['catch_up'];
    $message[] = ($options['result'] ? '' : 'not ') . 'expected to run';

    // Do the actual test
    $result = ultimate_cron_should_run($options['rules'], strtotime($options['last_run']), strtotime($options['now']), $options['catch_up']);
    return array(
      $options['result'] == $result,
      implode('<br/>', $message),
    );
  }
  function testIntervals2MinuteRange() {
    $intervals = $this
      ->getIntervals('10-11 12 * * *');
    $this
      ->assertEqual($intervals['minutes'], range(11, 10, -1), 'Expected minutes to be 10, 11');
    $intervals = $this
      ->getIntervals('0-1 12 * * *');
    $this
      ->assertEqual($intervals['minutes'], range(1, 0, -1), 'Expected minutes to be 0, 1');
    $intervals = $this
      ->getIntervals('58-59 12 * * *');
    $this
      ->assertEqual($intervals['minutes'], range(59, 58, -1), 'Expected minutes to be 58, 59');
  }
  function testIntervals2MinuteRangeWithOffset() {
    $intervals = $this
      ->getIntervals('0-1+1 12 * * *');
    $this
      ->assertEqual($intervals['minutes'], range(2, 1, -1), 'Expected minutes to be 1, 2');
    $intervals = $this
      ->getIntervals('10-11+1 12 * * *');
    $this
      ->assertEqual($intervals['minutes'], range(12, 11, -1), 'Expected minutes to be 11, 12');

    // Note, this test is testing for correct behaviour when the minutes wrap around
    // Previously, this test would generate 43, 0 due to a bug in expandRange/expandInterval
    $intervals = $this
      ->getIntervals('42-43+1 12 * * *');
    $this
      ->assertEqual($intervals['minutes'], array(
      44,
      43,
    ), 'Expected minutes to be 43, 44');

    // Note, this test is testing for correct behaviour when the minutes wrap around
    $intervals = $this
      ->getIntervals('58-59+1 12 * * *');
    $this
      ->assertEqual($intervals['minutes'], array(
      59,
      0,
    ), 'Expected minutes to be 59, 0');
  }
  function testIntervalsSpecificMinute() {
    $intervals = $this
      ->getIntervals('0 12 * * *');
    $this
      ->assertEqual($intervals['minutes'], array(
      0,
    ), 'Expected minutes to be 0');
    $intervals = $this
      ->getIntervals('10 12 * * *');
    $this
      ->assertEqual($intervals['minutes'], array(
      10,
    ), 'Expected minutes to be 10');
    $intervals = $this
      ->getIntervals('59 12 * * *');
    $this
      ->assertEqual($intervals['minutes'], array(
      59,
    ), 'Expected minutes to be 59');
  }
  function testRules() {
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '0 12 * * *',
      'last_run' => '2008-01-02 12:00:00',
      'now' => '2008-01-02 12:01:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '0 12 * * *',
      'last_run' => '2008-01-02 12:00:00',
      'now' => '2008-01-02 15:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '0 12 * * *',
      'last_run' => '2008-01-02 12:00:00',
      'now' => '2008-01-03 11:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '0 12 * * *',
      'last_run' => '2008-01-02 12:00:00',
      'now' => '2008-01-03 12:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59 23 * * *',
      'last_run' => '2008-01-02 23:59:00',
      'now' => '2008-01-03 00:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 * * *',
      'last_run' => '2008-01-02 23:59:00',
      'now' => '2008-01-03 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 * * *',
      'last_run' => '2008-01-02 23:59:00',
      'now' => '2008-01-04 00:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 * * *',
      'last_run' => '2008-01-02 23:58:00',
      'now' => '2008-01-02 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 * * *',
      'last_run' => '2008-01-02 23:58:00',
      'now' => '2008-01-03 00:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59 23 * * 0',
      'last_run' => '2008-01-05 23:58:00',
      'now' => '2008-01-05 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59 23 * * 0',
      'last_run' => '2008-01-05 23:58:00',
      'now' => '2008-01-06 00:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 * * 0',
      'last_run' => '2008-01-05 23:58:00',
      'now' => '2008-01-06 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 * * 0',
      'last_run' => '2008-01-05 23:58:00',
      'now' => '2008-01-07 00:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '29,59 23 * * 0',
      'last_run' => '2008-01-05 23:58:00',
      'now' => '2008-01-06 23:29:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '29,59 23 * * 0',
      'last_run' => '2008-01-05 23:58:00',
      'now' => '2008-01-06 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '29,59 23 * * 0',
      'last_run' => '2008-01-05 23:58:00',
      'now' => '2008-01-05 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '29,59 23 * * 0',
      'last_run' => '2008-01-05 23:58:00',
      'now' => '2008-01-06 23:58:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '29,59 23 * * 0',
      'last_run' => '2008-01-05 23:58:00',
      'now' => '2008-01-06 23:28:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '29,59 23 * * 0',
      'last_run' => '2008-01-05 23:28:00',
      'now' => '2008-01-05 23:29:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '29,59 23 * * 0',
      'last_run' => '2008-01-05 23:28:00',
      'now' => '2008-01-05 23:30:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '29,59 23 * * 0',
      'last_run' => '2008-01-05 23:28:00',
      'now' => '2008-01-05 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '29,59 23 * * 0',
      'last_run' => '2008-01-05 23:28:00',
      'now' => '2008-01-06 23:29:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '29,59 23 * * 5',
      'last_run' => '2008-02-22 23:59:00',
      'now' => '2008-02-28 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '29,59 23 * * 5',
      'last_run' => '2008-02-22 23:59:00',
      'now' => '2008-02-29 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '29,59 23 * * 5',
      'last_run' => '2008-02-22 23:59:00',
      'now' => '2008-03-01 00:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59 23 * * 3',
      'last_run' => '2008-12-31 23:59:00',
      'now' => '2009-01-01 00:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59 23 * * 3',
      'last_run' => '2008-12-31 23:59:00',
      'now' => '2009-01-07 00:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 * * 3',
      'last_run' => '2008-12-31 23:59:00',
      'now' => '2009-01-07 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 * 2 5',
      'last_run' => '2008-02-22 23:59:00',
      'now' => '2008-02-29 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 * 2 5',
      'last_run' => '2008-02-22 23:59:00',
      'now' => '2008-03-01 00:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59 23 * 2 5',
      'last_run' => '2008-02-29 23:59:00',
      'now' => '2008-03-07 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59 23 * 2 5',
      'last_run' => '2008-02-29 23:59:00',
      'now' => '2009-02-06 23:58:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 * 2 5',
      'last_run' => '2008-02-29 23:59:00',
      'now' => '2009-02-06 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59 23 */10 * *',
      'last_run' => '2008-01-10 23:58:00',
      'now' => '2008-01-10 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 */10 * *',
      'last_run' => '2008-01-10 23:59:00',
      'now' => '2008-01-11 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 */10 * *',
      'last_run' => '2008-01-10 23:59:00',
      'now' => '2008-01-20 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 1-5,10-15 * *',
      'last_run' => '2008-01-04 23:59:00',
      'now' => '2008-01-05 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 1-5,10-15 * *',
      'last_run' => '2008-01-04 23:59:00',
      'now' => '2008-01-06 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59 23 1-5,10-15 * *',
      'last_run' => '2008-01-05 23:59:00',
      'now' => '2008-01-06 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59 23 1-5,10-15 * *',
      'last_run' => '2008-01-05 23:59:00',
      'now' => '2008-01-10 23:58:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 1-5,10-15 * *',
      'last_run' => '2008-01-05 23:59:00',
      'now' => '2008-01-10 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 1-5,10-15 * *',
      'last_run' => '2008-01-05 23:59:00',
      'now' => '2008-01-16 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 1-5 1 0',
      'last_run' => '2008-01-04 23:59:00',
      'now' => '2008-01-05 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 1-5 1 0',
      'last_run' => '2008-01-05 23:59:00',
      'now' => '2008-01-06 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59 23 1-5 1 0',
      'last_run' => '2008-01-06 23:59:00',
      'now' => '2008-01-07 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59 23 1-5 1 0',
      'last_run' => '2008-01-06 23:59:00',
      'now' => '2008-01-13 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59 23 1-5 1 0',
      'last_run' => '2008-02-04 23:59:00',
      'now' => '2008-02-05 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59 23 1-5 1 0',
      'last_run' => '2008-02-05 23:59:00',
      'now' => '2008-02-10 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59 23 1-5 1 0',
      'last_run' => '2008-02-10 23:59:00',
      'now' => '2008-02-17 23:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *',
      'last_run' => '2008-02-10 08:58:00',
      'now' => '2008-02-10 08:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *',
      'last_run' => '2008-02-10 08:59:00',
      'now' => '2008-02-10 09:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *',
      'last_run' => '2008-02-10 08:59:00',
      'now' => '2008-02-10 17:59:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *',
      'last_run' => '2008-02-10 08:59:00',
      'now' => '2008-02-10 18:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *',
      'last_run' => '2008-02-10 18:00:00',
      'now' => '2008-02-10 18:01:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *',
      'last_run' => '2008-02-10 18:00:00',
      'now' => '2008-02-10 19:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '* 0,1,2,3,4,5,6,7,8,18,19,20,21,22,23 * * *',
      'last_run' => '2008-02-10 18:00:00',
      'now' => '2008-03-10 09:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
  }
  function testRules1MinuteRange() {

    // Test a 1 minute range
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '10-10 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:09:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '10-10 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:10:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '10-10 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:11:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
  }
  function testRules2MinuteRange() {

    // Test a 1 minute range
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '10-11 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:09:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '10-11 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:10:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '10-11 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:11:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '10-11 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:12:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
  }
  function testRules2MinuteRangeWithOffset() {

    // Test a 1 minute range
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '10-11+1 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:10:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '10-11+1 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:11:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '10-11+1 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:12:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '10-11+1 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:13:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
  }
  function testRules5MinuteRange() {

    // Test a 5 minute range
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '10-15 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:09:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '10-15 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:10:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '10-15 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:11:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '10-15 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:12:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '10-15 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:13:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '10-15 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:14:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '10-15 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:15:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);

    // This should not run, as it last ran one minute ago
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '10-15 12 * * *',
      'last_run' => '2008-01-03 12:15:00',
      'now' => '2008-01-03 12:16:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);

    // This should run, as catch_up defaults to 1 year and it last ran 16 minutes ago.
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '10-15 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:16:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
  }
  function testRules5MinuteStep() {

    // Test a 5 minute step
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '*/5 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:01:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '*/5 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:02:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '*/5 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:03:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '*/5 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:04:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '*/5 12 * * *',
      'last_run' => '2008-01-03 12:00:00',
      'now' => '2008-01-03 12:05:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
  }
  function testRulesExtended() {
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '0 0 * jan,oct *',
      'last_run' => '2008-01-31 00:00:00',
      'now' => '2008-03-10 09:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '0 0 * jan,oct *',
      'last_run' => '2008-01-31 00:00:00',
      'now' => '2008-10-01 00:00:00',
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
  }
  function testRulesMinuteWithOffset() {

    // Test a 1 minute range
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '10+1 12 * * *',
      'last_run' => '2008-01-01 12:00:00',
      'now' => '2008-01-03 12:10:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '10+1 12 * * *',
      'last_run' => '2008-01-01 12:00:00',
      'now' => '2008-01-03 12:11:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '10+1 12 * * *',
      'last_run' => '2008-01-01 12:00:00',
      'now' => '2008-01-03 12:12:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59+1 12 * * *',
      'last_run' => '2008-01-01 12:00:00',
      'now' => '2008-01-03 12:59:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => TRUE,
      'rules' => '59+1 12 * * *',
      'last_run' => '2008-01-01 12:00:00',
      'now' => '2008-01-03 12:00:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59+1 12 * * *',
      'last_run' => '2008-01-01 12:00:00',
      'now' => '2008-01-03 13:00:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
    $result = $this
      ->runTest(array(
      'result' => FALSE,
      'rules' => '59+1 12 * * *',
      'last_run' => '2008-01-01 12:00:00',
      'now' => '2008-01-03 13:01:00',
      'catch_up' => 1,
    ));
    $this
      ->assertTRUE($result[0], $result[1]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalUnitTestCase::tearDown protected function 1
DrupalUnitTestCase::__construct function Constructor for DrupalUnitTestCase. Overrides DrupalTestCase::__construct
UltimateCronRulesUnitTestCase::getInfo public static function
UltimateCronRulesUnitTestCase::getIntervals private function
UltimateCronRulesUnitTestCase::runTest private function
UltimateCronRulesUnitTestCase::setUp function Sets up unit test environment. Overrides DrupalUnitTestCase::setUp
UltimateCronRulesUnitTestCase::testIntervals2MinuteRange function
UltimateCronRulesUnitTestCase::testIntervals2MinuteRangeWithOffset function
UltimateCronRulesUnitTestCase::testIntervalsSpecificMinute function
UltimateCronRulesUnitTestCase::testRules function
UltimateCronRulesUnitTestCase::testRules1MinuteRange function
UltimateCronRulesUnitTestCase::testRules2MinuteRange function
UltimateCronRulesUnitTestCase::testRules2MinuteRangeWithOffset function
UltimateCronRulesUnitTestCase::testRules5MinuteRange function
UltimateCronRulesUnitTestCase::testRules5MinuteStep function
UltimateCronRulesUnitTestCase::testRulesExtended function
UltimateCronRulesUnitTestCase::testRulesMinuteWithOffset function