You are here

function CommonURLUnitTest::testDrupalGetQueryParameters in SimpleTest 7

Test drupal_get_query_parameters().

File

tests/common.test, line 82
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, t("\$_GET['q'] was removed."));

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

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

  // Second-level exclusion.
  $result = $original;
  unset($result['b']['d']);
  $this
    ->assertEqual(drupal_get_query_parameters($original, array(
    'b[d]',
  )), $result, t("'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, t("'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, t("'a', 'b[e]', 'c' were removed."));
}