You are here

protected function PanelizerEntityViewBuilderTest::setupView in Panelizer 8.4

Same name and namespace in other branches
  1. 8.5 tests/src/Unit/PanelizerEntityViewBuilderTest.php \Drupal\Tests\panelizer\Unit\PanelizerEntityViewBuilderTest::setupView()
  2. 8.3 tests/src/Unit/PanelizerEntityViewBuilderTest.php \Drupal\Tests\panelizer\Unit\PanelizerEntityViewBuilderTest::setupView()

Setups up the mock objects for testing view() and viewMultiple().

Return value

array An associative array with the following keys:

  • entities: Associative array of the mocked entity objects, keyed by the id.
  • expected: Associative array of the built render arrays keyed by the entity id.
2 calls to PanelizerEntityViewBuilderTest::setupView()
PanelizerEntityViewBuilderTest::testView in tests/src/Unit/PanelizerEntityViewBuilderTest.php
Tests view().
PanelizerEntityViewBuilderTest::testViewMultiple in tests/src/Unit/PanelizerEntityViewBuilderTest.php
Tests viewMultiple().

File

tests/src/Unit/PanelizerEntityViewBuilderTest.php, line 190

Class

PanelizerEntityViewBuilderTest
Tests the PanelizerEntityViewBuilder.

Namespace

Drupal\Tests\panelizer\Unit

Code

protected function setupView() {
  $entity1 = $this
    ->prophesize(FieldableEntityInterface::class);
  $entity1
    ->bundle()
    ->willReturn('abc');
  $entity1
    ->getEntityTypeId()
    ->willReturn('entity_type_id');
  $entity1
    ->id()
    ->willReturn(123);
  $entity1
    ->getCacheContexts()
    ->willReturn([
    'context',
  ]);
  $entity1
    ->getCacheTags()
    ->willReturn([
    'tag',
  ]);
  $entity1
    ->getCacheMaxAge()
    ->willReturn(123);
  $display1 = $this
    ->prophesize(EntityViewDisplayInterface::class);
  $display1
    ->getThirdPartySetting('panelizer', 'enable', FALSE)
    ->willReturn(TRUE);
  $entity2 = $this
    ->prophesize(FieldableEntityInterface::class);
  $entity2
    ->bundle()
    ->willReturn('xyz');
  $entity2
    ->getEntityTypeId()
    ->willReturn('entity_type_id');
  $display2 = $this
    ->prophesize(EntityViewDisplayInterface::class);
  $display2
    ->getThirdPartySetting('panelizer', 'enable', FALSE)
    ->willReturn(FALSE);
  $this->entityViewBuilder
    ->method('collectRenderDisplays')
    ->willReturn([
    'abc' => $display1
      ->reveal(),
    'xyz' => $display2
      ->reveal(),
  ]);
  $entity_context = $this
    ->prophesize(AutomaticContext::class);
  $this->entityViewBuilder
    ->method('getEntityContext')
    ->willReturn($entity_context
    ->reveal());
  $panels_display = $this
    ->prophesize(PanelsDisplayVariant::class);
  $other_context = $this
    ->prophesize(AutomaticContext::class);
  $panels_display
    ->getContexts()
    ->willReturn([
    'other' => $other_context
      ->reveal(),
  ]);
  $panels_display
    ->setContexts([
    'other' => $other_context
      ->reveal(),
    '@panelizer.entity_context:entity' => $entity_context
      ->reveal(),
  ])
    ->shouldBeCalled();
  $panels_display
    ->build()
    ->willReturn([
    '#markup' => 'Panelized',
  ]);
  $this->panelizer
    ->getPanelizerSettings('entity_type_id', 'abc', 'full', $display1
    ->reveal())
    ->willReturn([
    'default' => 'default',
  ]);
  $this->panelizer
    ->getDisplayStaticContexts('default', 'entity_type_id', 'abc', 'full', $display1
    ->reveal())
    ->willReturn([
    'other' => $other_context
      ->reveal(),
    '@panelizer.entity_context:entity' => $entity_context
      ->reveal(),
  ]);
  $this->panelizer
    ->getPanelsDisplay($entity1
    ->reveal(), 'full', $display1
    ->reveal())
    ->willReturn($panels_display
    ->reveal());
  $panels_display
    ->getCacheContexts()
    ->willReturn([]);
  $panels_display
    ->getCacheTags()
    ->willReturn([]);
  $panels_display
    ->getCacheMaxAge()
    ->willReturn(-1);
  return [
    'entities' => [
      123 => $entity1
        ->reveal(),
      234 => $entity2
        ->reveal(),
    ],
    'expected' => [
      123 => [
        '#theme' => [
          'panelizer_view_mode__entity_type_id__123',
          'panelizer_view_mode__entity_type_id__abc',
          'panelizer_view_mode__entity_type_id',
          'panelizer_view_mode',
        ],
        '#panelizer_plugin' => $this->panelizerPlugin
          ->reveal(),
        '#panels_display' => $panels_display
          ->reveal(),
        '#entity' => $entity1
          ->reveal(),
        '#view_mode' => 'full',
        '#langcode' => 'pl',
        'content' => [
          '#markup' => 'Panelized',
        ],
        '#cache' => [
          'tags' => [
            'tag',
          ],
          'contexts' => [
            'context',
          ],
          'max-age' => 123,
        ],
      ],
      234 => [
        '#markup' => 'Fallback',
      ],
    ],
  ];
}