You are here

public function CommerceInvoiceTestCase::testOrderUpdateWithPendingInvoices in Commerce Invoice 7.2

Tests invoice behavior when orders were updated prior to payment.

File

tests/commerce_invoice.test, line 100
Functional tests for the commerce invoice module.

Class

CommerceInvoiceTestCase
Test commerce invoices.

Code

public function testOrderUpdateWithPendingInvoices() {

  // Create an order. Pending invoice will be created by rules.
  $order = $this
    ->createDummyOrder(1, [
    $this->product100->product_id => 2,
  ], 'pending');

  // Update the order.
  $this
    ->addLineItemToOrder($order);
  $invoices = commerce_invoice_load_for_order($order);

  // Old invoice should be cancelled.
  $oldInvoice = reset($invoices);
  $this
    ->assertEqual($oldInvoice->invoice_status, Invoice::STATUS_CANCELED, 'Cancel pending invoice after change of order.');

  // New invoice should have a pending status.
  $newInvoice = next($invoices);
  $this
    ->assertEqual($newInvoice->invoice_status, Invoice::STATUS_PENDING, 'Create a new pending invoice after change of order.');

  // The new invoice total should be $700.
  $total = $newInvoice
    ->wrapper()->commerce_invoice_total->amount
    ->value();
  $this
    ->assertEqual($total, 700, 'Updated invoice total properly calculated.');
}