function AddToAllBundlesConfigActionTest::testFailIfExists

Tests that the action can be set to fail if the field already exists.

File

core/modules/field/tests/src/Kernel/AddToAllBundlesConfigActionTest.php, line 103

Class

AddToAllBundlesConfigActionTest
Tests Add To All Bundles Config Action.

Namespace

Drupal\Tests\field\Kernel

Code

public function testFailIfExists() : 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' => 'Body',
  ]);
  $field->save();
  $this->expectException(ConfigActionException::class);
  $this->expectExceptionMessage('Field entity_test.one.body already exists.');
  $this->applyAction('field.storage.entity_test.body', TRUE);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.