You are here

public function ReferenceMigratorTest::doesNotCreateDuplicatesWhen in Term reference change 8

Tests term merging does not create duplicate values.

@test

File

tests/src/Kernel/ReferenceMigratorTest.php, line 154

Class

ReferenceMigratorTest
Tests that references are migrated.

Namespace

Drupal\Tests\term_reference_change\Kernel

Code

public function doesNotCreateDuplicatesWhen() {
  $sourceTerm = $this
    ->createTerm($this->vocabulary);
  $targetTerm = $this
    ->createTerm($this->vocabulary);
  $node1 = $this
    ->createNode([
    'field_terms' => [
      [
        'target_id' => $sourceTerm
          ->id(),
      ],
      [
        'target_id' => $targetTerm
          ->id(),
      ],
    ],
  ]);
  $this
    ->assertNodeReferencesTermOnce($node1, $sourceTerm);
  $this
    ->assertNodeReferencesTermOnce($node1, $targetTerm);
  $sut = new ReferenceMigrator(\Drupal::service('term_reference_change.reference_finder'));
  $sut
    ->migrateReference($sourceTerm, $targetTerm);
  $this
    ->assertNodeReferencesTermOnce($node1, $targetTerm);
}