public function EncryptEncryptDecryptTest::testMcryptEncryptDecrypt in Encrypt 7.2
Same name and namespace in other branches
- 7.3 encrypt.test \EncryptEncryptDecryptTest::testMCryptEncryptDecrypt()
- 7 encrypt.test \EncryptEncryptDecryptTest::testMCryptEncryptDecrypt()
Test encryption and decryption with the "Mcrypt AES (CBC Mode)" method.
Pretty much the same as the "None" tests. See that method for more detailed comments.
File
- ./
encrypt.test, line 60 - Tests for the project Encrypt.
Class
- EncryptEncryptDecryptTest
- Test basic encryption and decryption.
Code
public function testMcryptEncryptDecrypt() {
if (function_exists('mcrypt_encrypt')) {
$random = $this
->randomName(10);
$encrypted = encrypt($random, array(), 'mcrypt_aes_cbc');
// Test that the original value does not equal the encrypted
// value (i.e. that the data is actually being encrypted).
$this
->assertTrue(strpos($encrypted, 'a:') === 0, t('Mcrypt AES (CBC Mode): The encrypted value is a serialized array.'));
$encryptedArray = unserialize($encrypted);
$this
->assertNotEqual($random, $encryptedArray['text'], t('Mcrypt AES (CBC Mode): A value, encrypted, does not equal itself.'));
$this
->assertEqual($encryptedArray['method'], 'mcrypt_aes_cbc', t('Mcrypt AES (CBC Mode): Encryption method stored correctly.'));
$decrypted = decrypt($encrypted);
$this
->assertEqual($random, $decrypted, t('Mcrypt AES (CBC Mode): A value, decrypted, equals itself.'));
}
else {
debug('Mcrypt extension not present. Skipping tests.');
}
}