You are here

public function Select2Test::testPlaceholderPropertyRendering in Select 2 8

Checks #placeholder property.

@dataProvider providerTestPlaceholderPropertyRendering

File

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

Class

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

Namespace

Drupal\Tests\select2\Unit\Element

Code

public function testPlaceholderPropertyRendering($required, $empty_option, $empty_value, $placeholder, $expected) {
  $element = [
    '#name' => 'field_foo',
    '#options' => [],
    '#autocreate' => [],
    '#multiple' => FALSE,
    '#required' => $required,
    '#autocomplete' => FALSE,
    '#empty_value' => $empty_value,
    '#empty_option' => $empty_option,
    '#attributes' => [
      'data-drupal-selector' => 'field-foo',
    ],
    '#placeholder' => $placeholder,
    '#select2' => [],
  ];
  $element = Select2::preRenderSelect($element);
  $element = Select2::preRenderAutocomplete($element);
  $placeholder = $element['#attributes']['data-select2-config']['placeholder'];
  $this
    ->assertSame($expected['id'], $placeholder['id']);
  $this
    ->assertEquals($expected['text'], $placeholder['text']
    ->getUntranslatedString());
}