You are here

public function EncryptConfigTest::testConfigEncrypt in Encrypt 7.2

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

Test an encryption with just a configuration.

File

./encrypt.test, line 319
Tests for the project Encrypt.

Class

EncryptConfigTest
Test configurations.

Code

public 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'], 'mcrypt_aes_cbc', 'Config: Encryption method stored correctly.');
  $decrypted = decrypt($encrypted, array(), 'default');
  $this
    ->assertEqual($random, $decrypted, 'Config: A value, decrypted, equals itself.');
}