You are here

public function EntityTypedDataDefinitionTest::testEntityDefinitionIsInternal in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/EntityTypedDataDefinitionTest.php \Drupal\KernelTests\Core\Entity\EntityTypedDataDefinitionTest::testEntityDefinitionIsInternal()

Tests that an entity annotation can mark the data definition as internal.

@dataProvider entityDefinitionIsInternalProvider

File

core/tests/Drupal/KernelTests/Core/Entity/EntityTypedDataDefinitionTest.php, line 149

Class

EntityTypedDataDefinitionTest
Tests deriving metadata of entity and field data types.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testEntityDefinitionIsInternal($internal, $expected) {
  $entity_type_id = $this
    ->randomMachineName();
  $entity_type = $this
    ->prophesize(EntityTypeInterface::class);
  $entity_type
    ->entityClassImplements(ConfigEntityInterface::class)
    ->willReturn(FALSE);
  $entity_type
    ->getKey('bundle')
    ->willReturn(FALSE);
  $entity_type
    ->getLabel()
    ->willReturn($this
    ->randomString());
  $entity_type
    ->getConstraints()
    ->willReturn([]);
  $entity_type
    ->isInternal()
    ->willReturn($internal);
  $entity_type
    ->getBundleEntityType()
    ->willReturn(NULL);
  $entity_type_manager = $this
    ->prophesize(EntityTypeManagerInterface::class);
  $entity_type_manager
    ->getDefinitions()
    ->willReturn([
    $entity_type_id => $entity_type
      ->reveal(),
  ]);
  $this->container
    ->set('entity_type.manager', $entity_type_manager
    ->reveal());
  $entity_data_definition = EntityDataDefinition::create($entity_type_id);
  $this
    ->assertSame($expected, $entity_data_definition
    ->isInternal());
}