You are here

encrypt.test in Encrypt 6

Same filename and directory in other branches
  1. 7.3 encrypt.test
  2. 7 encrypt.test
  3. 7.2 encrypt.test

Tests for Encrypt.

File

encrypt.test
View source
<?php

/**
 * @file
 * Tests for Encrypt.
 */

/**
 * Test Class for Encrypt
 */
class EncryptTest extends DrupalWebTestCase {

  /**
   * Get Info
   */
  public static function getInfo() {
    return array(
      'name' => 'Encryption Method Checking',
      'description' => 'Ensure that the Encrypt functionality is working correctly.',
      'group' => 'Encrypt',
    );
  }

  /**
   * Set Up
   */
  public function setUp() {

    // Enable any modules required for the test
    parent::setUp('encrypt');
  }

  /**
   * Test to check encryption methods
   */
  public function testCheckEncryptionMethodsKeys() {
    $test_strings = array(
      'Test String',
      '1234',
      '123',
      '111          00004  34 ls dlkj s     lsjf  sd <>?:"{})#(*#@&$@#^$!@@',
    );
    $options = array();

    // Get methods
    encrypt_initialize();
    $methods = encrypt_get_methods('full');

    // Get key names
    $key_names = array(
      NULL,
      ENCRYPT_DEFAULT_KEY,
      ENCRYPT_DEFAULT_KEY_FILE,
      ENCRYPT_DEFAULT_KEY_DB,
    );

    // Go through strings, methods, and keys
    foreach ($test_strings as $test_string) {
      foreach ($key_names as $key_name) {
        foreach ($methods as $method_name => $method) {

          // Test that original string is the same as encrypting
          // then decrypting
          $processed = decrypt(encrypt($test_string, $options, $method_name, $key_name));
          $this
            ->assertEqual($test_string, $processed, t('Ensure encryption works for method: %method and key_name: %key', array(
            '%method' => $method['title'],
            '%key' => $key_name,
          )));
        }
      }
    }
  }

}

Classes

Namesort descending Description
EncryptTest Test Class for Encrypt