You are here

function CommonURLUnitTest::testDrupalGetQueryParameters in Drupal 7

Test drupal_get_query_parameters().

File

modules/simpletest/tests/common.test, line 121
Tests for common.inc functionality.

Class

CommonURLUnitTest
Tests for URL generation functions.

Code

function testDrupalGetQueryParameters() {
  $original = array(
    'a' => 1,
    'b' => array(
      'd' => 4,
      'e' => array(
        'f' => 5,
      ),
    ),
    'c' => 3,
    'q' => 'foo/bar',
  );

  // Default arguments.
  $result = $_GET;
  unset($result['q']);
  $this
    ->assertEqual(drupal_get_query_parameters(), $result, "\$_GET['q'] was removed.");

  // Default exclusion.
  $result = $original;
  unset($result['q']);
  $this
    ->assertEqual(drupal_get_query_parameters($original), $result, "'q' was removed.");

  // First-level exclusion.
  $result = $original;
  unset($result['b']);
  $this
    ->assertEqual(drupal_get_query_parameters($original, array(
    'b',
  )), $result, "'b' was removed.");

  // Second-level exclusion.
  $result = $original;
  unset($result['b']['d']);
  $this
    ->assertEqual(drupal_get_query_parameters($original, array(
    'b[d]',
  )), $result, "'b[d]' was removed.");

  // Third-level exclusion.
  $result = $original;
  unset($result['b']['e']['f']);
  $this
    ->assertEqual(drupal_get_query_parameters($original, array(
    'b[e][f]',
  )), $result, "'b[e][f]' was removed.");

  // Multiple exclusions.
  $result = $original;
  unset($result['a'], $result['b']['e'], $result['c']);
  $this
    ->assertEqual(drupal_get_query_parameters($original, array(
    'a',
    'b[e]',
    'c',
  )), $result, "'a', 'b[e]', 'c' were removed.");
}