function BlockViewBuilderTest::testEmptyRender

Tests rendering a block plugin that returns an empty array.

File

core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php, line 75

Class

BlockViewBuilderTest
Tests the block view builder.

Namespace

Drupal\Tests\block\Kernel

Code

public function testEmptyRender() : void {
  \Drupal::keyValue('block_test')->set('content', '');
  $entity = $this->controller
    ->create([
    'id' => 'test_block1',
    'theme' => 'stark',
    'plugin' => 'test_empty',
  ]);
  $entity->save();
  // Test the rendering of a block.
  $entity = Block::load('test_block1');
  $builder = \Drupal::entityTypeManager()->getViewBuilder('block');
  $output = $builder->view($entity, 'block');
  $expected_output = '';
  $this->assertSame($expected_output, (string) $this->renderer
    ->renderRoot($output));
}

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