You are here

private function UltimateCronRulesUnitTestCase::runTestNext in Ultimate Cron 7.2

1 call to UltimateCronRulesUnitTestCase::runTestNext()
UltimateCronRulesUnitTestCase::testNextSchedule in tests/rules.test

File

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

Class

UltimateCronRulesUnitTestCase
@file

Code

private function runTestNext($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
  $message = array();
  foreach ($options['rules'] as $rule) {
    $cron = CronRule::factory($rule, strtotime($options['now']));
    $intervals = $cron
      ->getIntervals();
    $parsed_rule = '';
    foreach ($intervals as $key => $value) {
      $parsed_rule .= "{$key}: " . implode(',', $value) . "\n";
    }
    $last_scheduled = $cron
      ->getLastSchedule();
    $message[] = "<span title=\"{$parsed_rule}\">{$rule}</span> @ " . date('Y-m-d H:i:s', $last_scheduled);
    $start = microtime(TRUE);
    $time = $cron
      ->getNextSchedule();
    $end = microtime(TRUE);
    $next_schedule = !isset($next_schedule) || $time < $next_schedule ? $time : $next_schedule;
  }
  $message[] = 'now      @ ' . $options['now'];
  $message[] = 'catch-up @ ' . $options['catch_up'];
  $message[] = ($options['result'] ? '' : 'not ') . 'expected to run';
  $result = date('Y-m-d H:i:s', $next_schedule);
  return array(
    $options['result'] == $result,
    implode('<br/>', $message),
  );
}