public function BlockComponentRenderArrayTest::testOnBuildRenderDenied in Drupal 9
Same name and namespace in other branches
- 8 core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php \Drupal\Tests\layout_builder\Unit\BlockComponentRenderArrayTest::testOnBuildRenderDenied()
- 10 core/modules/layout_builder/tests/src/Unit/BlockComponentRenderArrayTest.php \Drupal\Tests\layout_builder\Unit\BlockComponentRenderArrayTest::testOnBuildRenderDenied()
@covers ::onBuildRender
@dataProvider providerBlockTypes
File
- core/
modules/ layout_builder/ tests/ src/ Unit/ BlockComponentRenderArrayTest.php, line 220
Class
- BlockComponentRenderArrayTest
- @coversDefaultClass \Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray @group layout_builder
Namespace
Drupal\Tests\layout_builder\UnitCode
public function testOnBuildRenderDenied($refinable_dependent_access) {
$contexts = [];
if ($refinable_dependent_access) {
$block = $this
->prophesize(TestBlockPluginWithRefinableDependentAccessInterface::class);
$layout_entity = $this
->prophesize(EntityInterface::class);
$layout_entity = $layout_entity
->reveal();
$context = $this
->prophesize(ContextInterface::class);
$context
->getContextValue()
->willReturn($layout_entity);
$contexts['layout_builder.entity'] = $context
->reveal();
$block
->setAccessDependency($layout_entity)
->shouldBeCalled();
}
else {
$block = $this
->prophesize(BlockPluginInterface::class);
}
$access_result = AccessResult::forbidden();
$block
->access($this->account
->reveal(), TRUE)
->willReturn($access_result)
->shouldBeCalled();
$block
->getCacheContexts()
->shouldNotBeCalled();
$block
->getCacheTags()
->shouldNotBeCalled();
$block
->getCacheMaxAge()
->shouldNotBeCalled();
$block
->getConfiguration()
->shouldNotBeCalled();
$block
->getPluginId()
->shouldNotBeCalled();
$block
->getBaseId()
->shouldNotBeCalled();
$block
->getDerivativeId()
->shouldNotBeCalled();
$block_content = [
'#markup' => 'The block content.',
];
$block
->build()
->willReturn($block_content);
$this->blockManager
->createInstance('some_block_id', [
'id' => 'some_block_id',
])
->willReturn($block
->reveal());
$component = new SectionComponent('some-uuid', 'some-region', [
'id' => 'some_block_id',
]);
$in_preview = FALSE;
$event = new SectionComponentBuildRenderArrayEvent($component, $contexts, $in_preview);
$subscriber = new BlockComponentRenderArray($this->account
->reveal());
$expected_build = [];
$expected_cache = [
'#cache' => [
'contexts' => [],
'tags' => [],
'max-age' => -1,
],
];
$subscriber
->onBuildRender($event);
$result = $event
->getBuild();
$this
->assertEquals($expected_build, $result);
$event
->getCacheableMetadata()
->applyTo($result);
$this
->assertEquals($expected_cache, $result);
}