You are here

public function RecurringOrderManagerTest::testRefreshOrder in Commerce Recurring Framework 8

@covers ::refreshOrder

File

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

Class

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

Namespace

Drupal\Tests\commerce_recurring\Kernel

Code

public function testRefreshOrder() {
  $order = $this->recurringOrderManager
    ->startRecurring($this->activeSubscription);
  $order_items = $order
    ->getItems();
  $order_item = reset($order_items);
  $previous_order_item_id = $order_item
    ->id();
  $this->activeSubscription
    ->set('payment_method', NULL);
  $this->activeSubscription
    ->setUnitPrice(new Price('3', 'USD'));
  $this->activeSubscription
    ->save();
  $this->recurringOrderManager
    ->refreshOrder($order);
  $this
    ->assertEmpty($order
    ->get('billing_profile')->target_id);
  $this
    ->assertEmpty($order
    ->get('payment_method')->target_id);
  $this
    ->assertEmpty($order
    ->get('payment_gateway')->target_id);
  $order_items = $order
    ->getItems();
  $order_item = reset($order_items);
  $this
    ->assertEquals($previous_order_item_id, $order_item
    ->id());
  $this
    ->assertEquals($this->activeSubscription
    ->getUnitPrice()
    ->divide('2'), $order_item
    ->getUnitPrice());

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