function AddToAllBundlesConfigActionTest::testIgnoreExistingFields

Same name and namespace in other branches
  1. 11.x core/modules/field/tests/src/Kernel/AddToAllBundlesConfigActionTest.php \Drupal\Tests\field\Kernel\AddToAllBundlesConfigActionTest::testIgnoreExistingFields()
  2. 10 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 123

Class

AddToAllBundlesConfigActionTest
Tests Add To All Bundles Config Action.

Namespace

Drupal\Tests\field\Kernel

Code

public function testIgnoreExistingFields() : void {
  $this->installConfig('entity_test');
  $this->installConfig('entity_test_with_storage');
  $field_storage = FieldStorageConfig::loadByName('entity_test', 'body');
  // Manually create the field.
  $field = FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => 'one',
    'label' => 'Original label',
    'description' => 'Original description',
  ]);
  $field->save();
  $this->applyAction('field.storage.entity_test.body');
  // The existing field should not be changed.
  $field = FieldConfig::loadByName('entity_test', '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('entity_test', '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.