public function TermMergerNodeCrudTest::nodeReferencesAreUpdated in Term Merge 8
Tests taxonomy term references are updated in a node after a term merge.
@test
File
- tests/
src/ Kernel/ TermMergerNodeCrudTest.php, line 54
Class
- TermMergerNodeCrudTest
- Tests term merging for nodes.
Namespace
Drupal\Tests\term_merge\KernelCode
public function nodeReferencesAreUpdated() {
$firstTerm = reset($this->terms);
$node = $this
->createNode([
'field_terms' => [
'target_id' => $firstTerm
->id(),
],
]);
$migrator = \Drupal::service('term_reference_change.migrator');
$dispatcher = \Drupal::service('event_dispatcher');
$sut = new TermMerger($this->entityTypeManager, $migrator, $dispatcher);
$newTerm = $sut
->mergeIntoNewTerm($this->terms, 'NewTerm');
/** @var \Drupal\node\Entity\Node $loadedNode */
$loadedNode = $this->entityTypeManager
->getStorage('node')
->load($node
->id());
$referencedTerms = $loadedNode->field_terms
->getValue();
self::assertCount(1, $referencedTerms);
$firstReference = reset($referencedTerms);
self::assertEquals($newTerm
->id(), $firstReference['target_id']);
}