feat: allow to url_encode array in polling url

This commit is contained in:
Benjamin Nussbaum 2025-09-02 14:33:54 +02:00
parent aa8d3d1428
commit 40ceba267a
3 changed files with 52 additions and 0 deletions

View file

@ -2,7 +2,9 @@
declare(strict_types=1);
use App\Liquid\Filters\StandardFilters;
use App\Models\Plugin;
use Keepsuit\Liquid\Environment;
/**
* Tests for the Liquid where filter functionality
@ -92,3 +94,31 @@ LIQUID
// Should not contain the low tide data
$this->assertStringNotContainsString('"type":"L"', $result);
});
it('encodes arrays for url_encode as JSON with spaces after commas and then percent-encodes', function () {
/** @var Environment $env */
$env = app('liquid.environment');
$env->filterRegistry->register(StandardFilters::class);
$template = $env->parseString('{{ categories | url_encode }}');
$output = $template->render($env->newRenderContext([
'categories' => ['common', 'obscure'],
]));
expect($output)->toBe('%5B%22common%22%2C%22obscure%22%5D');
});
it('keeps scalar url_encode behavior intact', function () {
/** @var Environment $env */
$env = app('liquid.environment');
$env->filterRegistry->register(StandardFilters::class);
$template = $env->parseString('{{ text | url_encode }}');
$output = $template->render($env->newRenderContext([
'text' => 'hello world',
]));
expect($output)->toBe('hello+world');
});