You are here

public function DefaultPluginManagerTest::testDefaultPluginManagerWithEmptyCache in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php \Drupal\Tests\Core\Plugin\DefaultPluginManagerTest::testDefaultPluginManagerWithEmptyCache()
  2. 10 core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php \Drupal\Tests\Core\Plugin\DefaultPluginManagerTest::testDefaultPluginManagerWithEmptyCache()

Tests the plugin manager with caching and altering.

File

core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php, line 179

Class

DefaultPluginManagerTest
Tests the DefaultPluginManager.

Namespace

Drupal\Tests\Core\Plugin

Code

public function testDefaultPluginManagerWithEmptyCache() {
  $cid = $this
    ->randomMachineName();
  $cache_backend = $this
    ->getMockBuilder('Drupal\\Core\\Cache\\MemoryBackend')
    ->disableOriginalConstructor()
    ->getMock();
  $cache_backend
    ->expects($this
    ->once())
    ->method('get')
    ->with($cid)
    ->will($this
    ->returnValue(FALSE));
  $cache_backend
    ->expects($this
    ->once())
    ->method('set')
    ->with($cid, $this->expectedDefinitions);
  $plugin_manager = new TestPluginManager($this->namespaces, $this->expectedDefinitions, NULL, NULL, '\\Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\FruitInterface');
  $plugin_manager
    ->setCacheBackend($cache_backend, $cid);
  $this
    ->assertEquals($this->expectedDefinitions, $plugin_manager
    ->getDefinitions());
  $this
    ->assertEquals($this->expectedDefinitions['banana'], $plugin_manager
    ->getDefinition('banana'));
}