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. 8.9.x core/modules/system/tests/src/Functional/Common/UrlTest.php \Drupal\Tests\system\Functional\Common\UrlTest::testDrupalGetQueryParameters()
  3. 10 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/Kernel/Common/UrlTest.php, line 185

Class

UrlTest
Tests the Url object.

Namespace

Drupal\Tests\system\Kernel\Common

Code

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