You are here

public function CommerceMigrateTestTrait::assertOrder in Commerce Migrate 8.2

Same name and namespace in other branches
  1. 3.1.x tests/src/Kernel/CommerceMigrateTestTrait.php \Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateTestTrait::assertOrder()
  2. 3.0.x tests/src/Kernel/CommerceMigrateTestTrait.php \Drupal\Tests\commerce_migrate\Kernel\CommerceMigrateTestTrait::assertOrder()

Asserts an order entity.

Parameters

array $order: An array of order information.

  • id: The order id.
  • type: The order type.
  • number: The order number.
  • store_id: The store id.
  • created_time: The time the order was created.
  • changed_time: The time the order was changed.
  • email: The email address for this order.
  • label: The label for this order.
  • ip_address: The ip address used to create this order.
  • customer_id: The customer id.
  • placed_time: The time the order was placed.
  • total_price_currency: Currency code for the total price.
  • total_price: The amount of the total price.
  • adjustments: An array of adjustments.
  • label_value: The state label
  • billing_profile: An array of billing profile target id and target

revision id.

  • data: The data blob for this order.
  • order_items_ids: An array of order item IDs for this order.
2 calls to CommerceMigrateTestTrait::assertOrder()
CommerceMigrateTestTrait::assertUbercartOrder in tests/src/Kernel/CommerceMigrateTestTrait.php
Asserts an order entity.
OrderTest::testOrder in modules/commerce/tests/src/Kernel/Migrate/commerce1/OrderTest.php
Test line item migration from Drupal 7 to 8.

File

tests/src/Kernel/CommerceMigrateTestTrait.php, line 227

Class

CommerceMigrateTestTrait
Helper function to test migrations.

Namespace

Drupal\Tests\commerce_migrate\Kernel

Code

public function assertOrder(array $order) {
  $order_instance = Order::load($order['id']);
  $this
    ->assertInstanceOf(Order::class, $order_instance);
  $this
    ->assertSame($order['type'], $order_instance
    ->bundle());
  $this
    ->assertSame($order['number'], $order_instance
    ->getOrderNumber());
  $this
    ->assertSame($order['store_id'], $order_instance
    ->getStoreId());
  $this
    ->assertSame($order['created_time'], $order_instance
    ->getCreatedTime());
  $this
    ->assertSame($order['changed_time'], $order_instance
    ->getChangedTime());
  $this
    ->assertSame($order['completed_time'], $order_instance
    ->getCompletedTime());
  $this
    ->assertSame($order['email'], $order_instance
    ->getEmail());
  $this
    ->assertInstanceOf(Profile::class, $order_instance
    ->getBillingProfile());
  $this
    ->assertSame($order['customer_id'], $order_instance
    ->getCustomerId());
  $this
    ->assertSame($order['ip_address'], $order_instance
    ->getIpAddress());
  $this
    ->assertSame($order['placed_time'], $order_instance
    ->getPlacedTime());

  // Order total price may be null if the source order was incomplete.
  $actual_total_price = $order_instance
    ->getTotalPrice();
  if ($actual_total_price != NULL) {
    $this
      ->assertEquals($order['total_price_currency'], $order_instance
      ->getTotalPrice()
      ->getCurrencyCode());
    $formatted_number = $this
      ->formatNumber($order['total_price'], $order_instance
      ->getTotalPrice()
      ->getNumber());
    $this
      ->assertSame($formatted_number['expected'], $formatted_number['actual']);
  }
  $this
    ->assertAdjustments($order['adjustments'], $order_instance
    ->getAdjustments());
  $this
    ->assertSame($order['label_value'], $order_instance
    ->getState()->value);
  $data = $order_instance
    ->get('data')
    ->getValue();
  $this
    ->assertSame($order['data'], $data);
  $state_label = $order_instance
    ->getState()
    ->getLabel();
  $label = NULL;
  if (is_string($state_label)) {
    $label = $state_label;
  }
  elseif ($state_label instanceof TranslatableMarkup) {
    $arguments = $state_label
      ->getArguments();
    $label = isset($arguments['@label']) ? $arguments['@label'] : $state_label
      ->render();
  }
  $this
    ->assertSame($order['label_rendered'], $label);

  // Allow orders to be tested without a cart.
  if (isset($order['cart'])) {
    $this
      ->assertSame($order['cart'], $order_instance
      ->get('cart')->value);
  }

  // Test billing profile.
  $billing_profile = [
    'target_id' => $order['billing_profile'][0],
    'target_revision_id' => $order['billing_profile'][1],
  ];
  $this
    ->assertSame([
    $billing_profile,
  ], $order_instance
    ->get('billing_profile')
    ->getValue());

  // Test the order items as linked.
  $actual_order_items = $order_instance
    ->get('order_items')
    ->getValue();
  $actual_order_item_ids = [];
  foreach ($actual_order_items as $actual_order_item) {
    $actual_order_item_ids[] = $actual_order_item['target_id'];
  }
  sort($actual_order_item_ids);
  sort($order['order_items_ids']);
  $this
    ->assertSame($order['order_items_ids'], $actual_order_item_ids);
}