function EntityFormDisplayTest::testBaseFieldComponent
Same name in other branches
- 9 core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityFormDisplayTest::testBaseFieldComponent()
- 10 core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityFormDisplayTest::testBaseFieldComponent()
- 11.x core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityFormDisplayTest::testBaseFieldComponent()
Tests the behavior of a field component for a base field.
File
-
core/
modules/ field_ui/ tests/ src/ Kernel/ EntityFormDisplayTest.php, line 133
Class
- EntityFormDisplayTest
- Tests the entity display configuration entities.
Namespace
Drupal\Tests\field_ui\KernelCode
public function testBaseFieldComponent() {
$display = EntityFormDisplay::create([
'targetEntityType' => 'entity_test_base_field_display',
'bundle' => 'entity_test_base_field_display',
'mode' => 'default',
]);
// Check that default options are correctly filled in.
$formatter_settings = \Drupal::service('plugin.manager.field.widget')->getDefaultSettings('text_textfield');
$expected = [
'test_no_display' => NULL,
'test_display_configurable' => [
'type' => 'text_textfield',
'settings' => $formatter_settings,
'third_party_settings' => [],
'weight' => 10,
'region' => 'content',
],
'test_display_non_configurable' => [
'type' => 'text_textfield',
'settings' => $formatter_settings,
'third_party_settings' => [],
'weight' => 11,
'region' => 'content',
],
];
foreach ($expected as $field_name => $options) {
$this->assertEqual($display->getComponent($field_name), $options);
}
// Check that saving the display only writes data for fields whose display
// is configurable.
$display->save();
$config = $this->config('core.entity_form_display.' . $display->id());
$data = $config->get();
$this->assertFalse(isset($data['content']['test_no_display']));
$this->assertFalse(isset($data['hidden']['test_no_display']));
$this->assertEqual($data['content']['test_display_configurable'], $expected['test_display_configurable']);
$this->assertFalse(isset($data['content']['test_display_non_configurable']));
$this->assertFalse(isset($data['hidden']['test_display_non_configurable']));
// Check that defaults are correctly filled when loading the display.
$display = EntityFormDisplay::load($display->id());
foreach ($expected as $field_name => $options) {
$this->assertEqual($display->getComponent($field_name), $options);
}
// Check that data manually written for fields whose display is not
// configurable is discarded when loading the display.
$data['content']['test_display_non_configurable'] = $expected['test_display_non_configurable'];
$data['content']['test_display_non_configurable']['weight']++;
$config->setData($data)
->save();
$display = EntityFormDisplay::load($display->id());
foreach ($expected as $field_name => $options) {
$this->assertEqual($display->getComponent($field_name), $options);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.