function EntityTypeManagerTest::testGetDefinition

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php \Drupal\Tests\Core\Entity\EntityTypeManagerTest::testGetDefinition()
  2. 10 core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php \Drupal\Tests\Core\Entity\EntityTypeManagerTest::testGetDefinition()
  3. 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityTypeManagerTest.php \Drupal\Tests\Core\Entity\EntityTypeManagerTest::testGetDefinition()

Tests the getDefinition() method.

@covers ::getDefinition

@dataProvider providerTestGetDefinition

File

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

Class

EntityTypeManagerTest
@coversDefaultClass \Drupal\Core\Entity\EntityTypeManager[[api-linebreak]] @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetDefinition($entity_type_id, $expected) {
  $entity = $this->prophesize(EntityTypeInterface::class);
  $this->setUpEntityTypeDefinitions([
    'apple' => $entity,
    'banana' => $entity,
  ]);
  $entity_type = $this->entityTypeManager
    ->getDefinition($entity_type_id, FALSE);
  if ($expected) {
    $this->assertInstanceOf(EntityTypeInterface::class, $entity_type);
  }
  else {
    $this->assertNull($entity_type);
  }
}

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