1 common.test CommonURLUnitTestCase::testBackdropGetQueryParameters()

Test backdrop_get_query_parameters().

File

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

Class

CommonURLUnitTestCase
All URL testing that does not require a Backdrop bootstrap.

Code

function testBackdropGetQueryParameters() {
  $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(backdrop_get_query_parameters(), $result, "\$_GET['q'] was removed.");

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

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

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

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