public function Select2Test::testEmptyOption in Select 2 8
Tests that an empty option is added or not.
File
- tests/
src/ Kernel/ Element/ Select2Test.php, line 41
Class
- Select2Test
- @coversDefaultClass \Drupal\select2\Element\Select2
Namespace
Drupal\Tests\select2\Kernel\ElementCode
public function testEmptyOption() {
$select = [
'#type' => 'select2',
'#options' => [],
'#multiple' => FALSE,
'#required' => FALSE,
'#attributes' => [
'data-drupal-selector' => 'field-foo',
],
];
$this
->render($select);
$this
->assertOptionExists('field-foo', '');
$select = [
'#type' => 'select2',
'#options' => [],
'#multiple' => TRUE,
'#required' => FALSE,
'#attributes' => [
'data-drupal-selector' => 'field-foo',
],
'#name' => 'field_foo',
];
$this
->render($select);
$this
->assertOptionNotExists('field-foo', '');
}