function EncryptEncryptDecryptTest::testNoneEncryptDecrypt in Encrypt 7
Same name and namespace in other branches
- 7.3 encrypt.test \EncryptEncryptDecryptTest::testNoneEncryptDecrypt()
- 7.2 encrypt.test \EncryptEncryptDecryptTest::testNoneEncryptDecrypt()
Test encryption and decryption with the "None" method.
File
- ./
encrypt.test, line 31 - Tests for encrypt.module
Class
- EncryptEncryptDecryptTest
- Test basic encryption and decryption.
Code
function testNoneEncryptDecrypt() {
// First, generate a random string to encrypt.
$random = $this
->randomName(10);
// Encrypt the string.
$encrypted = encrypt($random, array(), 'none');
$this
->assertNotEqual($random, $encrypted, t('None: A value, encrypted, does not equal itself.'));
$this
->assertTrue(strpos($encrypted, 'a:') === 0, t('None: The encrypted value is a serialized array.'));
// Since no actual encryption is being performed, ensure that the "encrypted" text is the same as the original.
$encryptedArray = unserialize($encrypted);
$this
->assertEqual($random, $encryptedArray['text'], t('None: Initial value equals "encrypted" value.'));
// Then, decrypt the encrypted string.
$decrypted = decrypt($encrypted, array(), 'none');
$this
->assertEqual($random, $decrypted, t('None: A value, decrypted, equals itself.'));
}