function EntityFieldManagerTest::testGetFieldDefinitionsProvider

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

Tests that getFieldDefinitions() method sets the 'provider' definition key.

@covers ::getFieldDefinitions @covers ::buildBundleFieldDefinitions

File

core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php, line 545

Class

EntityFieldManagerTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21EntityFieldManager.php/class/EntityFieldManager/10" title="Manages the discovery of entity fields." class="local">\Drupal\Core\Entity\EntityFieldManager</a> @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetFieldDefinitionsProvider() {
    $this->setUpEntityWithFieldDefinition(TRUE);
    $module = 'entity_field_manager_test_module';
    // @todo Mock FieldDefinitionInterface once it exposes a proper provider
    //   setter. See https://www.drupal.org/node/2225961.
    $field_definition = $this->prophesize(BaseFieldDefinition::class);
    // We expect two calls as the field definition will be returned from both
    // base and bundle entity field info hook implementations.
    $field_definition->getProvider()
        ->shouldBeCalled();
    $field_definition->setProvider($module)
        ->shouldBeCalledTimes(2);
    $field_definition->setName(0)
        ->shouldBeCalledTimes(2);
    $field_definition->setTargetEntityTypeId('test_entity_type')
        ->shouldBeCalled();
    $field_definition->setTargetBundle(NULL)
        ->shouldBeCalled();
    $field_definition->setTargetBundle('test_bundle')
        ->shouldBeCalled();
    $this->moduleHandler
        ->invokeAllWith(Argument::type('string'), Argument::any())
        ->will(function ($arguments) use ($field_definition, $module) {
        [
            $hook,
            $callback,
        ] = $arguments;
        $callback(function () use ($field_definition) {
            return [
                $field_definition->reveal(),
            ];
        }, $module);
    });
    $this->entityFieldManager
        ->getFieldDefinitions('test_entity_type', 'test_bundle');
}

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