You are here

public function MergeTermsTargetTest::newTermFormSubmission in Term Merge 8

Tests term merging to a new term.

@test

File

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

Class

MergeTermsTargetTest
Tests the merge terms target terms form.

Namespace

Drupal\Tests\term_merge\Kernel\Form

Code

public function newTermFormSubmission() {
  $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 = 'newTarget';
  $formState
    ->setValue('new', $target);
  $sut
    ->validateForm($build, $formState);
  $sut
    ->submitForm($build, $formState);
  self::assertSame($target, $termMergeCollection
    ->get('target'));
  $this
    ->assertRedirect($formState, 'entity.taxonomy_vocabulary.merge_confirm', $this->vocabulary
    ->id());
}