public function RecurringOrderManagerTest::testStartTrialPrepaid in Commerce Recurring Framework 8
@covers ::startTrial @covers ::collectSubscriptions
File
- tests/
src/ Kernel/ RecurringOrderManagerTest.php, line 141
Class
- RecurringOrderManagerTest
- @coversDefaultClass \Drupal\commerce_recurring\RecurringOrderManager @group commerce_recurring
Namespace
Drupal\Tests\commerce_recurring\KernelCode
public function testStartTrialPrepaid() {
$this->billingSchedule
->setBillingType(BillingScheduleInterface::BILLING_TYPE_PREPAID);
$this->billingSchedule
->save();
$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();
$expected_order_item_billing_period = new BillingPeriod(new DrupalDateTime('2019-02-15 00:00:00'), new DrupalDateTime('2019-03-01 00:00'));
$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($expected_order_item_billing_period, $order_item_billing_period);
// The subscription started mid-cycle, the unit price should be
// half the usual due to proration.
$this
->assertEquals($this->trialSubscription
->getUnitPrice()
->divide('2'), $order_item
->getUnitPrice());
}