function BlockComponentRenderArrayTest::testOnBuildRenderEmptyBuild

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. 8.9.x core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php \Drupal\Tests\layout_builder\Unit\BlockComponentRenderArrayTest::testOnBuildRenderEmptyBuild()
  3. 11.x 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 415

Class

BlockComponentRenderArrayTest
@coversDefaultClass \Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray[[api-linebreak]] @group layout_builder

Namespace

Drupal\Tests\layout_builder\Unit

Code

public function testOnBuildRenderEmptyBuild() : void {
  $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->assertEqualsCanonicalizing($expected_cache, $result);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.