You are here

function EncryptEncryptDecryptTest::testBasicEncryptDecrypt in Encrypt 7.3

Same name and namespace in other branches
  1. 7 encrypt.test \EncryptEncryptDecryptTest::testBasicEncryptDecrypt()

Test encryption and decryption with the "Basic" method.

Pretty much the same as the "None" tests. See that method for more detailed comments.

File

./encrypt.test, line 55
Tests for encrypt.module

Class

EncryptEncryptDecryptTest
Test basic encryption and decryption.

Code

function testBasicEncryptDecrypt() {
  $random = $this
    ->randomName(10);
  $encrypted = encrypt($random, array(), 'default');

  // 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('Basic: The encrypted value is a serialized array.'));
  $encryptedArray = unserialize($encrypted);
  $this
    ->assertNotEqual($random, $encryptedArray['text'], t('Basic: A value, encrypted, does not equal itself.'));
  $this
    ->assertEqual($encryptedArray['method'], 'default', t('Basic: Encryption method stored correctly.'));
  $decrypted = decrypt($encrypted, array(), 'default');
  $this
    ->assertEqual($random, $decrypted, t('Basic: A value, decrypted, equals itself.'));
}