You are here

function EncryptConfigTest::testConfigEncrypt in Encrypt 7.3

Same name and namespace in other branches
  1. 7.2 encrypt.test \EncryptConfigTest::testConfigEncrypt()

Test an encryption with just a configuration.

File

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

Class

EncryptConfigTest
Test configurations.

Code

function testConfigEncrypt() {
  $config = encrypt_get_default_config(TRUE);
  $random = $this
    ->randomName(10);
  $encrypted = encrypt($random, array(), NULL, NULL, $config['name']);

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