You are here

public function IntegrationTest::testMergeSucceeds in Term Merge 8

Tests that a simple merge succeeds.

File

tests/src/Functional/IntegrationTest.php, line 28

Class

IntegrationTest
Tests the Term Merge module.

Namespace

Drupal\Tests\term_merge\Functional

Code

public function testMergeSucceeds() {
  $a = $this
    ->createTerm($this->vocabulary);
  $b = $this
    ->createTerm($this->vocabulary);
  $node = $this
    ->drupalCreateNode([
    'type' => $this->contentType
      ->id(),
    'field_tags' => [
      [
        'target_id' => $a
          ->id(),
      ],
      [
        'target_id' => $b
          ->id(),
      ],
    ],
  ]);
  $this
    ->mergeAintoB($a, $b);

  /** @var \Drupal\node\NodeInterface $loadedNode */
  $loadedNode = \Drupal::entityTypeManager()
    ->getStorage('node')
    ->load($node
    ->id());
  $expected = [
    [
      'target_id' => $b
        ->id(),
    ],
  ];
  $this
    ->assertEquals($expected, $loadedNode
    ->get('field_tags')
    ->getValue());
}