function EntityOperationsCacheabilityTest::testEntityOperationsCacheability
Test cacheability is added via entity operations functions and hooks.
See also
\Drupal\Core\Entity\EntityListBuilder::getOperations()
\Drupal\Core\Entity\EntityListBuilder::getDefaultOperations()
\Drupal\entity_test\Hook\EntityTestHooks::entityOperation()
\Drupal\entity_test\Hook\EntityTestHooks::entityOperationAlter()
File
-
core/
modules/ system/ tests/ src/ Kernel/ Entity/ EntityOperationsCacheabilityTest.php, line 26
Class
- EntityOperationsCacheabilityTest
- Tests cacheability added by entity operations.
Namespace
Drupal\Tests\system\Kernel\EntityCode
public function testEntityOperationsCacheability() : void {
$entity = EntityTest::create([
'name' => 'Test entity',
]);
$entity->save();
$listBuilder = \Drupal::entityTypeManager()->getListBuilder('entity_test');
$cacheability = new CacheableMetadata();
$listBuilder->getOperations($entity, $cacheability);
$this->assertEquals([
'entity_test_operation_tag_test',
'entity_test_operation_alter_tag_test',
], $cacheability->getCacheTags());
$this->assertEquals([
'user.permissions',
], $cacheability->getCacheContexts());
$this->assertEquals(-1, $cacheability->getCacheMaxAge());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.