You are here

public function ReferenceMigratorTest::onlyMigratesLimitedNodes in Term reference change 8

Tests term references in nodes are migrated for selected nodes.

@test

File

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

Class

ReferenceMigratorTest
Tests that references are migrated.

Namespace

Drupal\Tests\term_reference_change\Kernel

Code

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