You are here

public function MergeTermsTargetTest::existingTermSubmission in Term Merge 8

Tests term merging to an existing term.

@test

File

tests/src/Kernel/Form/MergeTermsTargetTest.php, line 148

Class

MergeTermsTargetTest
Tests the merge terms target terms form.

Namespace

Drupal\Tests\term_merge\Kernel\Form

Code

public function existingTermSubmission() {
  $sut = new MergeTermsTarget($this->entityTypeManager, $this->privateTempStoreFactory);
  $knownTermIds = array_keys($this->terms);
  $selectedTermIds = array_slice($knownTermIds, 0, 2);
  $termMergeCollection = $this->privateTempStoreFactory
    ->get('term_merge');
  $termMergeCollection
    ->set('terms', $selectedTermIds);
  $formState = new FormState();
  $build = $sut
    ->buildForm([], $formState, $this->vocabulary);
  $target = end($knownTermIds);
  $formState
    ->setValue('existing', $target);
  $sut
    ->validateForm($build, $formState);
  $sut
    ->submitForm($build, $formState);
  $targetTerm = $this->entityTypeManager
    ->getStorage('taxonomy_term')
    ->load($target);
  self::assertEquals($targetTerm, $termMergeCollection
    ->get('target'));
  $this
    ->assertRedirect($formState, 'entity.taxonomy_vocabulary.merge_confirm', $this->vocabulary
    ->id());
}