You are here

public function RecurringOrderManagerTest::testStartTrialPostpaid in Commerce Recurring Framework 8

@covers ::startTrial @covers ::collectSubscriptions

File

tests/src/Kernel/RecurringOrderManagerTest.php, line 109

Class

RecurringOrderManagerTest
@coversDefaultClass \Drupal\commerce_recurring\RecurringOrderManager @group commerce_recurring

Namespace

Drupal\Tests\commerce_recurring\Kernel

Code

public function testStartTrialPostpaid() {
  $order = $this->recurringOrderManager
    ->startTrial($this->trialSubscription);
  $expected_billing_period = new BillingPeriod(new DrupalDateTime('2019-02-05 00:00:00'), new DrupalDateTime('2019-02-15 00:00:00'));

  /** @var \Drupal\commerce_recurring\Plugin\Field\FieldType\BillingPeriodItem $billing_period_item */
  $billing_period_item = $order
    ->get('billing_period')
    ->first();
  $billing_period = $billing_period_item
    ->toBillingPeriod();
  $this
    ->assertEquals($expected_billing_period, $billing_period);
  $this
    ->assertTrue($this->trialSubscription
    ->hasOrder($order));
  $this
    ->assertEmpty($this->trialSubscription
    ->getRenewedTime());
  $this
    ->assertEmpty($this->trialSubscription
    ->getNextRenewalTime());
  $this
    ->assertOrder($order, $this->trialSubscription);
  $this
    ->assertTrue($order
    ->hasItems());
  $order_items = $order
    ->getItems();
  $order_item = reset($order_items);

  /** @var \Drupal\commerce_recurring\Plugin\Field\FieldType\BillingPeriodItem $order_item_billing_period_item */
  $order_item_billing_period_item = $order_item
    ->get('billing_period')
    ->first();
  $order_item_billing_period = $order_item_billing_period_item
    ->toBillingPeriod();
  $this
    ->assertEquals('recurring_product_variation', $order_item
    ->bundle());
  $this
    ->assertEquals($this->trialSubscription
    ->id(), $order_item
    ->get('subscription')->target_id);
  $this
    ->assertEquals($this->trialSubscription
    ->getTitle(), $order_item
    ->getTitle());
  $this
    ->assertEquals($this->trialSubscription
    ->getQuantity(), $order_item
    ->getQuantity());
  $this
    ->assertEquals($this->trialSubscription
    ->getPurchasedEntityId(), $order_item
    ->getPurchasedEntityId());
  $this
    ->assertEquals($billing_period, $order_item_billing_period);
  $this
    ->assertTrue($order_item
    ->getTotalPrice()
    ->isZero());
}