示例#1
0
 /**
  * Test get keys by storage method.
  *
  * @group key
  */
 public function testGetKeysByStorageMethod()
 {
     // Create a key provider plugin to play with.
     $defaults = ['key_value' => $this->createToken()];
     $definition = ['id' => 'config', 'class' => 'Drupal\\key\\Plugin\\KeyProvider\\ConfigKeyProvider', 'title' => 'Configuration'];
     $KeyProvider = new ConfigKeyProvider($defaults, 'config', $definition);
     // Mock the loadByProperties method in entity manager.
     $this->configStorage->expects($this->any())->method('loadByProperties')->with(['key_provider' => 'config'])->willReturn([$this->key_id => $this->key]);
     // Make the key provider plugin manager return a plugin instance.
     $this->KeyProviderManager->expects($this->any())->method('createInstance')->with('config', $defaults)->willReturn($KeyProvider);
     $this->key->set('key_provider_settings', $defaults);
     $keys = $this->keyRepository->getKeysByStorageMethod('config');
     $this->assertEquals([$this->key_id => $this->key], $keys);
 }