You are here

public function Select2Test::testAutocompleteOptions in Select 2 8

Tests that in autocomplete are only the default options rendered.

File

tests/src/Kernel/Element/Select2Test.php, line 67

Class

Select2Test
@coversDefaultClass \Drupal\select2\Element\Select2

Namespace

Drupal\Tests\select2\Kernel\Element

Code

public function testAutocompleteOptions() {
  $select = [
    '#type' => 'select2',
    '#options' => [
      'foo' => 'Foo',
      'bar' => 'Bar',
      'foo_bar' => 'FooBar',
    ],
    '#default_value' => [
      'foo',
    ],
    '#autocomplete' => TRUE,
    '#target_type' => 'node',
    '#required' => FALSE,
    '#attributes' => [
      'data-drupal-selector' => 'field-foo',
    ],
  ];
  $this
    ->render($select);
  $this
    ->assertOptionExists('field-foo', 'foo');
  $this
    ->assertOptionNotExists('field-foo', 'bar');
  $this
    ->assertOptionNotExists('field-foo', 'foo_bar');
}