function EncryptEncryptDecryptTest::testMCryptEncryptDecrypt in Encrypt 7
Same name and namespace in other branches
- 7.3 encrypt.test \EncryptEncryptDecryptTest::testMCryptEncryptDecrypt()
- 7.2 encrypt.test \EncryptEncryptDecryptTest::testMcryptEncryptDecrypt()
Test encryption and decryption with the "MCrypt" method.
Pretty much the same as the "None" tests. See that method for more detailed comments.
File
- ./encrypt.test, line 72 
- Tests for encrypt.module
Class
- EncryptEncryptDecryptTest
- Test basic encryption and decryption.
Code
function testMCryptEncryptDecrypt() {
  if (function_exists('mcrypt_encrypt')) {
    $random = $this
      ->randomName(10);
    $encrypted = encrypt($random, array(), 'mcrypt_rij_256');
    // 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: The encrypted value is a serialized array.'));
    $encryptedArray = unserialize($encrypted);
    $this
      ->assertNotEqual($random, $encryptedArray['text'], t('MCrypt: A value, encrypted, does not equal itself.'));
    $decrypted = decrypt($encrypted, array(), 'mcrypt_rij_256');
    $this
      ->assertEqual($random, $decrypted, t('MCrypt: A value, decrypted, equals itself.'));
  }
  else {
    debug('MCrypt extension not present. Skipping tests.');
  }
}