function EntityFieldManagerTest::testGetFieldStorageDefinitions

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php \Drupal\Tests\Core\Entity\EntityFieldManagerTest::testGetFieldStorageDefinitions()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php \Drupal\Tests\Core\Entity\EntityFieldManagerTest::testGetFieldStorageDefinitions()
  3. 10 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 298

Class

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

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetFieldStorageDefinitions() : void {
    $field_definition = $this->setUpEntityWithFieldDefinition(TRUE);
    $field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class);
    $field_storage_definition->getName()
        ->willReturn('field_storage');
    $base_field_definition = $this->prophesize(BaseFieldDefinition::class);
    $base_field_definition->setProvider('example_module')
        ->shouldBeCalled();
    $base_field_definition->setName('base_field')
        ->shouldBeCalled();
    $base_field_definition->setTargetEntityTypeId('test_entity_type')
        ->shouldBeCalled();
    $definitions = [
        'base_field' => $base_field_definition->reveal(),
        'field_storage' => $field_storage_definition->reveal(),
    ];
    $this->moduleHandler
        ->invokeAllWith('entity_base_field_info', Argument::any());
    $this->moduleHandler
        ->invokeAllWith('entity_field_storage_info', Argument::any())
        ->will(function ($arguments) use ($definitions) {
        [
            $hook,
            $callback,
        ] = $arguments;
        $callback(function () use ($definitions) {
            return $definitions;
        }, 'example_module');
    });
    $this->moduleHandler
        ->alter('entity_field_storage_info', $definitions, $this->entityType)
        ->willReturn(NULL);
    $expected = [
        'id' => $field_definition,
        'base_field' => $base_field_definition->reveal(),
        'field_storage' => $field_storage_definition->reveal(),
    ];
    $this->assertSame($expected, $this->entityFieldManager
        ->getFieldStorageDefinitions('test_entity_type'));
}

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