protected function KeyEntityTest::setUp in Key 8
Overrides KeyTestBase::setUp
File
- tests/
src/ Unit/ Entity/ KeyEntityTest.php, line 82
Class
- KeyEntityTest
- @coversDefaultClass \Drupal\key\Entity\Key @group key
Namespace
Drupal\Tests\key\Unit\EntityCode
protected function setUp() {
parent::setUp();
$definition = [
'id' => 'authentication',
'label' => 'Authentication',
];
$this->key_type_settings = [];
$plugin = new AuthenticationKeyType($this->key_type_settings, 'authentication', $definition);
// Mock the KeyTypeManager service.
$this->keyTypeManager = $this
->getMockBuilder('\\Drupal\\key\\Plugin\\KeyPluginManager')
->disableOriginalConstructor()
->getMock();
$this->keyTypeManager
->expects($this
->any())
->method('getDefinitions')
->willReturn([
[
'id' => 'authentication',
'label' => 'Authentication',
],
]);
$this->keyTypeManager
->expects($this
->any())
->method('createInstance')
->with('authentication', $this->key_type_settings)
->willReturn($plugin);
$this->container
->set('plugin.manager.key.key_type', $this->keyTypeManager);
$definition = [
'id' => 'config',
'label' => 'Configuration',
'storage_method' => 'config',
];
$this->key_provider_settings = [
'key_value' => $this
->createToken(),
'base64_encoded' => FALSE,
];
$plugin = new ConfigKeyProvider($this->key_provider_settings, 'config', $definition);
// Mock the KeyProviderManager service.
$this->keyProviderManager = $this
->getMockBuilder('\\Drupal\\key\\Plugin\\KeyPluginManager')
->disableOriginalConstructor()
->getMock();
$this->keyProviderManager
->expects($this
->any())
->method('getDefinitions')
->willReturn([
[
'id' => 'file',
'label' => 'File',
'storage_method' => 'file',
],
[
'id' => 'config',
'label' => 'Configuration',
'storage_method' => 'config',
],
]);
$this->keyProviderManager
->expects($this
->any())
->method('createInstance')
->with('config', $this->key_provider_settings)
->willReturn($plugin);
$this->container
->set('plugin.manager.key.key_provider', $this->keyProviderManager);
$definition = [
'id' => 'none',
'label' => 'None',
];
$this->key_input_settings = [];
$plugin = new NoneKeyInput($this->key_input_settings, 'none', $definition);
// Mock the KeyInputManager service.
$this->keyInputManager = $this
->getMockBuilder('\\Drupal\\key\\Plugin\\KeyPluginManager')
->disableOriginalConstructor()
->getMock();
$this->keyInputManager
->expects($this
->any())
->method('getDefinitions')
->willReturn([
[
'id' => 'none',
'label' => 'None',
],
]);
$this->keyInputManager
->expects($this
->any())
->method('createInstance')
->with('none', $this->key_input_settings)
->willReturn($plugin);
$this->container
->set('plugin.manager.key.key_input', $this->keyInputManager);
\Drupal::setContainer($this->container);
}