You are here

public function BlockComponentRenderArrayTest::testOnBuildRenderEmptyBuild in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php \Drupal\Tests\layout_builder\Unit\BlockComponentRenderArrayTest::testOnBuildRenderEmptyBuild()
  2. 10 core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php \Drupal\Tests\layout_builder\Unit\BlockComponentRenderArrayTest::testOnBuildRenderEmptyBuild()

@covers ::onBuildRender

File

core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php, line 407

Class

BlockComponentRenderArrayTest
@coversDefaultClass \Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray @group layout_builder

Namespace

Drupal\Tests\layout_builder\Unit

Code

public function testOnBuildRenderEmptyBuild() {
  $block = $this
    ->prophesize(BlockPluginInterface::class);
  $access_result = AccessResult::allowed();
  $block
    ->access($this->account
    ->reveal(), TRUE)
    ->willReturn($access_result)
    ->shouldBeCalled();
  $block
    ->getCacheContexts()
    ->willReturn([]);
  $block
    ->getCacheTags()
    ->willReturn([
    'test',
  ]);
  $block
    ->getCacheMaxAge()
    ->willReturn(Cache::PERMANENT);
  $block
    ->getConfiguration()
    ->willReturn([]);
  $block
    ->getPluginId()
    ->willReturn('block_plugin_id');
  $block
    ->getBaseId()
    ->willReturn('block_plugin_id');
  $block
    ->getDerivativeId()
    ->willReturn(NULL);
  $block
    ->build()
    ->willReturn([
    '#cache' => [
      'tags' => [
        'build-tag',
      ],
    ],
  ]);
  $this->blockManager
    ->createInstance('some_block_id', [
    'id' => 'some_block_id',
  ])
    ->willReturn($block
    ->reveal());
  $component = new SectionComponent('some-uuid', 'some-region', [
    'id' => 'some_block_id',
  ]);
  $event = new SectionComponentBuildRenderArrayEvent($component, [], FALSE);
  $subscriber = new BlockComponentRenderArray($this->account
    ->reveal());
  $expected_build = [];
  $expected_cache = $expected_build + [
    '#cache' => [
      'contexts' => [],
      'tags' => [
        'build-tag',
        'test',
      ],
      'max-age' => -1,
    ],
  ];
  $subscriber
    ->onBuildRender($event);
  $result = $event
    ->getBuild();
  $this
    ->assertEquals($expected_build, $result);
  $event
    ->getCacheableMetadata()
    ->applyTo($result);
  $this
    ->assertEquals($expected_cache, $result);
}