protected function MemberCountBlockTest::doAssertCached in Organic groups 8
Checks the cache status of the block for the given group.
Parameters
string $assert_method: The method to use for asserting that the block is cached or not cached.
int $group_key: The key of the group for which to check the block cache status.
2 calls to MemberCountBlockTest::doAssertCached()
- MemberCountBlockTest::assertCached in tests/
src/ Kernel/ Plugin/ Block/ MemberCountBlockTest.php - Checks that the block is cached for the given group.
- MemberCountBlockTest::assertNotCached in tests/
src/ Kernel/ Plugin/ Block/ MemberCountBlockTest.php - Checks that the block is not cached for the given group.
File
- tests/
src/ Kernel/ Plugin/ Block/ MemberCountBlockTest.php, line 343
Class
- MemberCountBlockTest
- Tests the member count block.
Namespace
Drupal\Tests\og\Kernel\Plugin\BlockCode
protected function doAssertCached($assert_method, $group_key) {
// We will switch the currently active context so that the right cache
// contexts are available for the render cache. Keep track of the currently
// active group so we can restore it after checking the cache status.
$original_active_group = $this->activeGroup;
$this->activeGroup = $this->groups[$group_key];
// Retrieve the block to render, and apply the required cache contexts that
// are also applied when RendererInterface::renderRoot() is executed. This
// ensures that we pass the same cache information to the render cache as is
// done when actually rendering the HTML root.
$render_array = $this->blockViewBuilder
->view($this->block);
$render_array['#cache']['contexts'] = Cache::mergeContexts($render_array['#cache']['contexts'], $this->container
->getParameter('renderer.config')['required_cache_contexts']);
// Retrieve the cached data and perform the assertion.
$cached_data = $this->renderCache
->get($render_array);
$this
->{$assert_method}($cached_data);
// Restore the active group.
$this->activeGroup = $original_active_group;
}