3 namespace Drupal\Tests\Core\Cache;
5 use Drupal\Core\Cache\CacheTagsInvalidator;
6 use Drupal\Core\DependencyInjection\Container;
7 use Drupal\Tests\UnitTestCase;
10 * @coversDefaultClass \Drupal\Core\Cache\CacheTagsInvalidator
13 class CacheTagsInvalidatorTest extends UnitTestCase {
16 * @covers ::invalidateTags
18 public function testInvalidateTagsWithInvalidTags() {
19 $cache_tags_invalidator = new CacheTagsInvalidator();
20 $this->setExpectedException(\AssertionError::class);
21 $cache_tags_invalidator->invalidateTags(['node' => [2, 3, 5, 8, 13]]);
25 * @covers ::invalidateTags
26 * @covers ::addInvalidator
28 public function testInvalidateTags() {
29 $cache_tags_invalidator = new CacheTagsInvalidator();
31 // This does not actually implement,
32 // \Drupal\Cache\Cache\CacheBackendInterface but we can not mock from two
33 // interfaces, we would need a test class for that.
34 $invalidator_cache_bin = $this->getMock('\Drupal\Core\Cache\CacheTagsInvalidator');
35 $invalidator_cache_bin->expects($this->once())
36 ->method('invalidateTags')
39 // We do not have to define that invalidateTags() is never called as the
40 // interface does not define that method, trying to call it would result in
42 $non_invalidator_cache_bin = $this->getMock('\Drupal\Core\Cache\CacheBackendInterface');
44 $container = new Container();
45 $container->set('cache.invalidator_cache_bin', $invalidator_cache_bin);
46 $container->set('cache.non_invalidator_cache_bin', $non_invalidator_cache_bin);
47 $container->setParameter('cache_bins', ['cache.invalidator_cache_bin' => 'invalidator_cache_bin', 'cache.non_invalidator_cache_bin' => 'non_invalidator_cache_bin']);
48 $cache_tags_invalidator->setContainer($container);
50 $invalidator = $this->getMock('\Drupal\Core\Cache\CacheTagsInvalidator');
51 $invalidator->expects($this->once())
52 ->method('invalidateTags')
55 $cache_tags_invalidator->addInvalidator($invalidator);
57 $cache_tags_invalidator->invalidateTags(['node:1']);