You are here

public function ExtraFieldDisplayManagerTest::testEntityView in Extra Field 8.2

@covers ::entityView

@dataProvider entityViewProvider

Parameters

array $definitions: The plugin definitions as returned by ::getDefinitions().

string $entityType: The content entity type.

string $bundle: The content entity bundle.

bool $hasComponent: The has component flag as returned by EntityDisplayInterface::getComponent().

array $result: The ::entityView result.

File

tests/src/Unit/ExtraFieldDisplayManagerTest.php, line 302

Class

ExtraFieldDisplayManagerTest
@coversDefaultClass \Drupal\extra_field\Plugin\ExtraFieldDisplayManager

Namespace

Drupal\Tests\extra_field\Unit

Code

public function testEntityView(array $definitions, $entityType, $bundle, $hasComponent, array $result) {
  $this
    ->prepareDisplayManager([
    'getDefinitions',
    'getFactory',
  ]);
  $this
    ->prepareDefinitions($definitions);

  // Mock content entity.

  /** @var \Drupal\Core\Entity\ContentEntityInterface|\PHPUnit\Framework\MockObject\MockObject $contentEntity */
  $contentEntity = $this
    ->createMock('Drupal\\Core\\Entity\\ContentEntityInterface');
  $contentEntity
    ->expects($this
    ->any())
    ->method('getEntityTypeId')
    ->will($this
    ->returnValue($entityType));
  $contentEntity
    ->expects($this
    ->any())
    ->method('bundle')
    ->will($this
    ->returnValue($bundle));

  // Mock entity view display.

  /** @var \Drupal\Core\Entity\Entity\EntityViewDisplay|\PHPUnit\Framework\MockObject\MockObject $display */
  $display = $this
    ->createMock('Drupal\\Core\\Entity\\Entity\\EntityViewDisplay');
  $display
    ->expects($this
    ->any())
    ->method('getComponent')
    ->will($this
    ->returnValue($hasComponent));

  // Mock extra field display plugin.

  /** @var \Drupal\Component\Plugin\Factory\FactoryInterface|\PHPUnit\Framework\MockObject\MockObject $pluginFactory */
  $pluginFactory = $this
    ->createMock('Drupal\\Component\\Plugin\\Factory\\FactoryInterface');
  $pluginFactory
    ->expects($this
    ->any())
    ->method('createInstance')
    ->will($this
    ->returnValue($this
    ->createMockDisplayPlugin($contentEntity, $display, 'view_mode', [
    'mock' => 'display markup',
  ])));
  $this->displayManager
    ->expects($this
    ->any())
    ->method('getFactory')
    ->will($this
    ->returnValue($pluginFactory));
  $build = [];
  $this->displayManager
    ->entityView($build, $contentEntity, $display, 'view_mode');
  $this
    ->assertEquals($result, $build);
}