You are here

public function RecurringOrderManagerTest::testCloseOrderAlreadyPaidMarksTheOrderAsCompleted in Commerce Recurring Framework 8

@covers ::closeOrder

File

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

Class

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

Namespace

Drupal\Tests\commerce_recurring\Kernel

Code

public function testCloseOrderAlreadyPaidMarksTheOrderAsCompleted() {
  $order = $this->recurringOrderManager
    ->startRecurring($this->activeSubscription);

  // We set the total paid to the amount of the order, but don't set the order
  // as complete.
  $order
    ->set('total_paid', $order
    ->getTotalPrice())
    ->set('state', 'needs_payment')
    ->save();
  $order = $this
    ->reloadEntity($order);
  $this
    ->assertEquals('needs_payment', $order
    ->getState()
    ->getId());
  $this
    ->assertTrue($order
    ->isPaid());

  // We close an order that was already completed.
  $this->recurringOrderManager
    ->closeOrder($order);
  $order = $this
    ->reloadEntity($order);
  $this
    ->assertTrue($order
    ->isPaid());
  $this
    ->assertEquals('completed', $order
    ->getState()
    ->getId());

  /** @var \Drupal\commerce_payment\PaymentStorageInterface $payment_storage */
  $payment_storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('commerce_payment');

  // No extra payment has been added.
  $payments = $payment_storage
    ->loadMultipleByOrder($order);
  $this
    ->assertCount(0, $payments);
}