You are here

public function CommerceMigrateTestCase::testOrder in Commerce Migrate 7

Tests integrity of an order.

Parameters

string $order_number: Order number.

1 call to CommerceMigrateTestCase::testOrder()
CommerceMigrateTestCase::testRollback in tests/commerce_migrate_tests.test
Tests of removing imported data.

File

tests/commerce_migrate_tests.test, line 30
Tests of "Commerce Migrate".

Class

CommerceMigrateTestCase
Class CommerceMigrateTestCase.

Code

public function testOrder($order_number = 'EXAMPLE-ORDER-1') {
  $order = $this
    ->getOrder($order_number);
  $raw_order = $this
    ->getOrdersCsvItem($order_number);
  $line_items = array(
    'products' => array(),
    'shipping' => array(),
  );
  $amount = array(
    'total' => array(
      'products' => 0,
      'shipping' => 0,
    ),
    'expected' => array(
      'products' => 0,
      'shipping' => 0,
    ),
  );
  foreach ($order->commerce_line_items as $line_item_wrapper) {
    if (isset($line_item_wrapper->commerce_product)) {
      $raw_product = $this
        ->getProductsCsvItem($line_item_wrapper->commerce_product->sku
        ->value());
      $line_items['products'][] = $line_item_wrapper;
      $amount['total']['products'] += $line_item_wrapper->commerce_total->amount
        ->value();
      $amount['expected']['products'] += $line_item_wrapper->quantity
        ->value() * commerce_currency_decimal_to_amount($raw_product->price, $raw_product->currency_code);
    }
    if ('shipping' === $line_item_wrapper->type
      ->value()) {
      $line_items['shipping'][] = $line_item_wrapper;
      $amount['total']['shipping'] += $line_item_wrapper->commerce_total->amount
        ->value();
    }
  }

  // We migrate line items of two types: "product" and "shipping". So,
  // to get the total price of "shipping" line items, we need subtract
  // products cost from total cost.
  $amount['expected']['shipping'] += $order->commerce_order_total->amount
    ->value() - $amount['total']['products'];

  // Check that expected prices are equal to what we have.
  foreach (array_keys($line_items) as $item) {
    $this
      ->assertEqual($amount['total'][$item], $amount['expected'][$item], "{$item} prices are correct.");
  }
  foreach (array(
    'mail',
    'status',
    'hostname',
  ) as $item) {
    $this
      ->assertIdentical($raw_order->{$item}, $order->{$item}
      ->value(), "An order has correct {$item}.");
  }
}