public function MergeTermsTargetTest::buildsForm in Term Merge 8
Tests the form structure of the merge terms target terms form.
@test
File
- tests/
src/ Kernel/ Form/ MergeTermsTargetTest.php, line 35
Class
- MergeTermsTargetTest
- Tests the merge terms target terms form.
Namespace
Drupal\Tests\term_merge\Kernel\FormCode
public function buildsForm() {
$sut = new MergeTermsTarget($this->entityTypeManager, $this->privateTempStoreFactory);
$knownTermIds = array_keys($this->terms);
$selectedTermIds = array_slice($knownTermIds, 0, 2);
$this->privateTempStoreFactory
->get('term_merge')
->set('terms', $selectedTermIds);
$options = [];
foreach ($knownTermIds as $termId) {
if (in_array($termId, $selectedTermIds)) {
continue;
}
$options[$termId] = $this->terms[$termId]
->label();
}
$expected = [
'description' => [
'#markup' => new TranslatableMarkup('Please enter a new term or select an existing term to merge into.'),
],
'new' => [
'#type' => 'textfield',
'#title' => new TranslatableMarkup('New term'),
],
'existing' => [
'#type' => 'select',
'#title' => new TranslatableMarkup('Existing term'),
'#empty_option' => new TranslatableMarkup('Select an existing term'),
'#options' => $options,
],
'actions' => [
'#type' => 'actions',
'submit' => [
'#button_type' => 'primary',
'#type' => 'submit',
'#value' => new TranslatableMarkup('Submit'),
],
],
];
$actual = $sut
->buildForm([], new FormState(), $this->vocabulary);
self::assertEquals($expected, $actual);
}