You are here

public function AsymmetricalEncryptionMethod::testEncryptDecrypt in Encrypt 8.3

Test public profile/method/key.

File

tests/src/Kernel/AsymmetricalEncryptionMethod.php, line 63

Class

AsymmetricalEncryptionMethod
Tests asymmetrical_encryption_method encryption method.

Namespace

Drupal\Tests\encrypt\Kernel

Code

public function testEncryptDecrypt() {

  /** @var \Drupal\encrypt\EncryptServiceInterface $profile */
  $service = $this->container
    ->get('encryption');
  $text_encrypted = $service
    ->encrypt('Test to encrypt', $this->encryptionProfile);
  $this
    ->assertEquals('###encrypted###', $text_encrypted);

  // The encryption service throw an exception when trying to decrypt through
  // a method with 'can_decrypt' FALSE.
  $this
    ->expectException(EncryptionMethodCanNotDecryptException::class);
  $service
    ->decrypt($text_encrypted, $this->encryptionProfile);
}