You are here

public function MigrateDrupal6AuditIdsTest::testMultipleMigrationWithoutIdConflicts in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6AuditIdsTest.php \Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6AuditIdsTest::testMultipleMigrationWithoutIdConflicts()

Tests multiple migrations to the same destination with no ID conflicts.

File

core/modules/migrate_drupal/tests/src/Kernel/d6/MigrateDrupal6AuditIdsTest.php, line 59

Class

MigrateDrupal6AuditIdsTest
Tests the migration auditor for ID conflicts.

Namespace

Drupal\Tests\migrate_drupal\Kernel\d6

Code

public function testMultipleMigrationWithoutIdConflicts() {

  // Create a node of type page.
  $node = Node::create([
    'type' => 'page',
    'title' => 'foo',
  ]);
  $node->moderation_state->value = 'published';
  $node
    ->save();

  // Insert data in the d6_node:page migration mapping table to simulate a
  // previously migrated node.
  $id_map = $this
    ->getMigration('d6_node:page')
    ->getIdMap();
  $table_name = $id_map
    ->mapTableName();
  $id_map
    ->getDatabase()
    ->insert($table_name)
    ->fields([
    'source_ids_hash' => 1,
    'sourceid1' => 1,
    'destid1' => 1,
  ])
    ->execute();

  // Audit the IDs of the d6_node migrations for the page & article node type.
  // There should be no conflicts since the highest destination ID should be
  // equal to the highest migrated ID, as found in the aggregated mapping
  // tables of the two node migrations.
  $migrations = [
    $this
      ->getMigration('d6_node:page'),
    $this
      ->getMigration('d6_node:article'),
  ];
  $results = (new IdAuditor())
    ->auditMultiple($migrations);

  /** @var \Drupal\migrate\Audit\AuditResult $result */
  foreach ($results as $result) {
    $this
      ->assertInstanceOf(AuditResult::class, $result);
    $this
      ->assertTrue($result
      ->passed());
  }
}