Commit c9cc8357 authored by alexpott's avatar alexpott

Issue #2420025 by Berdir: Token::resetInfo() uses invalid cache tag structure

parent ea8d1aa5
......@@ -988,7 +988,7 @@ services:
- { name: service_collector, tag: breadcrumb_builder, call: addBuilder }
token:
class: Drupal\Core\Utility\Token
arguments: ['@module_handler', '@cache.discovery', '@language_manager']
arguments: ['@module_handler', '@cache.discovery', '@language_manager', '@cache_tags.invalidator']
batch.storage:
class: Drupal\Core\Batch\BatchStorage
arguments: ['@database', '@session_manager', '@csrf_token']
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
......@@ -96,6 +97,13 @@ class Token {
*/
protected $moduleHandler;
/**
* The cache tags invalidator.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
*/
protected $cacheTagsInvalidator;
/**
* Constructs a new class instance.
*
......@@ -105,11 +113,14 @@ class Token {
* The token cache.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
* The cache tags invalidator.
*/
public function __construct(ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManagerInterface $language_manager) {
public function __construct(ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, CacheTagsInvalidatorInterface $cache_tags_invalidator) {
$this->cache = $cache;
$this->languageManager = $language_manager;
$this->moduleHandler = $module_handler;
$this->cacheTagsInvalidator = $cache_tags_invalidator;
}
/**
......@@ -347,8 +358,6 @@ public function setInfo(array $tokens) {
*/
public function resetInfo() {
$this->tokenInfo = NULL;
Cache::invalidateTags(array(
static::TOKEN_INFO_CACHE_TAG => TRUE,
));
$this->cacheTagsInvalidator->invalidateTags([static::TOKEN_INFO_CACHE_TAG]);
}
}
......@@ -52,6 +52,13 @@ class TokenTest extends UnitTestCase {
*/
protected $token;
/**
* The cache tags invalidator.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $cacheTagsInvalidator;
/**
* {@inheritdoc}
*/
......@@ -64,7 +71,9 @@ protected function setUp() {
$this->language = $this->getMock('\Drupal\Core\Language\LanguageInterface');
$this->token = new Token($this->moduleHandler, $this->cache, $this->languageManager);
$this->cacheTagsInvalidator = $this->getMock('\Drupal\Core\Cache\CacheTagsInvalidatorInterface');
$this->token = new Token($this->moduleHandler, $this->cache, $this->languageManager, $this->cacheTagsInvalidator);
}
/**
......@@ -113,4 +122,15 @@ public function testGetInfo() {
$this->token->getInfo();
}
/**
* @covers ::resetInfo
*/
public function testResetInfo() {
$this->cacheTagsInvalidator->expects($this->once())
->method('invalidateTags')
->with(['token_info']);
$this->token->resetInfo();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment