public function UrlTest::testDrupalGetQueryParameters in Drupal 9
Tests UrlHelper::filterQueryParameters().
File
- core/
modules/ system/ tests/ src/ Kernel/ Common/ UrlTest.php, line 184
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\Kernel\CommonCode
public function testDrupalGetQueryParameters() {
$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.");
}