public function EntityUnitTest::testCacheTags in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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 494 - Contains \Drupal\Tests\Core\Entity\EntityUnitTest.
Class
- EntityUnitTest
- @coversDefaultClass \Drupal\Core\Entity\Entity @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());
}