You are here

public function EntityManagerTest::testGetAllowedEntityTypes in Acquia Content Hub 8

Test for getAllowedEntityTypes() method.

@covers ::getAllowedEntityTypes

File

tests/src/Unit/EntityManagerTest.php, line 246

Class

EntityManagerTest
PHPUnit for the EntityManager class.

Namespace

Drupal\Tests\acquia_contenthub\Unit

Code

public function testGetAllowedEntityTypes() {
  $entity_manager = new EntityManager($this->loggerFactory, $this->configFactory, $this->clientManager, $this->contentHubEntitiesTracking, $this->entityTypeManager, $this->entityTypeBundleInfoManager, $this->kernel);
  $entity_types = [
    'content_entity_1' => $this->contentEntityType,
    'content_entity_2' => $this->contentEntityType,
    'comment' => $this->contentEntityType,
    'user' => $this->contentEntityType,
    'config_entity_1' => $this->configEntityType,
    'config_entity_2' => $this->configEntityType,
  ];
  $this->entityTypeManager
    ->expects($this
    ->once())
    ->method('getDefinitions')
    ->willReturn($entity_types);
  $bundles = [
    'bundle1' => [
      'label' => 'bundle1',
    ],
    'bundle2' => [
      'label' => 'bundle2',
    ],
  ];
  $this->entityTypeBundleInfoManager
    ->expects($this
    ->at(0))
    ->method('getBundleInfo')
    ->with('content_entity_1')
    ->willReturn($bundles);

  // Second content entity does not have bundles.
  $this->entityTypeBundleInfoManager
    ->expects($this
    ->at(1))
    ->method('getBundleInfo')
    ->with('content_entity_2')
    ->willReturn(NULL);
  $entity_types = $entity_manager
    ->getAllowedEntityTypes();

  // We expect that an entity without bundles shouldn't show up in the list.
  $expected_entity_types = [
    'content_entity_1' => [
      'bundle1' => 'bundle1',
      'bundle2' => 'bundle2',
    ],
  ];
  $this
    ->assertEquals($expected_entity_types, $entity_types);
}