function EntityFieldManagerTest::setUpEntityTypeDefinitions

Sets up the entity type manager to be tested.

Parameters

\Drupal\Core\Entity\EntityTypeInterface[]|\Prophecy\Prophecy\ProphecyInterface[] $definitions: (optional) An array of entity type definitions.

6 calls to EntityFieldManagerTest::setUpEntityTypeDefinitions()
EntityFieldManagerTest::setUpEntityWithFieldDefinition in core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php
Prepares an entity that defines a field definition.
EntityFieldManagerTest::testClearCachedFieldDefinitions in core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php
Tests the clearCachedFieldDefinitions() method.
EntityFieldManagerTest::testGetExtraFields in core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php
@covers ::getExtraFields[[api-linebreak]]
EntityFieldManagerTest::testGetFieldMap in core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php
@covers ::getFieldMap[[api-linebreak]]
EntityFieldManagerTest::testGetFieldMapByFieldType in core/tests/Drupal/Tests/Core/Entity/EntityFieldManagerTest.php
@covers ::getFieldMapByFieldType[[api-linebreak]]

... See full list

File

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

Class

EntityFieldManagerTest
@coversDefaultClass \Drupal\Core\Entity\EntityFieldManager[[api-linebreak]] @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

protected function setUpEntityTypeDefinitions($definitions = []) {
  $class = $this->getMockClass(EntityInterface::class);
  foreach ($definitions as $key => $entity_type) {
    // \Drupal\Core\Entity\EntityTypeInterface::getLinkTemplates() is called
    // by \Drupal\Core\Entity\EntityTypeManager::processDefinition() so it must
    // always be mocked.
    $entity_type->getLinkTemplates()
      ->willReturn([]);
    // Give the entity type a legitimate class to return.
    $entity_type->getClass()
      ->willReturn($class);
    $definitions[$key] = $entity_type->reveal();
  }
  $this->entityTypeManager
    ->getDefinition(Argument::type('string'))
    ->will(function ($args) use ($definitions) {
    if (isset($definitions[$args[0]])) {
      return $definitions[$args[0]];
    }
    throw new PluginNotFoundException($args[0]);
  });
  $this->entityTypeManager
    ->getDefinition(Argument::type('string'), FALSE)
    ->will(function ($args) use ($definitions) {
    if (isset($definitions[$args[0]])) {
      return $definitions[$args[0]];
    }
  });
  $this->entityTypeManager
    ->getDefinitions()
    ->willReturn($definitions);
}

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