You are here

public function EntityAutocompleteElementFormTest::testEntityAutocompleteIdInput in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::testEntityAutocompleteIdInput()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php \Drupal\KernelTests\Core\Entity\Element\EntityAutocompleteElementFormTest::testEntityAutocompleteIdInput()

Tests ID input is handled correctly.

E.g. This can happen with GET form parameters.

File

core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php, line 364

Class

EntityAutocompleteElementFormTest
Tests the EntityAutocomplete Form API element.

Namespace

Drupal\KernelTests\Core\Entity\Element

Code

public function testEntityAutocompleteIdInput() {

  /** @var \Drupal\Core\Form\FormBuilderInterface $form_builder */
  $form_builder = $this->container
    ->get('form_builder');

  // $form = $form_builder->getForm($this);
  $form_state = (new FormState())
    ->setMethod('GET')
    ->setValues([
    'single' => [
      [
        'target_id' => $this->referencedEntities[0]
          ->id(),
      ],
    ],
    'single_no_validate' => [
      [
        'target_id' => $this->referencedEntities[0]
          ->id(),
      ],
    ],
  ]);
  $form_builder
    ->submitForm($this, $form_state);
  $form = $form_state
    ->getCompleteForm();
  $expected_label = $this
    ->getAutocompleteInput($this->referencedEntities[0]);
  $this
    ->assertSame($expected_label, $form['single']['#value']);
  $this
    ->assertSame($expected_label, $form['single_no_validate']['#value']);
}