You are here

public function FixedTest::testGenerate in Commerce Recurring Framework 8

@covers ::generateFirstBillingPeriod @covers ::generateNextBillingPeriod

File

tests/src/Kernel/Plugin/Commerce/BillingSchedule/FixedTest.php, line 31

Class

FixedTest
Tests the fixed billing schedule.

Namespace

Drupal\Tests\commerce_recurring\Kernel\Plugin\Commerce\BillingSchedule

Code

public function testGenerate() {
  $plugin = new Fixed([
    'interval' => [
      'number' => '2',
      'unit' => 'hour',
    ],
  ], '', []);
  $start_date = new DrupalDateTime('2017-03-16 10:22:30');
  $billing_period = $plugin
    ->generateFirstBillingPeriod($start_date);
  $this
    ->assertEquals(new DrupalDateTime('2017-03-16 10:00:00'), $billing_period
    ->getStartDate());
  $this
    ->assertEquals(new DrupalDateTime('2017-03-16 12:00:00'), $billing_period
    ->getEndDate());
  $next_billing_period = $plugin
    ->generateNextBillingPeriod($start_date, $billing_period);
  $this
    ->assertEquals(new DrupalDateTime('2017-03-16 12:00:00'), $next_billing_period
    ->getStartDate());
  $this
    ->assertEquals(new DrupalDateTime('2017-03-16 14:00:00'), $next_billing_period
    ->getEndDate());
  $plugin = new Fixed([
    'interval' => [
      'number' => '1',
      'unit' => 'month',
    ],
  ], '', []);
  $start_date = new DrupalDateTime('2017-03-16 10:22:30');
  $billing_period = $plugin
    ->generateFirstBillingPeriod($start_date);
  $this
    ->assertEquals(new DrupalDateTime('2017-03-01 00:00:00'), $billing_period
    ->getStartDate());
  $this
    ->assertEquals(new DrupalDateTime('2017-04-01 00:00:00'), $billing_period
    ->getEndDate());
  $next_billing_period = $plugin
    ->generateNextBillingPeriod($start_date, $billing_period);
  $this
    ->assertEquals(new DrupalDateTime('2017-04-01 00:00:00'), $next_billing_period
    ->getStartDate());
  $this
    ->assertEquals(new DrupalDateTime('2017-05-01 00:00:00'), $next_billing_period
    ->getEndDate());
  $plugin = new Fixed([
    'interval' => [
      'number' => '1',
      'unit' => 'year',
    ],
  ], '', []);
  $start_date = new DrupalDateTime('2017-03-16 10:22:30');
  $billing_period = $plugin
    ->generateFirstBillingPeriod($start_date);
  $this
    ->assertEquals(new DrupalDateTime('2017-01-01 00:00:00'), $billing_period
    ->getStartDate());
  $this
    ->assertEquals(new DrupalDateTime('2018-01-01 00:00:00'), $billing_period
    ->getEndDate());
  $next_billing_period = $plugin
    ->generateNextBillingPeriod($start_date, $billing_period);
  $this
    ->assertEquals(new DrupalDateTime('2018-01-01 00:00:00'), $next_billing_period
    ->getStartDate());
  $this
    ->assertEquals(new DrupalDateTime('2019-01-01 00:00:00'), $next_billing_period
    ->getEndDate());
}