public function BlockPageVariantTest::testBuild in Drupal 10
Same name and namespace in other branches
- 8 core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php \Drupal\Tests\block\Unit\Plugin\DisplayVariant\BlockPageVariantTest::testBuild()
- 9 core/modules/block/tests/src/Unit/Plugin/DisplayVariant/BlockPageVariantTest.php \Drupal\Tests\block\Unit\Plugin\DisplayVariant\BlockPageVariantTest::testBuild()
Tests the building of a full page variant.
@covers ::build
@dataProvider providerBuild
File
- core/
modules/ block/ tests/ src/ Unit/ Plugin/ DisplayVariant/ BlockPageVariantTest.php, line 204
Class
- BlockPageVariantTest
- @coversDefaultClass \Drupal\block\Plugin\DisplayVariant\BlockPageVariant @group block
Namespace
Drupal\Tests\block\Unit\Plugin\DisplayVariantCode
public function testBuild(array $blocks_config, $visible_block_count, array $expected_render_array) {
$display_variant = $this
->setUpDisplayVariant();
$display_variant
->setMainContent([
'#markup' => 'Hello kittens!',
]);
$blocks = [
'top' => [],
'center' => [],
'bottom' => [],
];
$block_plugin = $this
->createMock('Drupal\\Core\\Block\\BlockPluginInterface');
$main_content_block_plugin = $this
->createMock('Drupal\\Core\\Block\\MainContentBlockPluginInterface');
$messages_block_plugin = $this
->createMock('Drupal\\Core\\Block\\MessagesBlockPluginInterface');
$title_block_plugin = $this
->createMock('Drupal\\Core\\Block\\TitleBlockPluginInterface');
foreach ($blocks_config as $block_id => $block_config) {
$block = $this
->createMock('Drupal\\block\\BlockInterface');
$block
->expects($this
->atLeastOnce())
->method('getPlugin')
->willReturn($block_config[1] ? $main_content_block_plugin : ($block_config[2] ? $messages_block_plugin : ($block_config[3] ? $title_block_plugin : $block_plugin)));
$blocks[$block_config[0]][$block_id] = $block;
}
$this->blockViewBuilder
->expects($this
->exactly($visible_block_count))
->method('view')
->will($this
->returnValue([]));
$this->blockRepository
->expects($this
->once())
->method('getVisibleBlocksPerRegion')
->willReturnCallback(function (&$cacheable_metadata) use ($blocks) {
$cacheable_metadata['top'] = (new CacheableMetadata())
->addCacheTags([
'route',
]);
return $blocks;
});
$value = $display_variant
->build();
$this
->assertSame($expected_render_array, $value);
}