function TextFieldItemListTest::testDefaultValuesFormValidateWithMultipleCardinality
Same name and namespace in other branches
- 11.x core/modules/text/tests/src/Unit/Plugin/Field/FieldType/TextFieldItemListTest.php \Drupal\Tests\text\Unit\Plugin\Field\FieldType\TextFieldItemListTest::testDefaultValuesFormValidateWithMultipleCardinality()
Tests ::defaultValuesFormValidate() if the field allows multiple values.
Ensures that the add_more button is filtered out of the submitted values before validation, preventing PHP warnings due to trying to access array keys on a TranslatableMarkup object.
File
-
core/
modules/ text/ tests/ src/ Unit/ Plugin/ Field/ FieldType/ TextFieldItemListTest.php, line 29
Class
- TextFieldItemListTest
- Tests TextFieldItemList.
Namespace
Drupal\Tests\text\Unit\Plugin\Field\FieldTypeCode
public function testDefaultValuesFormValidateWithMultipleCardinality() : void {
$field_name = 'field_test_text';
$definition = $this->createMock(FieldDefinitionInterface::class);
$definition->expects($this->once())
->method('getName')
->willReturn($field_name);
$definition->expects($this->once())
->method('getSetting')
->with('allowed_formats')
->willReturn([
'restricted_html',
]);
$form_state = $this->createMock(FormStateInterface::class);
$form_state->expects($this->once())
->method('getValue')
->with([
'default_value_input',
$field_name,
])
->willReturn([
'add_more' => new TranslatableMarkup('Add another item'),
]);
$form_state->expects($this->once())
->method('has')
->with('default_value_widget')
->willReturn(TRUE);
$form_state->expects($this->once())
->method('get')
->with('default_value_widget')
->willReturn([]);
$item_list = new TextFieldItemList($definition);
$form = [];
$item_list->defaultValuesFormValidate([], $form, $form_state);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.