/** * @covers ::getCacheTags * @covers ::getCacheTagsToInvalidate * @covers ::addCacheTags */ 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()); }