You are here

public function ProductVariationTest::testProductVariation in Commerce Migrate 8.2

Same name in this branch
  1. 8.2 modules/csv_example/tests/src/Kernel/Migrate/ProductVariationTest.php \Drupal\Tests\commerce_migrate_csv_example\Kernel\Migrate\ProductVariationTest::testProductVariation()
  2. 8.2 modules/shopify/tests/src/Kernel/Migrate/ProductVariationTest.php \Drupal\Tests\commerce_migrate_shopify\Kernel\Migrate\shopify\ProductVariationTest::testProductVariation()
  3. 8.2 modules/magento/tests/src/Kernel/Migrate/magento2/ProductVariationTest.php \Drupal\Tests\commerce_migrate_magento\Kernel\Migrate\magento2\ProductVariationTest::testProductVariation()
  4. 8.2 modules/ubercart/tests/src/Kernel/Migrate/uc7/ProductVariationTest.php \Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc7\ProductVariationTest::testProductVariation()
  5. 8.2 modules/ubercart/tests/src/Kernel/Migrate/uc6/ProductVariationTest.php \Drupal\Tests\commerce_migrate_ubercart\Kernel\Migrate\uc6\ProductVariationTest::testProductVariation()
  6. 8.2 modules/commerce/tests/src/Kernel/Migrate/commerce1/ProductVariationTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1\ProductVariationTest::testProductVariation()
Same name and namespace in other branches
  1. 3.1.x modules/commerce/tests/src/Kernel/Migrate/commerce1/ProductVariationTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1\ProductVariationTest::testProductVariation()
  2. 3.0.x modules/commerce/tests/src/Kernel/Migrate/commerce1/ProductVariationTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1\ProductVariationTest::testProductVariation()

Test product variation migration from Drupal 7 Commerce to Drupal 8.

1 method overrides ProductVariationTest::testProductVariation()
ProductVariationRollbackTest::testProductVariation in modules/commerce/tests/src/Kernel/Migrate/commerce1/ProductVariationRollbackTest.php
Test product migration rollback.

File

modules/commerce/tests/src/Kernel/Migrate/commerce1/ProductVariationTest.php, line 73

Class

ProductVariationTest
Tests product variation migration.

Namespace

Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1

Code

public function testProductVariation() {
  $variation = [
    'id' => 1,
    'type' => 'bags_cases',
    'uid' => '1',
    'sku' => 'TOT1-GRN-OS',
    'price' => '16.000000',
    'currency' => 'USD',
    'product_id' => NULL,
    'title' => 'Tote Bag 1',
    'order_item_type_id' => 'product',
    'created_time' => '1493287314',
    'changed_time' => '1493287350',
    'attributes' => NULL,
  ];
  $this
    ->assertProductVariationEntity($variation);
  $variation = [
    'id' => 11,
    'type' => 'hats',
    'uid' => '1',
    'sku' => 'HAT1-GRY-OS',
    'price' => '16.000000',
    'currency' => 'USD',
    'product_id' => NULL,
    'title' => 'Hat 1',
    'order_item_type_id' => 'product',
    'created_time' => '1493287364',
    'changed_time' => '1493287400',
    'attributes' => NULL,
  ];
  $this
    ->assertProductVariationEntity($variation);
  $variation = [
    'id' => 12,
    'type' => 'hats',
    'uid' => '1',
    'sku' => 'HAT2-BLK-OS',
    'price' => '12.000000',
    'currency' => 'USD',
    'product_id' => NULL,
    'title' => 'Hat 2',
    'order_item_type_id' => 'product',
    'created_time' => '1493287369',
    'changed_time' => '1493287405',
    'attributes' => NULL,
  ];
  $this
    ->assertProductVariationEntity($variation);
  $variation = [
    'id' => 12,
    'type' => 'hats',
    'uid' => '1',
    'sku' => 'HAT2-BLK-OS',
    'price' => '12.000000',
    'currency' => 'USD',
    'product_id' => NULL,
    'title' => 'Hat 2',
    'order_item_type_id' => 'product',
    'created_time' => '1493287369',
    'changed_time' => '1493287405',
    'attributes' => NULL,
  ];
  $this
    ->assertProductVariationEntity($variation);
  $variation = [
    'id' => 19,
    'type' => 'shoes',
    'uid' => '1',
    'sku' => 'SHO2-PRL-04',
    'price' => '40.000000',
    'currency' => 'USD',
    'product_id' => NULL,
    'title' => 'Shoe 2',
    'order_item_type_id' => 'product',
    'created_time' => '1493287404',
    'changed_time' => '1493287440',
    'attributes' => NULL,
  ];
  $this
    ->assertProductVariationEntity($variation);
  $variation = [
    'id' => 20,
    'type' => 'shoes',
    'uid' => '1',
    'sku' => 'SHO2-PRL-05',
    'price' => '40.000000',
    'currency' => 'USD',
    'product_id' => NULL,
    'title' => 'Shoe 2',
    'order_item_type_id' => 'product',
    'created_time' => '1493287409',
    'changed_time' => '1493287445',
    'attributes' => NULL,
  ];
  $this
    ->assertProductVariationEntity($variation);
  $variation = [
    'id' => 28,
    'type' => 'storage_devices',
    'uid' => '1',
    'sku' => 'USB-BLU-08',
    'price' => '11.990000',
    'currency' => 'USD',
    'product_id' => NULL,
    'title' => 'Storage 1',
    'order_item_type_id' => 'product',
    'created_time' => '1493287449',
    'changed_time' => '1493287485',
    'attributes' => NULL,
  ];
  $this
    ->assertProductVariationEntity($variation);
  $variation = [
    'id' => 29,
    'type' => 'storage_devices',
    'uid' => '1',
    'sku' => 'USB-BLU-16',
    'price' => '17.990000',
    'currency' => 'USD',
    'product_id' => NULL,
    'title' => 'Storage 1',
    'order_item_type_id' => 'product',
    'created_time' => '1493287454',
    'changed_time' => '1493287490',
    'attributes' => NULL,
  ];
  $this
    ->assertProductVariationEntity($variation);
  $variation = [
    'id' => 30,
    'type' => 'storage_devices',
    'uid' => '1',
    'sku' => 'USB-BLU-32',
    'price' => '29.990000',
    'currency' => 'USD',
    'product_id' => NULL,
    'title' => 'Storage 1',
    'order_item_type_id' => 'product',
    'created_time' => '1493287459',
    'changed_time' => '1493287495',
    'attributes' => NULL,
  ];
  $this
    ->assertProductVariationEntity($variation);

  // Test values of a product variation field.
  $variation = ProductVariation::load(1);
  $this
    ->assertInstanceOf(ProductVariation::class, $variation);
  $expected = [
    [
      'target_id' => '1',
      'alt' => NULL,
      'title' => NULL,
      'width' => '860',
      'height' => '842',
    ],
    [
      'target_id' => '2',
      'alt' => NULL,
      'title' => NULL,
      'width' => '860',
      'height' => '1251',
    ],
    [
      'target_id' => '3',
      'alt' => NULL,
      'title' => NULL,
      'width' => '860',
      'height' => '1100',
    ],
  ];
  $actual = $variation
    ->get('field_images')
    ->getValue();
  $this
    ->assertCount(3, $actual);
  $target_id = array_column($actual, 'target_id');
  array_multisort($target_id, SORT_ASC, SORT_NUMERIC, $actual);
  $this
    ->assertSame($expected, $actual);
}