function EntityTypeBundleInfoTest::setUpEntityTypeDefinitions

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php \Drupal\Tests\Core\Entity\EntityTypeBundleInfoTest::setUpEntityTypeDefinitions()
  2. 10 core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php \Drupal\Tests\Core\Entity\EntityTypeBundleInfoTest::setUpEntityTypeDefinitions()
  3. 11.x 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 <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21EntityTypeBundleInfo.php/class/EntityTypeBundleInfo/8.9.x" title="Provides discovery and retrieval of entity type bundles." class="local">\Drupal\Core\Entity\EntityTypeBundleInfo</a> @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);
}

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