You are here

public function OrderRefreshTest::testRefresh in Commerce Recurring Framework 8

@covers ::process

File

tests/src/Kernel/OrderRefreshTest.php, line 34

Class

OrderRefreshTest
@coversDefaultClass \Drupal\commerce_recurring\RecurringOrderProcessor @group commerce_recurring

Namespace

Drupal\Tests\commerce_recurring\Kernel

Code

public function testRefresh() {
  $subscription = Subscription::create([
    'type' => 'product_variation',
    'store_id' => $this->store
      ->id(),
    'billing_schedule' => $this->billingSchedule,
    'uid' => $this->user,
    'payment_method' => $this->paymentMethod,
    'purchased_entity' => $this->variation,
    'title' => $this->variation
      ->getOrderItemTitle(),
    'unit_price' => new Price('2', 'USD'),
    'state' => 'active',
    'starts' => strtotime('2019-02-01 00:00'),
  ]);
  $subscription
    ->save();
  $order = $this->recurringOrderManager
    ->startRecurring($subscription);
  $this
    ->assertEquals(new Price('2', 'USD'), $order
    ->getTotalPrice());
  $subscription
    ->setUnitPrice(new Price('3', 'USD'));
  $subscription
    ->save();

  // Save the order to refresh it.
  $order
    ->save();
  $this
    ->assertEquals(new Price('3', 'USD'), $order
    ->getTotalPrice());

  // Confirm that the order is canceled on refresh if no charges remain.
  $this->billingSchedule
    ->setBillingType(BillingScheduleInterface::BILLING_TYPE_PREPAID);
  $this->billingSchedule
    ->save();
  $subscription
    ->cancel()
    ->save();
  $order
    ->save();
  $this
    ->assertEquals('canceled', $order
    ->getState()
    ->getId());
  $this
    ->assertEmpty($order
    ->getItems());
}