public function BlockViewTest::testViewBlockWithUnexpectedBlockValue in Collapsiblock 3.x
Same name and namespace in other branches
- 4.x tests/src/Kernel/BlockViewTest.php \Drupal\Tests\collapsiblock\Kernel\BlockViewTest::testViewBlockWithUnexpectedBlockValue()
Tests viewing a block with an unexpected value for '#block'.
File
- tests/
src/ Kernel/ BlockViewTest.php, line 70
Class
- BlockViewTest
- Tests viewing blocks with Collapsiblock enabled.
Namespace
Drupal\Tests\collapsiblock\KernelCode
public function testViewBlockWithUnexpectedBlockValue() {
// Create a block plugin instance.
$block_instance = $this->container
->get('plugin.manager.block')
->createInstance('test_html', []);
// Create a render array representing a block, but put an unexpected value
// in '#block'.
$base_id = $block_instance
->getBaseId();
$build = [
'#theme' => 'block',
'#attributes' => [],
'#configuration' => $block_instance
->getConfiguration(),
'#plugin_id' => $block_instance
->getPluginId(),
'#base_plugin_id' => $base_id,
'#derivative_plugin_id' => $block_instance
->getDerivativeId(),
'#id' => $block_instance
->getMachineNameSuggestion(),
// Put an unexpected value in '#block'.
'#block' => 'foo',
'content' => $block_instance
->build(),
];
// Invoke the hook_block_view_alter() hook.
$this->container
->get('module_handler')
->alter([
'block_view',
"block_view_{$base_id}",
], $build, $block_instance);
$expected = [];
$expected[] = '<div id="block-testhtmlblock">';
$expected[] = ' ';
$expected[] = ' ';
$expected[] = ' ';
$expected[] = ' </div>';
$expected[] = '';
$expected_output = implode("\n", $expected);
$this
->assertEquals($expected_output, $this->renderer
->renderRoot($build));
}