You are here

public function ContentHubEntityEmbedHandlerTest::testGetReferencedEntities in Acquia Content Hub 8

Test for getReferencedEntities method.

@covers ::getReferencedEntities

File

tests/src/Unit/ContentHubEntityEmbedHandlerTest.php, line 92

Class

ContentHubEntityEmbedHandlerTest
PHPUnit for the ContentHubEntityEmbedHandler class.

Namespace

Drupal\Tests\acquia_contenthub\Unit

Code

public function testGetReferencedEntities() {
  $uuid = "00000000-1111-0000-0000-000000000000";
  $type = "media";
  $entity = $this
    ->createMock('\\Drupal\\Core\\Entity\\EntityInterface');
  $entity
    ->method('uuid')
    ->willReturn($uuid);
  $entity_storage = $this
    ->createMock('\\Drupal\\Core\\Entity\\EntityStorageInterface');
  $expected = [
    $uuid => $entity,
  ];
  $entity_storage
    ->expects($this
    ->once())
    ->method('loadByProperties')
    ->with([
    'uuid' => $uuid,
  ])
    ->willReturn($expected);
  $this->entityTypeManager
    ->expects($this
    ->once())
    ->method('getStorage')
    ->with($type)
    ->willReturn($entity_storage);
  $text = '<drupal-entity data-caption="some_image" data-embed-button="media_browser" data-entity-embed-display="view_mode:media.embedded" data-entity-type="' . $type . '" data-entity-uuid="' . $uuid . '"></drupal-entity>';
  $this->field
    ->expects($this
    ->once())
    ->method('getString')
    ->willReturn($text);
  $result = $this->entityEmbedHandler
    ->getReferencedEntities();
  $this
    ->assertEquals($expected, $result);
}