Enhance RedirectConditionTest with new query-param-related conditions

This commit is contained in:
Alejandro Celaya
2025-07-17 08:37:03 +02:00
parent 18c4c39fee
commit 47293be85c
2 changed files with 30 additions and 1 deletions

View File

@@ -32,6 +32,33 @@ class RedirectConditionTest extends TestCase
self::assertEquals($expectedResult, $result);
}
#[Test]
#[TestWith(['nop', '', false])] // param not present
#[TestWith(['foo', '', true])]
#[TestWith(['foo', 'something', true])]
#[TestWith(['foo', 'something else', true])]
public function matchesAnyValueQueryParams(string $param, string $value, bool $expectedResult): void
{
$request = ServerRequestFactory::fromGlobals()->withQueryParams(['foo' => $value]);
$result = RedirectCondition::forAnyValueQueryParam($param)->matchesRequest($request);
self::assertEquals($expectedResult, $result);
}
#[Test]
#[TestWith(['nop', '', false])] // param not present
#[TestWith(['foo', '', true])]
#[TestWith(['foo', null, true])]
#[TestWith(['foo', 'something', false])]
#[TestWith(['foo', 'something else', false])]
public function matchesValuelessQueryParams(string $param, string|null $value, bool $expectedResult): void
{
$request = ServerRequestFactory::fromGlobals()->withQueryParams(['foo' => $value]);
$result = RedirectCondition::forValuelessQueryParam($param)->matchesRequest($request);
self::assertEquals($expectedResult, $result);
}
#[Test]
#[TestWith([null, '', false], 'no accept language')]
#[TestWith(['', '', false], 'empty accept language')]
@@ -141,6 +168,8 @@ class RedirectConditionTest extends TestCase
#[TestWith([RedirectConditionType::DEVICE->value, RedirectConditionType::DEVICE])]
#[TestWith([RedirectConditionType::LANGUAGE->value, RedirectConditionType::LANGUAGE])]
#[TestWith([RedirectConditionType::QUERY_PARAM->value, RedirectConditionType::QUERY_PARAM])]
#[TestWith([RedirectConditionType::ANY_VALUE_QUERY_PARAM->value, RedirectConditionType::ANY_VALUE_QUERY_PARAM])]
#[TestWith([RedirectConditionType::VALUELESS_QUERY_PARAM->value, RedirectConditionType::VALUELESS_QUERY_PARAM])]
#[TestWith([RedirectConditionType::IP_ADDRESS->value, RedirectConditionType::IP_ADDRESS])]
#[TestWith(
[RedirectConditionType::GEOLOCATION_COUNTRY_CODE->value, RedirectConditionType::GEOLOCATION_COUNTRY_CODE],