public function BlockPreviewRendererTest::testBlockWithPreviewCallback in Panopoly Magic 8.2
Tests a block that has been altered to use a preview callback.
File
- tests/
src/ Unit/ BlockPreviewRendererTest.php, line 200
Class
- BlockPreviewRendererTest
- Unit tests for the BlockPreviewRenderer.
Namespace
Drupal\Tests\panopoly_magic\UnitCode
public function testBlockWithPreviewCallback() {
$block_id = 'block_with_preview_callback';
$block_definition = [
'id' => $block_id,
'admin_label' => 'Block with preview callback',
'preview_callback' => [
$this,
'previewCallback',
],
];
/** @var \Drupal\Core\Block\BlockPluginInterface|\Prophecy\Prophecy\ObjectProphecy $block_plugin */
$block_plugin = $this
->prophesize(BlockPluginInterface::class);
$block_plugin
->build()
->willReturn([
'#markup' => 'Normal block content',
])
->shouldNotBeCalled();
$this->blockManager
->getDefinition($block_id)
->willReturn($block_definition);
$this->blockManager
->createInstance($block_id)
->willReturn($block_plugin
->reveal());
$rendered = $this->renderer
->buildBlockPreview($block_id);
$this
->assertEquals([
'#markup' => 'Block preview callback content',
], $rendered);
}