You are here

protected function EntityFieldManagerTest::setUpEntityWithFieldDefinition in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php \Drupal\Tests\Core\Entity\EntityFieldManagerTest::setUpEntityWithFieldDefinition()

Prepares an entity that defines a field definition.

Parameters

bool $custom_invoke_all: (optional) Whether the test will set up its own ModuleHandlerInterface::invokeAll() implementation. Defaults to FALSE.

string $field_definition_id: (optional) The ID to use for the field definition. Defaults to 'id'.

array $entity_keys: (optional) An array of entity keys for the mocked entity type. Defaults to an empty array.

Return value

\Drupal\Core\Field\BaseFieldDefinition|\Prophecy\Prophecy\ProphecyInterface A field definition object.

10 calls to EntityFieldManagerTest::setUpEntityWithFieldDefinition()
EntityFieldManagerTest::testGetBaseFieldDefinitions in core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php
Tests the getBaseFieldDefinitions() method.
EntityFieldManagerTest::testGetBaseFieldDefinitionsInvalidDefinition in core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php
Tests the getBaseFieldDefinitions() method with an invalid definition.
EntityFieldManagerTest::testGetBaseFieldDefinitionsTranslatableEntityTypeDefaultLangcode in core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php
Tests the getBaseFieldDefinitions() method with a translatable entity type.
EntityFieldManagerTest::testGetBaseFieldDefinitionsTranslatableEntityTypeLangcode in core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php
Tests the getBaseFieldDefinitions() method with a translatable entity type.
EntityFieldManagerTest::testGetBaseFieldDefinitionsWithCaching in core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php
Tests the getBaseFieldDefinitions() method with caching.

... See full list

File

core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php, line 528
Contains \Drupal\Tests\Core\Entity\EntityFieldManagerTest.

Class

EntityFieldManagerTest
@coversDefaultClass \Drupal\Core\Entity\EntityFieldManager @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $field_definition_id = 'id', $entity_keys = []) {
  $field_type_manager = $this
    ->prophesize(FieldTypePluginManagerInterface::class);
  $field_type_manager
    ->getDefaultStorageSettings('boolean')
    ->willReturn([]);
  $field_type_manager
    ->getDefaultFieldSettings('boolean')
    ->willReturn([]);
  $this->container
    ->get('plugin.manager.field.field_type')
    ->willReturn($field_type_manager
    ->reveal());
  $string_translation = $this
    ->prophesize(TranslationInterface::class);
  $this->container
    ->get('string_translation')
    ->willReturn($string_translation
    ->reveal());
  $entity_class = EntityTypeManagerTestEntity::class;
  $field_definition = $this
    ->prophesize()
    ->willImplement(FieldDefinitionInterface::class)
    ->willImplement(FieldStorageDefinitionInterface::class);
  $entity_class::$baseFieldDefinitions = [
    $field_definition_id => $field_definition
      ->reveal(),
  ];
  $entity_class::$bundleFieldDefinitions = [];
  if (!$custom_invoke_all) {
    $this->moduleHandler
      ->getImplementations(Argument::cetera())
      ->willReturn([]);
  }

  // Mock the base field definition override.
  $override_entity_type = $this
    ->prophesize(EntityTypeInterface::class);
  $this->entityType = $this
    ->prophesize(EntityTypeInterface::class);
  $this
    ->setUpEntityTypeDefinitions([
    'test_entity_type' => $this->entityType,
    'base_field_override' => $override_entity_type,
  ]);
  $storage = $this
    ->prophesize(ConfigEntityStorageInterface::class);
  $storage
    ->loadMultiple(Argument::type('array'))
    ->willReturn([]);
  $this->entityTypeManager
    ->getStorage('base_field_override')
    ->willReturn($storage
    ->reveal());
  $this->entityType
    ->getClass()
    ->willReturn($entity_class);
  $this->entityType
    ->getKeys()
    ->willReturn($entity_keys + [
    'default_langcode' => 'default_langcode',
  ]);
  $this->entityType
    ->entityClassImplements(FieldableEntityInterface::class)
    ->willReturn(TRUE);
  $this->entityType
    ->isTranslatable()
    ->willReturn(FALSE);
  $this->entityType
    ->isRevisionable()
    ->willReturn(FALSE);
  $this->entityType
    ->getProvider()
    ->willReturn('the_provider');
  $this->entityType
    ->id()
    ->willReturn('the_entity_id');
  return $field_definition
    ->reveal();
}