public function ListWidgetTest::massageFormValuesDoNotAddOtherValuesToAllowedValues in Select (or other) 8
Same name and namespace in other branches
- 4.x tests/src/Unit/ListWidgetTest.php \Drupal\Tests\select_or_other\Unit\ListWidgetTest::massageFormValuesDoNotAddOtherValuesToAllowedValues()
@test @covers Drupal\select_or_other\Plugin\Field\FieldWidget\ListWidget::extractNewValues @covers Drupal\select_or_other\Plugin\Field\FieldWidget\ListWidget::AddNewValuesToAllowedValues
File
- tests/
src/ Unit/ ListWidgetTest.php, line 164
Class
- ListWidgetTest
- Tests the form element implementation.
Namespace
Drupal\Tests\select_or_other\UnitCode
public function massageFormValuesDoNotAddOtherValuesToAllowedValues() {
$allowed_values = [
't' => 'test',
];
$field_definition = $this
->getMockForAbstractClass('\\Drupal\\Core\\Field\\FieldDefinitionInterface');
$field_definition
->method('getSetting')
->willReturn($allowed_values);
$sut = $this
->getNewSubjectUnderTest($field_definition);
$field_storage_config = $this
->getMockForAbstractClass('\\Drupal\\field\\FieldStorageConfigInterface');
$field_storage_config
->expects($this
->never())
->method('setSetting')
->willReturnSelf();
$field_storage_config
->expects($this
->never())
->method('save');
$entity_storage_methods = [
'load' => $field_storage_config,
];
$entity_type_manager_methods = [
'getStorage' => $this
->getMockForAbstractClassWithMethods('\\Drupal\\Core\\Entity\\EntityStorageInterface', $entity_storage_methods),
];
$entity_type_manager_mock = $this
->getMockForAbstractClassWithMethods('\\Drupal\\Core\\Entity\\EntityTypeManagerInterface', $entity_type_manager_methods);
$this
->registerServiceWithContainerMock('entity_type.manager', $entity_type_manager_mock);
$form = [];
$form_state = new FormState();
$sut
->setSetting('add_other_value_to_allowed_values', FALSE);
// First invocation does not call setSetting or save.
$sut
->massageFormValues([
't',
], $form, $form_state);
// Second invocation calls setSetting and save.
$sut
->massageFormValues([
't',
'est',
], $form, $form_state);
}