public function PluginIdTest::testCacheContexts in Plugin 8.2
@covers ::getCacheContexts @covers ::getCacheableMetadata
File
- tests/
src/ Unit/ Plugin/ views/ filter/ PluginIdTest.php, line 87
Class
- PluginIdTest
- @coversDefaultClass \Drupal\plugin\Plugin\views\filter\PluginId
Namespace
Drupal\Tests\plugin\Unit\Plugin\views\filterCode
public function testCacheContexts() {
$plugin_manager_cache_contexts = [
'dog',
'ball',
];
$container = $this
->prophesize(ContainerInterface::class);
$cache_contexts_manager = new CacheContextsManager($container
->reveal(), []);
$container
->get('cache_contexts_manager')
->willReturn($cache_contexts_manager);
\Drupal::setContainer($container
->reveal());
$plugin_manager = $this
->prophesize(CacheableDependencyPluginManagerInterface::class);
$plugin_manager
->getCacheContexts()
->willReturn($plugin_manager_cache_contexts);
$plugin_manager
->getCacheTags()
->willReturn([]);
$plugin_manager
->getCacheMaxAge()
->willReturn(0);
$this->pluginType
->getPluginManager()
->willReturn($plugin_manager
->reveal());
// Temporarily disable asserts, because Cache::mergeContexts() calls
// \Drupal::service(). See https://www.drupal.org/node/2720947.
assert_options(ASSERT_ACTIVE, FALSE);
$cache_contexts = $this->sut
->getCacheContexts();
$this
->assertIsArray($cache_contexts);
foreach ($plugin_manager_cache_contexts as $plugin_manager_cache_context) {
$this
->assertTrue(in_array($plugin_manager_cache_context, $cache_contexts));
}
assert_options(ASSERT_ACTIVE, TRUE);
}