diff -u b/core/modules/system/src/Tests/Entity/EntityFormCorrectUserInputMappingOnFieldDeltaElementsTest.php b/core/modules/system/src/Tests/Entity/EntityFormCorrectUserInputMappingOnFieldDeltaElementsTest.php --- b/core/modules/system/src/Tests/Entity/EntityFormCorrectUserInputMappingOnFieldDeltaElementsTest.php +++ b/core/modules/system/src/Tests/Entity/EntityFormCorrectUserInputMappingOnFieldDeltaElementsTest.php @@ -5,6 +5,8 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityStorageInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; use Drupal\simpletest\WebTestBase; /** @@ -43,16 +45,27 @@ $web_user = $this->drupalCreateUser(['administer entity_test content']); $this->drupalLogin($web_user); - // Create a base field of field type "shape" with unlimited cardinality on - // the entity type entity_test_mulrev. - $this->entityTypeId = 'entity_test_mulrev'; - $this->fieldName = 'description'; - - $state = $this->container->get('state'); - $state->set('entity_test.multi_column', TRUE); - $state->set('entity_test.multi_column.cardinality', FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); - $this->container->get('entity.definition_update_manager')->applyUpdates(); - $this->container->get('entity_field.manager')->clearCachedFieldDefinitions(); + // Create a field of field type "shape" with unlimited cardinality on the + // entity type "entity_test". + $this->entityTypeId = 'entity_test'; + $this->fieldName = 'shape'; + + FieldStorageConfig::create([ + 'field_name' => $this->fieldName, + 'entity_type' => $this->entityTypeId, + 'type' => 'shape', + 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, + ]) + ->save(); + FieldConfig::create([ + 'entity_type' => $this->entityTypeId, + 'field_name' => $this->fieldName, + 'bundle' => $this->entityTypeId, + 'label' => 'Shape', + 'translatable' => FALSE, + ]) + ->save(); + entity_get_form_display($this->entityTypeId, $this->entityTypeId, 'default') ->setComponent($this->fieldName, ['type' => 'shape_only_color_editable_widget']) ->save(); @@ -65,10 +78,10 @@ /** @var ContentEntityStorageInterface $storage */ $storage = $this->container->get('entity_type.manager')->getStorage($this->entityTypeId); - /** @var ContentEntityInterface $entity1 */ + /** @var ContentEntityInterface $entity */ $entity = $storage->create([$this->fieldName => [ ['shape' => 'rectangle', 'color' => 'green'], - ['shape' => 'circle', 'color' => 'red'], + ['shape' => 'circle', 'color' => 'blue'], ]]); $entity->save(); @@ -87,12 +100,13 @@ $this->drupalPostForm(NULL, $edit, t('Add another item')); $this->drupalPostForm(NULL, [], t('Save')); + // Reload the entity. $entity = $storage->load($entity->id()); // Assert that after rearranging the field items the user input will be // mapped on the correct delta field items. $this->assertEqual($entity->get($this->fieldName)->getValue(), [ - ['shape' => 'circle', 'color' => 'red'], + ['shape' => 'circle', 'color' => 'blue'], ['shape' => 'rectangle', 'color' => 'green'], ]); }