function OptionsWidgetBaseTest::testGetSelectedOptionsWithNullValue
Same name and namespace in other branches
- main core/modules/options/tests/src/Kernel/OptionsWidgetBaseTest.php \Drupal\Tests\options\Kernel\OptionsWidgetBaseTest::testGetSelectedOptionsWithNullValue()
Tests that getSelectedOptions() skips NULL item values.
File
-
core/
modules/ options/ tests/ src/ Kernel/ OptionsWidgetBaseTest.php, line 29
Class
- OptionsWidgetBaseTest
- Tests OptionsWidgetBase.
Namespace
Drupal\Tests\options\KernelCode
public function testGetSelectedOptionsWithNullValue() : void {
\Drupal::service('entity_display.repository')->getFormDisplay('entity_test', 'entity_test')
->setComponent($this->fieldName, [
'type' => 'options_select_no_multiple',
])
->save();
// An entity with no value triggers formMultipleElements() which appends
// an item with value = NULL before calling getSelectedOptions().
$entity = EntityTest::create();
$form = \Drupal::service('entity.form_builder')->getForm($entity);
$this->assertSame([], $form[$this->fieldName]['widget'][0]['#default_value']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.