function EntityTypeManagerTest::setUpEntityTypeDefinitions

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

13 calls to EntityTypeManagerTest::setUpEntityTypeDefinitions()
EntityTypeManagerTest::testGetAccessControlHandler in core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php
Tests the getAccessControlHandler() method.
EntityTypeManagerTest::testGetDefinition in core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php
Tests the getDefinition() method.
EntityTypeManagerTest::testGetDefinitionInvalidException in core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php
Tests the getDefinition() method with an invalid definition.
EntityTypeManagerTest::testGetFormObject in core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php
Tests the getFormObject() method.
EntityTypeManagerTest::testGetFormObjectInvalidOperation in core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php
Tests the getFormObject() method with an invalid operation.

... See full list

File

core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php, line 98

Class

EntityTypeManagerTest
@coversDefaultClass \Drupal\Core\Entity\EntityTypeManager @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

protected function setUpEntityTypeDefinitions($definitions = []) {
    $class = get_class($this->createMock(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);
        $entity_type->setClass($class)
            ->willReturn($entity_type->reveal());
        $definitions[$key] = $entity_type->reveal();
    }
    $this->discovery
        ->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->discovery
        ->getDefinitions()
        ->willReturn($definitions);
}

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