You are here

private function RulesUnitTest::assertRule in Ultimate Cron 8.2

8 calls to RulesUnitTest::assertRule()
RulesUnitTest::testRules in tests/src/Unit/RulesUnitTest.php
RulesUnitTest::testRules1MinuteRange in tests/src/Unit/RulesUnitTest.php
RulesUnitTest::testRules2MinuteRange in tests/src/Unit/RulesUnitTest.php
RulesUnitTest::testRules2MinuteRangeWithOffset in tests/src/Unit/RulesUnitTest.php
RulesUnitTest::testRules5MinuteRange in tests/src/Unit/RulesUnitTest.php

... See full list

File

tests/src/Unit/RulesUnitTest.php, line 21

Class

RulesUnitTest
Tests Drupal\ultimate_cron\CronRule.

Namespace

Drupal\Tests\ultimate_cron\Unit

Code

private function assertRule($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";
    }

    #$parsed_rule = str_replace(" ", "\n", $cron->rebuildRule($cron->getIntervals()));
    $last_scheduled = $cron
      ->getLastSchedule();
    $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 = Crontab::shouldRun($options['rules'], strtotime($options['last_run']), strtotime($options['now']), $options['catch_up']);
  return array(
    $options['result'] == $result,
    implode('<br/>', $message),
  );
}