示例#1
0
 /**
  * @covers ::getCacheContexts
  * @covers ::addCacheContexts
  */
 public function testCacheContexts()
 {
     $cache_contexts_manager = $this->getMockBuilder('Drupal\\Core\\Cache\\Context\\CacheContextsManager')->disableOriginalConstructor()->getMock();
     $container = new ContainerBuilder();
     $container->set('cache_contexts_manager', $cache_contexts_manager);
     \Drupal::setContainer($container);
     // There are no cache contexts by default.
     $this->assertEquals([], $this->entity->getCacheContexts());
     // Add an additional cache context.
     $this->entity->addCacheContexts(['user']);
     $this->assertEquals(['user'], $this->entity->getCacheContexts());
 }