Commit 78bb26d7 authored by alexpott's avatar alexpott

Issue #2720813 by Xano, Wim Leers: DefaultPluginManager should expose its cacheability metadata

parent 3af27170
......@@ -3,6 +3,7 @@
namespace Drupal\Core\Plugin;
use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Cache\UseCacheBackendTrait;
use Drupal\Component\Plugin\Discovery\DiscoveryCachedTrait;
......@@ -20,7 +21,7 @@
*
* @ingroup plugin_api
*/
class DefaultPluginManager extends PluginManagerBase implements PluginManagerInterface, CachedDiscoveryInterface {
class DefaultPluginManager extends PluginManagerBase implements PluginManagerInterface, CachedDiscoveryInterface, CacheableDependencyInterface {
use DiscoveryCachedTrait;
use UseCacheBackendTrait;
......@@ -313,4 +314,25 @@ protected function providerExists($provider) {
return $this->moduleHandler->moduleExists($provider);
}
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return [];
}
/**
* {@inheritdoc}
*/
public function getCacheTags() {
return $this->cacheTags;
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
return CACHE::PERMANENT;
}
}
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\Core\Plugin;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Tests\UnitTestCase;
/**
......@@ -301,4 +302,40 @@ public function testGetDefinitionsWithoutRequiredInterface() {
$this->assertInternalType('array', $plugin_manager->getDefinitions());
}
/**
* @covers ::getCacheContexts
*/
public function testGetCacheContexts() {
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
$plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, $module_handler->reveal(), NULL);
$cache_contexts = $plugin_manager->getCacheContexts();
$this->assertInternalType('array', $cache_contexts);
array_map(function ($cache_context) {
$this->assertInternalType('string', $cache_context);
}, $cache_contexts);
}
/**
* @covers ::getCacheTags
*/
public function testGetCacheTags() {
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
$plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, $module_handler->reveal(), NULL);
$cache_tags = $plugin_manager->getCacheTags();
$this->assertInternalType('array', $cache_tags);
array_map(function ($cache_tag) {
$this->assertInternalType('string', $cache_tag);
}, $cache_tags);
}
/**
* @covers ::getCacheMaxAge
*/
public function testGetCacheMaxAge() {
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
$plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, $module_handler->reveal(), NULL);
$cache_max_age = $plugin_manager->getCacheMaxAge();
$this->assertInternalType('int', $cache_max_age);
}
}
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