public function RecurringOrderManagerTest::testStartRecurringPrepaid in Commerce Recurring Framework 8
@covers ::startRecurring @covers ::collectSubscriptions
File
- tests/
src/ Kernel/ RecurringOrderManagerTest.php, line 228
Class
- RecurringOrderManagerTest
- @coversDefaultClass \Drupal\commerce_recurring\RecurringOrderManager @group commerce_recurring
Namespace
Drupal\Tests\commerce_recurring\KernelCode
public function testStartRecurringPrepaid() {
$this->billingSchedule
->setBillingType(BillingScheduleInterface::BILLING_TYPE_PREPAID);
$this->billingSchedule
->save();
$order = $this->recurringOrderManager
->startRecurring($this->activeSubscription);
$expected_billing_period = new BillingPeriod(new DrupalDateTime('2019-02-01 00:00:00'), new DrupalDateTime('2019-03-01 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
->assertEquals($billing_period
->getEndDate()
->getTimestamp(), $this->activeSubscription
->getNextRenewalTime());
// Confirm that the current billing period is 28 days long.
$this
->assertEquals(2419200, $billing_period
->getDuration());
$this
->assertTrue($this->activeSubscription
->hasOrder($order));
$this
->assertEmpty($this->activeSubscription
->getRenewedTime());
$this
->assertOrder($order, $this->activeSubscription);
$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-03-01 00:00:00'), new DrupalDateTime('2019-04-01 00:00'));
$this
->assertEquals('recurring_product_variation', $order_item
->bundle());
$this
->assertEquals($this->activeSubscription
->id(), $order_item
->get('subscription')->target_id);
$this
->assertEquals($this->activeSubscription
->getTitle(), $order_item
->getTitle());
$this
->assertEquals($this->activeSubscription
->getQuantity(), $order_item
->getQuantity());
$this
->assertEquals($this->activeSubscription
->getPurchasedEntityId(), $order_item
->getPurchasedEntityId());
$this
->assertEquals($expected_order_item_billing_period, $order_item_billing_period);
// The order item is charging for the next billing period, the unit price
// should not be prorated.
$this
->assertEquals($this->activeSubscription
->getUnitPrice(), $order_item
->getUnitPrice());
}