function FieldDefinitionListenerTest::setUpEntityTypeManager

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php \Drupal\Tests\Core\Field\FieldDefinitionListenerTest::setUpEntityTypeManager()
  2. 10 core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php \Drupal\Tests\Core\Field\FieldDefinitionListenerTest::setUpEntityTypeManager()
  3. 11.x core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php \Drupal\Tests\Core\Field\FieldDefinitionListenerTest::setUpEntityTypeManager()

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.

5 calls to FieldDefinitionListenerTest::setUpEntityTypeManager()
FieldDefinitionListenerTest::testOnFieldDefinitionCreateExistingField in core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php
@covers ::onFieldDefinitionCreate
FieldDefinitionListenerTest::testOnFieldDefinitionCreateNewField in core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php
@covers ::onFieldDefinitionCreate
FieldDefinitionListenerTest::testOnFieldDefinitionDeleteMultipleBundles in core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php
@covers ::onFieldDefinitionDelete
FieldDefinitionListenerTest::testOnFieldDefinitionDeleteSingleBundles in core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php
@covers ::onFieldDefinitionDelete
FieldDefinitionListenerTest::testOnFieldDefinitionUpdate in core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php
@covers ::onFieldDefinitionUpdate

File

core/tests/Drupal/Tests/Core/Field/FieldDefinitionListenerTest.php, line 80

Class

FieldDefinitionListenerTest
@coversDefaultClass \Drupal\Core\Field\FieldDefinitionListener @group Field

Namespace

Drupal\Tests\Core\Field

Code

protected function setUpEntityTypeManager($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::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.