You are here

public function NodeTest::testNode in Commerce Migrate 3.1.x

Same name and namespace in other branches
  1. 8.2 modules/commerce/tests/src/Kernel/Migrate/commerce1/NodeTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1\NodeTest::testNode()
  2. 3.0.x modules/commerce/tests/src/Kernel/Migrate/commerce1/NodeTest.php \Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1\NodeTest::testNode()

Test node migration from Commerce 1 to Commerce Drupal 8.

File

modules/commerce/tests/src/Kernel/Migrate/commerce1/NodeTest.php, line 71

Class

NodeTest
Tests node migration.

Namespace

Drupal\Tests\commerce_migrate_commerce\Kernel\Migrate\commerce1

Code

public function testNode() {

  // Confirm there are only complete node migration map tables. This shows
  // that only the complete migration ran.
  $results = $this
    ->nodeMigrateMapTableCount('7');
  $this
    ->assertSame(5, $results['node']);
  $db = \Drupal::database();
  $this
    ->assertEquals($this
    ->expectedNodeFieldRevisionTable(), $db
    ->select('node_field_revision', 'nr')
    ->fields('nr')
    ->orderBy('vid')
    ->orderBy('langcode')
    ->execute()
    ->fetchAll(\PDO::FETCH_ASSOC));
  $this
    ->assertEquals($this
    ->expectedNodeFieldDataTable(), $db
    ->select('node_field_data', 'nr')
    ->fields('nr')
    ->orderBy('nid')
    ->orderBy('vid')
    ->orderBy('langcode')
    ->execute()
    ->fetchAll(\PDO::FETCH_ASSOC));

  // Test field values on node 11.
  $node_storage = \Drupal::service('entity_type.manager')
    ->getStorage('node');
  $revision = $node_storage
    ->loadRevision(11);
  $this
    ->assertInstanceOf(NodeInterface::class, $revision);
  $this
    ->assertSame('99', $revision
    ->get('field_image')
    ->getValue()[0]['target_id']);
  $this
    ->assertSame('internal:/drinks/guy-h20', $revision
    ->get('field_link')
    ->getValue()[0]['uri']);
  $this
    ->assertSame("You're getting thirsty", $revision
    ->get('field_tagline')
    ->getValue()[0]['value']);

  // 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);

  // Test values of a product field.
  $product = Product::load(15);
  $this
    ->assertInstanceOf(Product::class, $product);
  $this
    ->assertCount(1, $product
    ->get('field_category')
    ->getValue());
  $this
    ->assertSame('50', $product
    ->get('field_category')
    ->getValue()[0]['target_id']);

  // Test vocabulary and terms for non-product terms.
  $this
    ->assertVocabularyEntity('blog_category', 'Blog category', '', NULL, 0);
  $this
    ->assertVocabularyEntity('tags', 'Tags', 'Use tags to group blog posts on similar topics.', NULL, 0);
  $this
    ->assertTermEntity(44, 'Kickstart Tip', 'blog_category', '', NULL, 0, [
    0,
  ]);
  $this
    ->assertTermEntity(45, 'Social', 'tags', '', NULL, 0, [
    0,
  ]);
  $this
    ->assertTermEntity(46, 'Kickstart', 'tags', '', NULL, 0, [
    0,
  ]);
  $this
    ->assertTermEntity(47, 'CMT', 'blog_category', '', NULL, 0, [
    0,
  ]);
}