function EntityUnitTest::testCacheTags
Same name in other branches
- 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php \Drupal\Tests\Core\Entity\EntityUnitTest::testCacheTags()
- 10 core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php \Drupal\Tests\Core\Entity\EntityUnitTest::testCacheTags()
- 11.x core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php \Drupal\Tests\Core\Entity\EntityUnitTest::testCacheTags()
@covers ::getCacheTags @covers ::getCacheTagsToInvalidate @covers ::addCacheTags
File
-
core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUnitTest.php, line 567
Class
- EntityUnitTest
- @coversDefaultClass \Drupal\Core\Entity\EntityBase @group Entity @group Access
Namespace
Drupal\Tests\Core\EntityCode
public function testCacheTags() {
// Ensure that both methods return the same by default.
$this->assertEqualsCanonicalizing([
$this->entityTypeId . ':' . 1,
], $this->entity
->getCacheTags());
$this->assertEqualsCanonicalizing([
$this->entityTypeId . ':' . 1,
], $this->entity
->getCacheTagsToInvalidate());
// Add an additional cache tag and make sure only getCacheTags() returns
// that.
$this->entity
->addCacheTags([
'additional_cache_tag',
]);
// EntityTypeId is random so it can shift order. We need to duplicate the
// sort from \Drupal\Core\Cache\Cache::mergeTags().
$tags = [
$this->entityTypeId . ':' . 1,
'additional_cache_tag',
];
$this->assertEqualsCanonicalizing($tags, $this->entity
->getCacheTags());
$this->assertEqualsCanonicalizing([
$this->entityTypeId . ':' . 1,
], $this->entity
->getCacheTagsToInvalidate());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.