Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Cache / CacheTagsInvalidatorTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Cache;
4
5 use Drupal\Core\Cache\CacheTagsInvalidator;
6 use Drupal\Core\DependencyInjection\Container;
7 use Drupal\Tests\UnitTestCase;
8
9 /**
10  * @coversDefaultClass \Drupal\Core\Cache\CacheTagsInvalidator
11  * @group Cache
12  */
13 class CacheTagsInvalidatorTest extends UnitTestCase {
14
15   /**
16    * @covers ::invalidateTags
17    */
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]]);
22   }
23
24   /**
25    * @covers ::invalidateTags
26    * @covers ::addInvalidator
27    */
28   public function testInvalidateTags() {
29     $cache_tags_invalidator = new CacheTagsInvalidator();
30
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')
37       ->with(['node:1']);
38
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
41     // a fatal error.
42     $non_invalidator_cache_bin = $this->getMock('\Drupal\Core\Cache\CacheBackendInterface');
43
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);
49
50     $invalidator = $this->getMock('\Drupal\Core\Cache\CacheTagsInvalidator');
51     $invalidator->expects($this->once())
52       ->method('invalidateTags')
53       ->with(['node:1']);
54
55     $cache_tags_invalidator->addInvalidator($invalidator);
56
57     $cache_tags_invalidator->invalidateTags(['node:1']);
58   }
59
60 }