You are here

public function OrderItemTest::testOrderItem in Commerce Migrate 3.0.x

Same name in this branch
  1. 3.0.x modules/ubercart/tests/src/Kernel/Migrate/uc7/OrderItemTest.php \Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc7\OrderItemTest::testOrderItem()
  2. 3.0.x modules/ubercart/tests/src/Kernel/Migrate/uc6/OrderItemTest.php \Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc6\OrderItemTest::testOrderItem()
  3. 3.0.x modules/commerce/tests/src/Kernel/Migrate/commerce1/OrderItemTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1\OrderItemTest::testOrderItem()
Same name and namespace in other branches
  1. 8.2 modules/ubercart/tests/src/Kernel/Migrate/uc6/OrderItemTest.php \Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc6\OrderItemTest::testOrderItem()
  2. 3.1.x modules/ubercart/tests/src/Kernel/Migrate/uc6/OrderItemTest.php \Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc6\OrderItemTest::testOrderItem()

Test order item migration.

File

modules/ubercart/tests/src/Kernel/Migrate/uc6/OrderItemTest.php, line 51

Class

OrderItemTest
Tests order item migration.

Namespace

Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc6

Code

public function testOrderItem() {
  $order_item = [
    'id' => 2,
    'order_id' => NULL,
    'created' => '1492989920',
    'changed' => '1508916762',
    'purchased_entity_id' => 3,
    'quantity' => '1.00',
    'title' => 'Fairy cake',
    'unit_price' => '1500.000000',
    'unit_price_currency_code' => 'NZD',
    'total_price' => '1500.000000',
    'total_price_currency_code' => 'NZD',
    'uses_legacy_adjustments' => FALSE,
    'adjustments' => [
      new Adjustment([
        'type' => 'tax',
        'label' => 'Handling',
        'amount' => new Price('60', 'NZD'),
        'percentage' => '0.04',
        'source_id' => 'custom',
        'included' => FALSE,
        'locked' => TRUE,
      ]),
    ],
  ];
  $this
    ->assertOrderItem($order_item);
  $order_item = [
    'id' => 3,
    'order_id' => NULL,
    'created' => '1492868907',
    'changed' => '1523578137',
    'purchased_entity_id' => 1,
    'quantity' => '1.00',
    'title' => 'Bath Towel',
    'unit_price' => '20.000000',
    'unit_price_currency_code' => 'NZD',
    'total_price' => '20.000000',
    'total_price_currency_code' => 'NZD',
    'uses_legacy_adjustments' => FALSE,
    'adjustments' => [
      new Adjustment([
        'type' => 'tax',
        'label' => 'Service charge',
        'amount' => new Price('0.99', 'NZD'),
        'percentage' => NULL,
        'source_id' => 'custom',
        'included' => FALSE,
        'locked' => TRUE,
      ]),
      new Adjustment([
        'type' => 'tax',
        'label' => 'Handling',
        'amount' => new Price('0.7', 'NZD'),
        'percentage' => '0.04',
        'source_id' => 'custom',
        'included' => FALSE,
        'locked' => TRUE,
      ]),
    ],
  ];
  $this
    ->assertOrderItem($order_item);
  $order_item = [
    'id' => 4,
    'order_id' => NULL,
    'created' => '1492868907',
    'changed' => '1523578137',
    'purchased_entity_id' => 2,
    'quantity' => '1.00',
    'title' => 'Beach Towel',
    'unit_price' => '15.000000',
    'unit_price_currency_code' => 'NZD',
    'total_price' => '15.000000',
    'total_price_currency_code' => 'NZD',
    'uses_legacy_adjustments' => FALSE,
    'adjustments' => [
      new Adjustment([
        'type' => 'tax',
        'label' => 'Service charge',
        'amount' => new Price('1', 'NZD'),
        'percentage' => NULL,
        'source_id' => 'custom',
        'included' => FALSE,
        'locked' => TRUE,
      ]),
      new Adjustment([
        'type' => 'tax',
        'label' => 'Handling',
        'amount' => new Price('0.7', 'NZD'),
        'percentage' => '0.04',
        'source_id' => 'custom',
        'included' => FALSE,
        'locked' => TRUE,
      ]),
    ],
  ];
  $this
    ->assertOrderItem($order_item);
  $order_item = [
    'id' => 5,
    'order_id' => NULL,
    'created' => '1511148641',
    'changed' => '1511149246',
    'purchased_entity_id' => 4,
    'quantity' => '1.00',
    'title' => 'Magdalenas',
    'unit_price' => '20.000000',
    'unit_price_currency_code' => 'NZD',
    'total_price' => '20.000000',
    'total_price_currency_code' => 'NZD',
    'uses_legacy_adjustments' => FALSE,
    'adjustments' => [
      new Adjustment([
        'type' => 'tax',
        'label' => 'Handling',
        'amount' => new Price('0.8', 'NZD'),
        'percentage' => '0.04',
        'source_id' => 'custom',
        'included' => FALSE,
        'locked' => TRUE,
      ]),
    ],
  ];
  $this
    ->assertOrderItem($order_item);
  $order_item = [
    'id' => 6,
    'order_id' => NULL,
    'created' => '1502996811',
    'changed' => '1523578318',
    'purchased_entity_id' => 4,
    'quantity' => '1.00',
    'title' => 'Golgafrincham B-Ark',
    'unit_price' => '6000000000.000000',
    'unit_price_currency_code' => 'NZD',
    'total_price' => '6000000000.000000',
    'total_price_currency_code' => 'NZD',
    'uses_legacy_adjustments' => FALSE,
    'adjustments' => [
      new Adjustment([
        'type' => 'tax',
        'label' => 'Handling',
        'amount' => new Price('240000000', 'NZD'),
        'percentage' => '0.04',
        'source_id' => 'custom',
        'included' => FALSE,
        'locked' => TRUE,
      ]),
    ],
  ];
  $this
    ->assertOrderItem($order_item);
  $order_item = [
    'id' => 7,
    'order_id' => NULL,
    'created' => '1526437863',
    'changed' => '1526437864',
    'purchased_entity_id' => 2,
    'quantity' => '1.00',
    'title' => 'Beach Towel',
    'unit_price' => '18.000000',
    'unit_price_currency_code' => 'NZD',
    'total_price' => '18.000000',
    'total_price_currency_code' => 'NZD',
    'uses_legacy_adjustments' => FALSE,
    'adjustments' => [],
  ];
  $this
    ->assertOrderItem($order_item);

  // Test that both product and order are linked.
  $order_item = OrderItem::load(2);
  $product = $order_item
    ->getPurchasedEntity();
  $this
    ->assertNotNull($product);
  $this
    ->assertEquals(3, $product
    ->id());
}