You are here

public function RollingIntervalTest::test2WeekInterval in Recurring Time Period 8

Tests a 2 week interval in UTC.

File

tests/src/Kernel/RollingIntervalTest.php, line 94

Class

RollingIntervalTest
Tests the rolling interval plugin.

Namespace

Drupal\Tests\recurring_period\Kernel

Code

public function test2WeekInterval() {
  $timezone_utc = new \DateTimeZone('UTC');

  /** @var RecurringPeriodInterface $plugin */
  $plugin = $this->recurringPeriodManager
    ->createInstance('rolling_interval', [
    'interval' => [
      'period' => 'week',
      'interval' => 2,
    ],
  ]);
  $start_date = new \DateTimeImmutable('2017-01-01T09:00:00', $timezone_utc);
  $expected_end_date = new \DateTimeImmutable('2017-01-15T09:00:00', $timezone_utc);
  $actual_end_date = $plugin
    ->calculateDate($start_date);
  $this
    ->assertEquals($expected_end_date, $actual_end_date);

  // The timestamp difference should be 14*86400 seconds.
  $expected_timestamp_diff = 14 * 86400;
  $actual_timestamp_diff = (int) $actual_end_date
    ->format('U') - (int) $start_date
    ->format('U');
  $this
    ->assertEquals($expected_timestamp_diff, $actual_timestamp_diff);
}