private function ReferenceMigratorTest::assertNodeReferencesTermOnce in Term reference change 8
Check a taxonomy term is referenced in a given node.
Parameters
\Drupal\node\NodeInterface $node: The target node.
\Drupal\taxonomy\TermInterface $targetTerm: The target taxonomy term.
6 calls to ReferenceMigratorTest::assertNodeReferencesTermOnce()
- ReferenceMigratorTest::doesNotCreateDuplicatesWhen in tests/src/ Kernel/ ReferenceMigratorTest.php 
- Tests term merging does not create duplicate values.
- ReferenceMigratorTest::doesNotFailWhenReferenceFieldIsEmpty in tests/src/ Kernel/ ReferenceMigratorTest.php 
- Tests term merging does not fail when the source field is empty.
- ReferenceMigratorTest::doesNotFailWhenReferenceFieldIsMissing in tests/src/ Kernel/ ReferenceMigratorTest.php 
- Tests term merging does not fail when the target field is missing.
- ReferenceMigratorTest::migratesNodes in tests/src/ Kernel/ ReferenceMigratorTest.php 
- Tests term references in nodes are migrated.
- ReferenceMigratorTest::onlyMigratesLimitedNodes in tests/src/ Kernel/ ReferenceMigratorTest.php 
- Tests term references in nodes are migrated for selected nodes.
File
- tests/src/ Kernel/ ReferenceMigratorTest.php, line 217 
Class
- ReferenceMigratorTest
- Tests that references are migrated.
Namespace
Drupal\Tests\term_reference_change\KernelCode
private function assertNodeReferencesTermOnce(NodeInterface $node, TermInterface $targetTerm) {
  /** @var \Drupal\node\Entity\Node $loadedNode */
  $loadedNode = $this->entityTypeManager
    ->getStorage('node')
    ->load($node
    ->id());
  $referencedTerms = $loadedNode->field_terms
    ->getValue();
  $referenceCount = 0;
  foreach ($referencedTerms as $term) {
    if ($targetTerm
      ->id() != $term['target_id']) {
      continue;
    }
    $referenceCount++;
  }
  self::assertSame(1, $referenceCount);
}