public function testBlockViewBuilderViewAlter() { // Establish baseline.
$build =
$this->
getBlockRenderArray();
$this->
setRawContent((string) $this->renderer->
renderRoot($build));
$this->
assertSame('Llamas > unicorns!',
trim((string) $this->
cssSelect('div'
)[0
]));
// Enable the block view alter hook that adds a foo=bar attribute.
\Drupal::
state()->
set('block_test_view_alter_suffix', TRUE
);
Cache::
invalidateTags($this->block->
getCacheTagsToInvalidate());
$build =
$this->
getBlockRenderArray();
$this->
setRawContent((string) $this->renderer->
renderRoot($build));
$this->
assertSame('Llamas > unicorns!',
trim((string) $this->
cssSelect('[foo=bar]'
)[0
]));
\Drupal::
state()->
set('block_test_view_alter_suffix', FALSE
);
\Drupal::
state()->
set('block_test.content', NULL
);
Cache::
invalidateTags($this->block->
getCacheTagsToInvalidate());
// Advanced: cached block, but an alter hook adds a #pre_render callback to
// alter the eventual content.
\Drupal::
state()->
set('block_test_view_alter_append_pre_render_prefix', TRUE
);