You are here

public function EntityFieldManagerTest::testGetFieldStorageDefinitions in Drupal 8

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

Tests the getFieldStorageDefinitions() method.

@covers ::getFieldStorageDefinitions @covers ::buildFieldStorageDefinitions

File

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

Class

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

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetFieldStorageDefinitions() {
  $field_definition = $this
    ->setUpEntityWithFieldDefinition(TRUE);
  $field_storage_definition = $this
    ->prophesize(FieldStorageDefinitionInterface::class);
  $field_storage_definition
    ->getName()
    ->willReturn('field_storage');
  $definitions = [
    'field_storage' => $field_storage_definition
      ->reveal(),
  ];
  $this->moduleHandler
    ->getImplementations('entity_base_field_info')
    ->willReturn([]);
  $this->moduleHandler
    ->getImplementations('entity_field_storage_info')
    ->willReturn([
    'example_module',
  ]);
  $this->moduleHandler
    ->invoke('example_module', 'entity_field_storage_info', [
    $this->entityType,
  ])
    ->willReturn($definitions);
  $this->moduleHandler
    ->alter('entity_field_storage_info', $definitions, $this->entityType)
    ->willReturn(NULL);
  $expected = [
    'id' => $field_definition,
    'field_storage' => $field_storage_definition
      ->reveal(),
  ];
  $this
    ->assertSame($expected, $this->entityFieldManager
    ->getFieldStorageDefinitions('test_entity_type'));
}