View source
<?php
namespace Drupal\Tests\recurring_period\Kernel;
use Drupal\recurring_period\Plugin\RecurringPeriod\RecurringPeriodInterface;
class FixedReferenceDateIntervalTest extends RecurringPeriodTestBase {
public function testFixedIntervalPlugin($timezone_name, $reference_date, $interval, $start_date, $expected_next, $expected_start) {
$timezone = new \DateTimeZone($timezone_name);
$plugin = $this->recurringPeriodManager
->createInstance('fixed_reference_date_interval', [
'reference_date' => $reference_date,
'interval' => $interval,
]);
$start_date = new \DateTimeImmutable($start_date, $timezone);
$expected_end_date = new \DateTimeImmutable($expected_next, $timezone);
$this
->assertEquals($expected_end_date, $plugin
->calculateDate($start_date));
$expected_start_date = new \DateTimeImmutable($expected_start, $timezone);
$this
->assertEquals($expected_start_date, $plugin
->calculateStart($start_date));
}
public function testFixedIntervalPluginProvider() {
return [
'annual recurring, due later this year' => [
'Europe/London',
'1970-12-25',
[
'period' => 'year',
'interval' => 1,
],
'2017-07-01T00:00:00',
'2017-12-25T00:00:00',
'2016-12-25T00:00:00',
],
'annual recurring, due next year' => [
'Europe/London',
'1970-01-01',
[
'period' => 'year',
'interval' => 1,
],
'2017-07-01T00:00:00',
'2018-01-01T00:00:00',
'2017-01-01T00:00:00',
],
'annual recurring, entire year left' => [
'Europe/London',
'2025-01-01',
[
'period' => 'year',
'interval' => 1,
],
'2017-01-01T00:00:00',
'2018-01-01T00:00:00',
'2017-01-01T00:00:00',
],
];
}
}