You are here

class QueryParametersToURLUnitTestCase in Query Parameters To URL 7

Class QueryParametersToURLUnitTestCase.

Hierarchy

Expanded class hierarchy of QueryParametersToURLUnitTestCase

File

./query_parameters_to_url.test, line 302
Query Arguments To URL tests.

View source
class QueryParametersToURLUnitTestCase extends DrupalUnitTestCase {

  /**
   * Returns test info.
   */
  public static function getInfo() {
    return array(
      'name' => 'Query Parameters To URL Unit tests',
      'description' => 'Test query parameter values encoding / decoding.',
      'group' => 'Query Parameters To URL',
    );
  }

  /**
   * Setup.
   */
  public function setUp() {
    drupal_load('module', 'query_parameters_to_url');
    parent::setUp();
  }

  /**
   * Returns a list of test cases.
   */
  public function getTestCases() {
    $test_cases = array();

    // ?value[a][1][2]=3&value[a][1][6]=7&value[b]=4&value[c]=5
    $test_cases[] = array(
      'parameter_value_array' => array(
        'a' => array(
          1 => array(
            2 => 3,
            6 => 7,
          ),
        ),
        'b' => 4,
        'c' => 5,
      ),
      'encoded_parameter_value_string' => 'a__1__2__3--a__1__6__7--b__4--c__5',
    );

    // ?f[0]=standard_page&f[1]=sm_og_group_ref:node:100
    $test_cases[] = array(
      'parameter_value_array' => array(
        0 => 'standard_page',
        1 => 'sm_og_group_ref:node:100',
      ),
      'encoded_parameter_value_string' => '0__standard_page--1__sm_og_group_ref:node:100',
    );
    return $test_cases;
  }

  /**
   * Unpacks a test case.
   */
  public function unpackTestCase($test_case) {
    return array(
      $test_case['parameter_value_array'],
      $test_case['encoded_parameter_value_string'],
    );
  }

  /**
   * Tests if a query parameter's values are properly encoded.
   */
  public function testQueryParameterValuesEncoding() {
    $test_cases = $this
      ->getTestCases();
    foreach ($test_cases as $test_case) {
      list($parameter_values, $expected_query_parameter_string) = $this
        ->unpackTestCase($test_case);
      $encoded_query_parameter = query_parameters_to_url_encode_query_parameter_values($parameter_values);
      $message = 'Query parameter values are encoded properly.<br/> Initial array:<br/>!initial<br/>Encoded to string:<br/>!string';
      $message = format_string($message, array(
        '!initial' => var_export($parameter_values, TRUE),
        '!string' => var_export($encoded_query_parameter, TRUE),
      ));
      $this
        ->assertEqual($encoded_query_parameter, $expected_query_parameter_string, $message);
    }
  }

  /**
   * Tests if an encoded query parameter's values is properly decoded.
   */
  public function testQueryParameterValuesDecoding() {
    $test_cases = $this
      ->getTestCases();
    foreach ($test_cases as $test_case) {
      list($expected_parameter_values, $encoded_parameter_string) = $this
        ->unpackTestCase($test_case);
      $decoded_query_parameter_values = query_parameters_to_url_decode_query_parameter_values($encoded_parameter_string);
      $message = 'Query parameter values are decoded properly.<br/> Initial string:<br/>!initial<br/>Decoded to array:<br/>!array';
      $message = format_string($message, array(
        '!initial' => var_export($encoded_parameter_string, TRUE),
        '!array' => var_export($decoded_query_parameter_values, TRUE),
      ));
      $this
        ->assertEqual($decoded_query_parameter_values, $expected_parameter_values, $message);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalUnitTestCase::tearDown protected function 1
DrupalUnitTestCase::__construct function Constructor for DrupalUnitTestCase. Overrides DrupalTestCase::__construct
QueryParametersToURLUnitTestCase::getInfo public static function Returns test info.
QueryParametersToURLUnitTestCase::getTestCases public function Returns a list of test cases.
QueryParametersToURLUnitTestCase::setUp public function Setup. Overrides DrupalUnitTestCase::setUp
QueryParametersToURLUnitTestCase::testQueryParameterValuesDecoding public function Tests if an encoded query parameter's values is properly decoded.
QueryParametersToURLUnitTestCase::testQueryParameterValuesEncoding public function Tests if a query parameter's values are properly encoded.
QueryParametersToURLUnitTestCase::unpackTestCase public function Unpacks a test case.