You are here

private function MergeTermsConfirmTest::assertConfirmationForm in Term Merge 8

Tests the confirm form build structure for a given set of taxonomy terms.

Parameters

\Drupal\taxonomy\TermInterface[] $selectedTerms: An array of selected taxonomy terms.

array $actual: The form structure.

\Drupal\taxonomy\Entity\Term|string $target: A newly created term if the target was an empty string, the original string otherwise.

1 call to MergeTermsConfirmTest::assertConfirmationForm()
MergeTermsConfirmTest::buildForm in tests/src/Kernel/Form/MergeTermsConfirmTest.php
Tests the form build for the confirm form.

File

tests/src/Kernel/Form/MergeTermsConfirmTest.php, line 139

Class

MergeTermsConfirmTest
Tests the Merge terms confirm form.

Namespace

Drupal\Tests\term_merge\Kernel\Form

Code

private function assertConfirmationForm(array $selectedTerms, array $actual, $target) {
  $items = [];
  foreach ($selectedTerms as $termIndex) {
    $items[] = $this->terms[$termIndex]
      ->label();
  }
  $arguments = [
    '%termCount' => count($selectedTerms),
    '%termName' => is_string($target) ? $target : $target
      ->label(),
  ];
  if (is_string($target)) {
    $message = new TranslatableMarkup("You are about to merge %termCount terms into new term %termName. This action can't be undone. Are you sure you wish to continue with merging the terms below?", $arguments);
  }
  else {
    $message = new TranslatableMarkup("You are about to merge %termCount terms into existing term %termName. This action can't be undone. Are you sure you wish to continue with merging the terms below?", $arguments);
  }
  $expected = [
    'message' => [
      '#markup' => $message,
    ],
    'terms' => [
      '#title' => new TranslatableMarkup("Terms to be merged"),
      '#theme' => 'item_list',
      '#items' => $items,
    ],
    'actions' => [
      '#type' => 'actions',
      'submit' => [
        '#button_type' => 'primary',
        '#type' => 'submit',
        '#value' => new TranslatableMarkup('Confirm merge'),
      ],
    ],
  ];
  self::assertEquals($expected, $actual);
}