function UrlTest::testDrupalGetQueryParameters

Same name in other branches
  1. 9 core/modules/system/tests/src/Kernel/Common/UrlTest.php \Drupal\Tests\system\Kernel\Common\UrlTest::testDrupalGetQueryParameters()
  2. 10 core/modules/system/tests/src/Kernel/Common/UrlTest.php \Drupal\Tests\system\Kernel\Common\UrlTest::testDrupalGetQueryParameters()
  3. 11.x core/modules/system/tests/src/Kernel/Common/UrlTest.php \Drupal\Tests\system\Kernel\Common\UrlTest::testDrupalGetQueryParameters()

Tests UrlHelper::filterQueryParameters().

File

core/modules/system/tests/src/Functional/Common/UrlTest.php, line 222

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\Tests\system\Functional\Common

Code

public function testDrupalGetQueryParameters() {
    $original = [
        'a' => 1,
        'b' => [
            'd' => 4,
            'e' => [
                'f' => 5,
            ],
        ],
        'c' => 3,
    ];
    // First-level exclusion.
    $result = $original;
    unset($result['b']);
    $this->assertEqual(UrlHelper::filterQueryParameters($original, [
        'b',
    ]), $result, "'b' was removed.");
    // Second-level exclusion.
    $result = $original;
    unset($result['b']['d']);
    $this->assertEqual(UrlHelper::filterQueryParameters($original, [
        'b[d]',
    ]), $result, "'b[d]' was removed.");
    // Third-level exclusion.
    $result = $original;
    unset($result['b']['e']['f']);
    $this->assertEqual(UrlHelper::filterQueryParameters($original, [
        '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, [
        'a',
        'b[e]',
        'c',
    ]), $result, "'a', 'b[e]', 'c' were removed.");
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.