function ManageFieldsMultipleTypesTest::testReuseField
Same name in other branches
- 10 core/modules/field_ui/tests/src/Functional/ManageFieldsMultipleTypesTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsMultipleTypesTest::testReuseField()
Tests that options are copied over when reusing a field.
@dataProvider entityTypesProvider
File
-
core/
modules/ field_ui/ tests/ src/ Functional/ ManageFieldsMultipleTypesTest.php, line 26
Class
- ManageFieldsMultipleTypesTest
- Tests the Field UI "Manage fields" screen.
Namespace
Drupal\Tests\field_ui\FunctionalCode
public function testReuseField($entity_type, $bundle1, $bundle2) : void {
$field_name = 'test_reuse';
$label = $this->randomMachineName();
// Create field with pre-configured options.
$this->drupalGet($bundle1['path'] . "/fields/add-field");
$this->fieldUIAddNewField(NULL, $field_name, $label, 'field_ui:test_field_with_preconfigured_options:custom_options');
$new_label = $this->randomMachineName();
$this->fieldUIAddExistingField($bundle2['path'], "field_{$field_name}", $new_label);
$field = FieldConfig::loadByName($entity_type, $bundle2['id'], "field_{$field_name}");
$this->assertTrue($field->isRequired());
$this->assertEquals($new_label, $field->label());
$this->assertEquals('preconfigured_field_setting', $field->getSetting('test_field_setting'));
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
$display_repository = \Drupal::service('entity_display.repository');
$form_display = $display_repository->getFormDisplay($entity_type, $bundle2['id']);
$this->assertEquals('test_field_widget_multiple', $form_display->getComponent("field_{$field_name}")['type']);
$view_display = $display_repository->getViewDisplay($entity_type, $bundle2['id']);
$this->assertEquals('field_test_multiple', $view_display->getComponent("field_{$field_name}")['type']);
$this->assertEquals('altered dummy test string', $view_display->getComponent("field_{$field_name}")['settings']['test_formatter_setting_multiple']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.