/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $definition = ['id' => 'config', 'title' => 'Configuration', 'storage_method' => 'config']; $this->key_settings = ['key_value' => $this->createToken()]; $plugin = new ConfigKeyProvider($this->key_settings, 'config', $definition); // Mock the KeyProviderPluginManager service. $this->KeyProviderManager = $this->getMockBuilder('\\Drupal\\key\\KeyProviderPluginManager')->disableOriginalConstructor()->getMock(); $this->KeyProviderManager->expects($this->any())->method('getDefinitions')->willReturn([['id' => 'file', 'title' => 'File', 'storage_method' => 'file'], ['id' => 'config', 'title' => 'Configuration', 'storage_method' => 'config']]); $this->KeyProviderManager->expects($this->any())->method('createInstance')->with('config', $this->key_settings)->willReturn($plugin); $this->container->set('plugin.manager.key.key_provider', $this->KeyProviderManager); \Drupal::setContainer($this->container); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->key_id = $this->getRandomGenerator()->word(15); $defaults = ['key_id' => $this->key_id, 'key_provider' => 'config']; $this->key = new Key($defaults, 'key'); // Mock the get method on the Config object. $this->config->expects($this->any())->method('get')->with('default_key')->will($this->onConsecutiveCalls(FALSE, $this->key_id)); // Mock load method to return when key is not defined and when it is // defined. $this->configStorage->expects($this->any())->method('load')->with($this->key_id)->willReturn($this->key); // Mock the KeyProviderPluginManager service. $this->KeyProviderManager = $this->getMockBuilder('\\Drupal\\key\\KeyProviderPluginManager')->disableOriginalConstructor()->getMock(); $this->KeyProviderManager->expects($this->any())->method('getDefinitions')->willReturn([['id' => 'file', 'title' => 'File', 'storage_method' => 'file'], ['id' => 'config', 'title' => 'Configuration', 'storage_method' => 'config']]); $this->container->set('plugin.manager.key.key_provider', $this->KeyProviderManager); \Drupal::setContainer($this->container); // Create a new key manager object. $this->keyManager = new KeyManager($this->entityManager, $this->configFactory, $this->KeyProviderManager); }