public function RendererBubblingTest::testContextBubblingCustomCacheBin in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php \Drupal\Tests\Core\Render\RendererBubblingTest::testContextBubblingCustomCacheBin()
- 9 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 - Contains \Drupal\Tests\Core\Render\RendererBubblingTest.
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);
}