function EntityUnitTest::testCacheTags
Same name and namespace in other branches
- 9 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 580
Class
- EntityUnitTest
- @coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21Entity.php/class/Entity/8.9.x" title="Defines a base entity class." class="local">\Drupal\Core\Entity\Entity</a> @group Entity @group Access
Namespace
Drupal\Tests\Core\EntityCode
public function testCacheTags() {
// Ensure that both methods return the same by default.
$this->assertEquals([
$this->entityTypeId . ':' . 1,
], $this->entity
->getCacheTags());
$this->assertEquals([
$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 = [
'additional_cache_tag',
$this->entityTypeId . ':' . 1,
];
sort($tags);
$this->assertEquals($tags, $this->entity
->getCacheTags());
$this->assertEquals([
$this->entityTypeId . ':' . 1,
], $this->entity
->getCacheTagsToInvalidate());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.