You are here

function UrlTest::testDrupalGetQueryParameters in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/Common/UrlTest.php \Drupal\system\Tests\Common\UrlTest::testDrupalGetQueryParameters()

Tests UrlHelper::filterQueryParameters().

File

core/modules/system/src/Tests/Common/UrlTest.php, line 219
Contains \Drupal\system\Tests\Common\UrlTest.

Class

UrlTest
Confirm that \Drupal\Core\Url, \Drupal\Component\Utility\UrlHelper::filterQueryParameters(), \Drupal\Component\Utility\UrlHelper::buildQuery(), and \Drupal\Core\Utility\LinkGeneratorInterface::generate() work correctly with various input.

Namespace

Drupal\system\Tests\Common

Code

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

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

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

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