function ManageFieldsFunctionalTest::testPreconfiguredFields
Same name in other branches
- 9 core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsFunctionalTest::testPreconfiguredFields()
- 8.9.x core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsFunctionalTest::testPreconfiguredFields()
- 10 core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsFunctionalTest::testPreconfiguredFields()
Tests the "preconfigured field" functionality.
See also
\Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface
File
-
core/
modules/ field_ui/ tests/ src/ Functional/ ManageFieldsFunctionalTest.php, line 330
Class
- ManageFieldsFunctionalTest
- Tests the Field UI "Manage fields" screen.
Namespace
Drupal\Tests\field_ui\FunctionalCode
public function testPreconfiguredFields() : void {
$this->drupalGet('admin/structure/types/manage/article/fields/add-field');
// Check that the preconfigured field option exist alongside the regular
// field type option.
$this->assertSession()
->elementExists('css', "[name='new_storage_type'][value='field_ui:test_field_with_preconfigured_options:custom_options']");
$this->assertSession()
->elementExists('css', "[name='new_storage_type'][value='test_field_with_preconfigured_options']");
// Add a field with every possible preconfigured value.
$this->fieldUIAddNewField(NULL, 'test_custom_options', 'Test label', 'field_ui:test_field_with_preconfigured_options:custom_options');
$field_storage = FieldStorageConfig::loadByName('node', 'field_test_custom_options');
$this->assertEquals(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, $field_storage->getCardinality());
$this->assertEquals('preconfigured_storage_setting', $field_storage->getSetting('test_field_storage_setting'));
$field = FieldConfig::loadByName('node', 'article', 'field_test_custom_options');
$this->assertTrue($field->isRequired());
$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('node', 'article');
$this->assertEquals('test_field_widget_multiple', $form_display->getComponent('field_test_custom_options')['type']);
$view_display = $display_repository->getViewDisplay('node', 'article');
$this->assertEquals('field_test_multiple', $view_display->getComponent('field_test_custom_options')['type']);
$this->assertEquals('altered dummy test string', $view_display->getComponent('field_test_custom_options')['settings']['test_formatter_setting_multiple']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.