function AddToAllBundlesConfigActionTest::testIgnoreExistingFields
Same name in other branches
- 11.x core/modules/field/tests/src/Kernel/AddToAllBundlesConfigActionTest.php \Drupal\Tests\field\Kernel\AddToAllBundlesConfigActionTest::testIgnoreExistingFields()
Tests that the action will ignore existing fields by default.
File
-
core/
modules/ field/ tests/ src/ Kernel/ AddToAllBundlesConfigActionTest.php, line 96
Class
Namespace
Drupal\Tests\field\KernelCode
public function testIgnoreExistingFields() : void {
$this->installConfig('node');
node_add_body_field(NodeType::load('one'))->setLabel('Original label')
->setDescription('Original description')
->save();
$this->applyAction('field.storage.node.body');
// The existing field should not be changed.
$field = FieldConfig::loadByName('node', 'one', 'body');
$this->assertInstanceOf(FieldConfig::class, $field);
$this->assertSame('Original label', $field->label());
$this->assertSame('Original description', $field->getDescription());
// But the new field should be created as expected.
$field = FieldConfig::loadByName('node', 'two', 'body');
$this->assertInstanceOf(FieldConfig::class, $field);
$this->assertSame('Body field label', $field->label());
$this->assertSame('Set by config actions.', $field->getDescription());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.