You are here

public function EncryptPortability::testDecryptWithoutKeyProvider in Encrypt 7.2

Same name and namespace in other branches
  1. 7.3 encrypt.test \EncryptPortability::testDecryptWithoutKeyProvider()

Test decrypting when only an encryption method is provided.

I.e., there is no key provider. We are likely to encounter this when sites upgrade from 1.x to 2.x, since key providers did not exist in 1.x.

File

./encrypt.test, line 146
Tests for the project Encrypt.

Class

EncryptPortability
Various tests that ensure our encrypted data is portable.

Code

public function testDecryptWithoutKeyProvider() {

  // Generate some text and encrypt it.
  $text = $this
    ->randomName(10);
  $encrypted = encrypt($text);

  // Now, we'll manually remove the key provider array key and reserialize.
  $encrypted_array = unserialize($encrypted);
  $this
    ->assertTrue(isset($encrypted_array['key_provider']), t('The key provider key exists in the encrypted array.'));
  unset($encrypted_array['key_provider']);
  $this
    ->assertEqual(count($encrypted_array), 5, t('The key provider was successfully unset.'));
  $encrypted = serialize($encrypted_array);

  // Now, we'll attempt to decrypt.
  $decrypted = decrypt($encrypted);
  $this
    ->assertEqual($decrypted, $text, t('The value was successfully decrypted.'));
}