function SimplePageVariantTest::testCacheMetadataFromPlugin
Tests that cache metadata in the plugin are present in the build.
@legacy-covers ::build
File
-
core/
tests/ Drupal/ Tests/ Core/ Render/ Plugin/ DisplayVariant/ SimplePageVariantTest.php, line 100
Class
Namespace
Drupal\Tests\Core\Render\Plugin\DisplayVariantCode
public function testCacheMetadataFromPlugin() : void {
$display_variant = $this->setUpDisplayVariant();
$route_match = $this->createMock(RouteMatchInterface::class);
$event = new PageDisplayVariantSelectionEvent($display_variant->getPluginId(), $route_match);
$event->addCacheTags([
'my_tag',
]);
$event->addCacheContexts([
'my_context',
]);
$event->mergeCacheMaxAge(50);
$display_variant->addCacheableDependency($event);
$expectedCache = [
'contexts' => [
'my_context',
],
'tags' => [
'my_tag',
],
'max-age' => 50,
];
$this->assertSame($expectedCache, $display_variant->build()['#cache']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.