function EncryptPortability::testDecryptWithoutKeyProvider in Encrypt 7.3
Same name and namespace in other branches
- 7.2 encrypt.test \EncryptPortability::testDecryptWithoutKeyProvider()
Test decrypting when only an encryption method is provided (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 148 - Tests for encrypt.module
Class
- EncryptPortability
- Various tests that ensure our encrypted data is portable (i.e. encryptable/decryptable in different environments).
Code
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.'));
}