function FieldDefinitionListenerTest::testOnFieldDefinitionCreateExistingField

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php \Drupal\Tests\Core\Field\FieldDefinitionListenerTest::testOnFieldDefinitionCreateExistingField()
  2. 8.9.x core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php \Drupal\Tests\Core\Field\FieldDefinitionListenerTest::testOnFieldDefinitionCreateExistingField()
  3. 11.x core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php \Drupal\Tests\Core\Field\FieldDefinitionListenerTest::testOnFieldDefinitionCreateExistingField()

@covers ::onFieldDefinitionCreate

File

core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php, line 142

Class

FieldDefinitionListenerTest
@coversDefaultClass \Drupal\Core\Field\FieldDefinitionListener[[api-linebreak]] @group Field

Namespace

Drupal\Tests\Core\Field

Code

public function testOnFieldDefinitionCreateExistingField() : void {
  $field_definition = $this->prophesize(FieldDefinitionInterface::class);
  $field_definition->getTargetEntityTypeId()
    ->willReturn('test_entity_type');
  $field_definition->getTargetBundle()
    ->willReturn('test_bundle');
  $field_definition->getName()
    ->willReturn('test_field');
  $storage = $this->prophesize(DynamicallyFieldableEntityStorageInterface::class);
  $storage->onFieldDefinitionCreate($field_definition->reveal())
    ->shouldBeCalledTimes(1);
  $this->entityTypeManager
    ->getStorage('test_entity_type')
    ->willReturn($storage->reveal());
  $entity = $this->prophesize(EntityTypeInterface::class);
  $this->setUpEntityTypeManager([
    'test_entity_type' => $entity,
  ]);
  // Set up the stored bundle field map.
  $key_value_store = $this->prophesize(KeyValueStoreInterface::class);
  $this->keyValueFactory
    ->get('entity.definitions.bundle_field_map')
    ->willReturn($key_value_store->reveal());
  $key_value_store->get('test_entity_type')
    ->willReturn([
    'test_field' => [
      'type' => 'test_type',
      'bundles' => [
        'existing_bundle' => 'existing_bundle',
      ],
    ],
  ]);
  $key_value_store->set('test_entity_type', [
    'test_field' => [
      'type' => 'test_type',
      'bundles' => [
        'existing_bundle' => 'existing_bundle',
        'test_bundle' => 'test_bundle',
      ],
    ],
  ])
    ->shouldBeCalled();
  $this->fieldDefinitionListener
    ->onFieldDefinitionCreate($field_definition->reveal());
}

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