function ManageFieldsTest::testEditFieldWithLeftOverFieldInTempStore

Same name and namespace in other branches
  1. 11.x core/modules/field_ui/tests/src/Functional/ManageFieldsTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsTest::testEditFieldWithLeftOverFieldInTempStore()

Tests editing field when the field exists in temp store.

File

core/modules/field_ui/tests/src/Functional/ManageFieldsTest.php, line 264

Class

ManageFieldsTest
Tests the Manage Display page of a fieldable entity type.

Namespace

Drupal\Tests\field_ui\Functional

Code

public function testEditFieldWithLeftOverFieldInTempStore() : void {
  $user = $this->drupalCreateUser([
    'administer node fields',
  ]);
  $node_type = $this->drupalCreateContentType();
  $bundle_path = '/admin/structure/types/manage/' . $node_type->id();
  // Start adding a field but stop prior to saving.
  $this->drupalLogin($user);
  $this->drupalGet($bundle_path . '/fields/add-field');
  $edit = [
    'new_storage_type' => 'test_field',
  ];
  $this->submitForm($edit, 'Continue');
  $edit = [
    'label' => 'Test field',
    'field_name' => 'test_field',
  ];
  $this->submitForm($edit, 'Continue');
  /** @var \Drupal\field\FieldStorageConfigInterface $storage */
  $storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('field_storage_config')
    ->create([
    'type' => 'test_field',
    'field_name' => 'test_field',
    'entity_type' => 'node',
  ]);
  $storage->save();
  $this->container
    ->get('entity_type.manager')
    ->getStorage('field_config')
    ->create([
    'field_storage' => $storage,
    'bundle' => $node_type->id(),
    'entity_type' => 'node',
  ])
    ->save();
  $this->drupalGet("{$bundle_path}/fields/node.{$node_type->id()}.test_field");
  $this->submitForm([], 'Save settings');
  $this->assertSession()
    ->statusMessageContains('Saved test_field configuration.', 'status');
}

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