You are here

protected function EntityTypeBundleInfoTest::setUpEntityTypeDefinitions in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php \Drupal\Tests\Core\Entity\EntityTypeBundleInfoTest::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.

4 calls to EntityTypeBundleInfoTest::setUpEntityTypeDefinitions()
EntityTypeBundleInfoTest::testClearCachedBundles in core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php
Tests the clearCachedBundles() method.
EntityTypeBundleInfoTest::testGetAllBundleInfo in core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php
Tests the getAllBundleInfo() method.
EntityTypeBundleInfoTest::testGetAllBundleInfoWithEntityBundleInfo in core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php
@covers ::getAllBundleInfo
EntityTypeBundleInfoTest::testGetBundleInfo in core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php
Tests the getBundleInfo() method.

File

core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php, line 115

Class

EntityTypeBundleInfoTest
@coversDefaultClass \Drupal\Core\Entity\EntityTypeBundleInfo @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\EntitTypeManager::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::cetera())
    ->will(function ($args) use ($definitions) {
    $entity_type_id = $args[0];
    $exception_on_invalid = $args[1];
    if (isset($definitions[$entity_type_id])) {
      return $definitions[$entity_type_id];
    }
    elseif (!$exception_on_invalid) {
      return NULL;
    }
    else {
      throw new PluginNotFoundException($entity_type_id);
    }
  });
  $this->entityTypeManager
    ->getDefinitions()
    ->willReturn($definitions);
}