function BlockViewBuilderTest::testBlockViewBuilderCacheTitleBlock

Tests title block render cache handling.

See also

\Drupal\block_test\Hook\BlockTestHooks::blockViewPageTitleBlockAlter()

File

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

Class

BlockViewBuilderTest
Tests the block view builder.

Namespace

Drupal\Tests\block\Kernel

Code

public function testBlockViewBuilderCacheTitleBlock() : void {
  // Create title block.
  $this->block = $this->controller
    ->create([
    'id' => 'test_block_title',
    'theme' => 'stark',
    'plugin' => 'page_title_block',
  ]);
  $this->block
    ->save();
  $entity = Block::load('test_block_title');
  $builder = \Drupal::entityTypeManager()->getViewBuilder('block');
  $output = $builder->view($entity, 'block');
  $this->assertSame([
    'block_view',
    'config:block.block.test_block_title',
    'custom_cache_tag',
  ], $output['#cache']['tags']);
}

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