You are here

public function MigrateDrupal7AuditIdsTest::testDraftRevisionIdConflicts in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7AuditIdsTest.php \Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7AuditIdsTest::testDraftRevisionIdConflicts()

Tests draft revisions ID conflicts.

File

core/modules/migrate_drupal/tests/src/Kernel/d7/MigrateDrupal7AuditIdsTest.php, line 150

Class

MigrateDrupal7AuditIdsTest
Tests the migration auditor for ID conflicts.

Namespace

Drupal\Tests\migrate_drupal\Kernel\d7

Code

public function testDraftRevisionIdConflicts() {

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

  // Create a draft revision.
  $node->moderation_state->value = 'draft';
  $node
    ->setNewRevision(TRUE);
  $node
    ->save();

  // Insert data in the d7_node_revision:page migration mapping table to
  // simulate a previously migrated node revision.
  $id_map = $this
    ->getMigration('d7_node_revision: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 d7_node_revision migration. There should be
  // conflicts since a draft revision has been created.

  /** @var \Drupal\migrate\Audit\AuditResult $result */
  $result = (new IdAuditor())
    ->audit($this
    ->getMigration('d7_node_revision:page'));
  $this
    ->assertInstanceOf(AuditResult::class, $result);
  $this
    ->assertFalse($result
    ->passed());
}