You are here

public function MigrateNodeCompleteTest::testNodeCompleteMigration in Drupal 10

Same name in this branch
  1. 10 core/modules/node/tests/src/Kernel/Migrate/d6/MigrateNodeCompleteTest.php \Drupal\Tests\node\Kernel\Migrate\d6\MigrateNodeCompleteTest::testNodeCompleteMigration()
  2. 10 core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeCompleteTest.php \Drupal\Tests\node\Kernel\Migrate\d7\MigrateNodeCompleteTest::testNodeCompleteMigration()
Same name and namespace in other branches
  1. 8 core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeCompleteTest.php \Drupal\Tests\node\Kernel\Migrate\d7\MigrateNodeCompleteTest::testNodeCompleteMigration()
  2. 9 core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeCompleteTest.php \Drupal\Tests\node\Kernel\Migrate\d7\MigrateNodeCompleteTest::testNodeCompleteMigration()

Tests the complete node migration.

File

core/modules/node/tests/src/Kernel/Migrate/d7/MigrateNodeCompleteTest.php, line 101

Class

MigrateNodeCompleteTest
Test class for a complete node migration for Drupal 7.

Namespace

Drupal\Tests\node\Kernel\Migrate\d7

Code

public function testNodeCompleteMigration() {

  // Confirm there are only complete node migration map tables. This shows
  // that only the complete migration ran.
  $results = $this
    ->nodeMigrateMapTableCount('7');
  $this
    ->assertSame(0, $results['node']);
  $this
    ->assertSame(8, $results['node_complete']);
  $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));

  // Load and test each revision.
  $data = $this
    ->expectedRevisionEntityData()[0];
  foreach ($this
    ->expectedNodeFieldRevisionTable() as $key => $revision) {
    $this
      ->assertRevision($revision, $data[$key]);
  }

  // Test the migration of node and user reference fields.
  foreach ([
    2,
    3,
  ] as $revision_id) {
    $revision = $this->nodeStorage
      ->loadRevision($revision_id);
    $this
      ->assertCount(1, $revision->field_node_reference);
    $this
      ->assertSame('5', $revision->field_node_reference->target_id);
    $this
      ->assertCount(1, $revision->field_user_reference);
    $this
      ->assertSame('Bob', $revision->field_user_reference[0]->entity
      ->getAccountName());
  }

  // Test the translated node reference in the latest revision of node 2. This
  // references the legacy site node 4 instead of node 2. The reference is
  // fixed by the followup migrations, 'd7_entity_reference_translation' and
  // tested in \Drupal\Tests\migrate_drupal\Kernel\d7\FollowUpMigrationsTest.
  $node = Node::load(2);
  $this
    ->assertSame('6', $node
    ->get('field_reference_2')->target_id);
  $translation = $node
    ->getTranslation('is');
  $this
    ->assertSame('4', $translation
    ->get('field_reference_2')->target_id);

  // Test the order in multi-value fields.
  $revision = $this->nodeStorage
    ->loadRevision(1);
  $this
    ->assertSame([
    [
      'value' => 'default@example.com',
    ],
    [
      'value' => 'another@example.com',
    ],
  ], $revision
    ->get('field_email')
    ->getValue());
  $this
    ->assertSame([
    [
      'target_id' => '17',
    ],
    [
      'target_id' => '15',
    ],
  ], $revision
    ->get('field_term_entityreference')
    ->getValue());
}