You are here

public function Select2Test::testPreRenderSelect in Select 2 8

@covers ::preRenderSelect

@dataProvider providerTestPreRenderSelect

File

tests/src/Unit/Element/Select2Test.php, line 66

Class

Select2Test
@coversDefaultClass \Drupal\select2\Element\Select2 @group select2

Namespace

Drupal\Tests\select2\Unit\Element

Code

public function testPreRenderSelect($multiple, $required, $settings, $expected) {
  $element = [
    '#name' => 'field_foo',
    '#options' => [],
    '#multiple' => $multiple,
    '#required' => $required,
    '#attributes' => [
      'data-drupal-selector' => 'field-foo',
    ],
    '#autocreate' => [],
    '#autocomplete' => FALSE,
    '#cardinality' => 0,
    '#empty_value' => '',
    '#select2' => $settings,
  ];
  $element = Select2::preRenderSelect($element);
  $element = Select2::preRenderAutocomplete($element);
  $element = Select2::preRenderOverwrites($element);
  $this
    ->assertEquals($expected, array_intersect_key($element['#attributes'], $expected));
}