Skip to content
Snippets Groups Projects
Commit b9176b2f authored by Patrick Kenny's avatar Patrick Kenny Committed by Rick Hawkins
Browse files

Issue #3448070 by ptmkenny, jcnventura, rlhawk: Add support for Drupal 11

parent f71937ad
Branches
Tags
1 merge request!7support Drupal 11
Pipeline #289252 passed with warnings
name: Encrypt
description: 'Provides an API for two-way encryption.'
core_version_requirement: ^8 || ^9 || ^10
core_version_requirement: ^8 || ^9 || ^10 || ^11
package: Encryption
dependencies:
- key:key
......
name: 'Encrypt Test module'
type: module
description: 'Test module for Encrypt'
core_version_requirement: ^8 || ^9 || ^10
package: Testing
dependencies:
- encrypt:encrypt
......@@ -84,10 +84,20 @@ class EncryptionProfileTest extends UnitTestCase {
$this->keyRepository = $this->createMock('\Drupal\key\KeyRepository');
// Mock a plugin collection.
$this->pluginCollection = $this->getMockBuilder('\Drupal\Core\Plugin\DefaultLazyPluginCollection')
->disableOriginalConstructor()
->setMethods(['get', 'set', 'addInstanceID'])
->getMock();
$mock_builder_plugin_collection = $this->getMockBuilder('\Drupal\Core\Plugin\DefaultLazyPluginCollection');
// @todo Remove this conditional once support for Drupal <11 is dropped.
if (method_exists($mock_builder_plugin_collection, 'onlyMethods')) {
$this->pluginCollection = $mock_builder_plugin_collection
->disableOriginalConstructor()
->onlyMethods(['get', 'set', 'addInstanceID'])
->getMock();
}
else {
$this->pluginCollection = $mock_builder_plugin_collection
->disableOriginalConstructor()
->setMethods(['get', 'set', 'addInstanceID'])
->getMock();
}
}
/**
......@@ -100,16 +110,34 @@ class EncryptionProfileTest extends UnitTestCase {
*/
public function testValidate($enc_method_id, $enc_key, $enc_method_def, $expected_errors) {
// Set up a mock for the EncryptionProfile class to mock some methods.
$encryption_profile = $this->getMockBuilder('\Drupal\encrypt\Entity\EncryptionProfile')
->setMethods([
'getEncryptionMethod',
'getEncryptionMethodId',
'getEncryptionKey',
'getEncryptionKeyId',
]
)
->disableOriginalConstructor()
->getMock();
$mock_builder_encryption_profile = $this->getMockBuilder('\Drupal\encrypt\Entity\EncryptionProfile');
// @todo Remove this conditional once support for Drupal <11 is dropped.
if (method_exists($mock_builder_encryption_profile, 'onlyMethods')) {
$encryption_profile = $mock_builder_encryption_profile
->onlyMethods(
[
'getEncryptionMethod',
'getEncryptionMethodId',
'getEncryptionKey',
'getEncryptionKeyId',
]
)
->disableOriginalConstructor()
->getMock();
}
else {
$encryption_profile = $mock_builder_encryption_profile
->setMethods(
[
'getEncryptionMethod',
'getEncryptionMethodId',
'getEncryptionKey',
'getEncryptionKeyId',
]
)
->disableOriginalConstructor()
->getMock();
}
// Set expectations for the EncryptionMethod.
$this->encryptionMethod->expects($this->any())
......@@ -202,14 +230,30 @@ class EncryptionProfileTest extends UnitTestCase {
*/
public function testGetEncryptionMethod() {
// Set up a mock for the EncryptionProfile class to mock some methods.
$encryption_profile = $this->getMockBuilder('\Drupal\encrypt\Entity\EncryptionProfile')
->setMethods([
'getPluginCollection',
'getEncryptionMethodId',
]
)
->disableOriginalConstructor()
->getMock();
$mock_builder_encryption_profile = $this->getMockBuilder('\Drupal\encrypt\Entity\EncryptionProfile');
// @todo Remove this conditional once support for Drupal <11 is dropped.
if (method_exists($mock_builder_encryption_profile, 'onlyMethods')) {
$encryption_profile = $mock_builder_encryption_profile
->onlyMethods(
[
'getPluginCollection',
'getEncryptionMethodId',
]
)
->disableOriginalConstructor()
->getMock();
}
else {
$encryption_profile = $mock_builder_encryption_profile
->setMethods(
[
'getPluginCollection',
'getEncryptionMethodId',
]
)
->disableOriginalConstructor()
->getMock();
}
// Set up expectations for plugin collection.
$this->pluginCollection->expects($this->atLeastOnce())
......@@ -236,10 +280,20 @@ class EncryptionProfileTest extends UnitTestCase {
*/
public function testSetEncryptionMethod() {
// Set up a mock for the EncryptionProfile class to mock some methods.
$encryption_profile = $this->getMockBuilder('\Drupal\encrypt\Entity\EncryptionProfile')
->setMethods(['getPluginCollection'])
->disableOriginalConstructor()
->getMock();
// @todo Remove this conditional once support for Drupal <11 is dropped.
$mock_builder_encryption_profile = $this->getMockBuilder('\Drupal\encrypt\Entity\EncryptionProfile');
if (method_exists($mock_builder_encryption_profile, 'onlyMethods')) {
$encryption_profile = $mock_builder_encryption_profile
->onlyMethods(['getPluginCollection'])
->disableOriginalConstructor()
->getMock();
}
else {
$encryption_profile = $mock_builder_encryption_profile
->setMethods(['getPluginCollection'])
->disableOriginalConstructor()
->getMock();
}
$this->pluginCollection->expects($this->once())
->method('addInstanceID');
......@@ -264,14 +318,30 @@ class EncryptionProfileTest extends UnitTestCase {
*/
public function testGetEncryptionKey() {
// Set up a mock for the EncryptionProfile class to mock some methods.
$encryption_profile = $this->getMockBuilder('\Drupal\encrypt\Entity\EncryptionProfile')
->setMethods([
'getKeyRepository',
'getEncryptionKeyId',
]
)
->disableOriginalConstructor()
->getMock();
$mock_builder_encryption_profile = $this->getMockBuilder('\Drupal\encrypt\Entity\EncryptionProfile');
// @todo Remove this conditional once support for Drupal <11 is dropped.
if (method_exists($mock_builder_encryption_profile, 'onlyMethods')) {
$encryption_profile = $mock_builder_encryption_profile
->onlyMethods(
[
'getKeyRepository',
'getEncryptionKeyId',
]
)
->disableOriginalConstructor()
->getMock();
}
else {
$encryption_profile = $this->getMockBuilder('\Drupal\encrypt\Entity\EncryptionProfile')
->setMethods(
[
'getKeyRepository',
'getEncryptionKeyId',
]
)
->disableOriginalConstructor()
->getMock();
}
$this->keyRepository->expects($this->any())
->method('getKey')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment