function RendererBubblingTest::testContextBubblingCustomCacheBin
Same name in other branches
- 8.9.x core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php \Drupal\Tests\Core\Render\RendererBubblingTest::testContextBubblingCustomCacheBin()
- 10 core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php \Drupal\Tests\Core\Render\RendererBubblingTest::testContextBubblingCustomCacheBin()
- 11.x core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php \Drupal\Tests\Core\Render\RendererBubblingTest::testContextBubblingCustomCacheBin()
Tests cache context bubbling with a custom cache bin.
File
-
core/
tests/ Drupal/ Tests/ Core/ Render/ RendererBubblingTest.php, line 80
Class
- RendererBubblingTest
- @coversDefaultClass \Drupal\Core\Render\Renderer @group Render
Namespace
Drupal\Tests\Core\RenderCode
public function testContextBubblingCustomCacheBin() {
$bin = $this->randomMachineName();
$this->setUpRequest();
$this->memoryCache = new MemoryBackend();
$custom_cache = new MemoryBackend();
$this->cacheFactory
->expects($this->atLeastOnce())
->method('get')
->with($bin)
->willReturnCallback(function ($requested_bin) use ($bin, $custom_cache) {
if ($requested_bin === $bin) {
return $custom_cache;
}
else {
throw new \Exception();
}
});
$this->cacheContextsManager
->expects($this->any())
->method('convertTokensToKeys')
->willReturnArgument(0);
$build = [
'#cache' => [
'keys' => [
'parent',
],
'contexts' => [
'foo',
],
'bin' => $bin,
],
'#markup' => 'parent',
'child' => [
'#cache' => [
'contexts' => [
'bar',
],
'max-age' => 3600,
],
],
];
$this->renderer
->renderRoot($build);
$this->assertRenderCacheItem('parent:foo', [
'#cache_redirect' => TRUE,
'#cache' => [
'keys' => [
'parent',
],
'contexts' => [
'foo',
'bar',
],
'tags' => [],
'bin' => $bin,
'max-age' => 3600,
],
], $bin);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.