mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-27 08:18:24 +03:00
Test new methods for RedirectCondition and ShortUrlRedirectRule
This commit is contained in:
parent
d8ede3263f
commit
3bfb29a51c
1 changed files with 35 additions and 0 deletions
|
@ -6,9 +6,11 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||
use Laminas\Diactoros\ServerRequestFactory;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\TestWith;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Shlinkio\Shlink\Core\RedirectRule\Entity\RedirectCondition;
|
||||
use Shlinkio\Shlink\Core\RedirectRule\Entity\ShortUrlRedirectRule;
|
||||
use Shlinkio\Shlink\Core\RedirectRule\Model\RedirectConditionType;
|
||||
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
|
||||
|
||||
class ShortUrlRedirectRuleTest extends TestCase
|
||||
|
@ -51,6 +53,39 @@ class ShortUrlRedirectRuleTest extends TestCase
|
|||
self::assertEmpty($conditions);
|
||||
}
|
||||
|
||||
#[Test, DataProvider('provideConditionMappingCallbacks')]
|
||||
public function conditionsCanBeMapped(callable $callback, array $expectedResult): void
|
||||
{
|
||||
$conditions = new ArrayCollection(
|
||||
[RedirectCondition::forLanguage('en-UK'), RedirectCondition::forQueryParam('foo', 'bar')],
|
||||
);
|
||||
$rule = $this->createRule($conditions);
|
||||
|
||||
$result = $rule->mapConditions($callback);
|
||||
|
||||
self::assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public static function provideConditionMappingCallbacks(): iterable
|
||||
{
|
||||
yield 'json-serialized conditions' => [fn (RedirectCondition $cond) => $cond->jsonSerialize(), [
|
||||
[
|
||||
'type' => RedirectConditionType::LANGUAGE->value,
|
||||
'matchKey' => null,
|
||||
'matchValue' => 'en-UK',
|
||||
],
|
||||
[
|
||||
'type' => RedirectConditionType::QUERY_PARAM->value,
|
||||
'matchKey' => 'foo',
|
||||
'matchValue' => 'bar',
|
||||
],
|
||||
]];
|
||||
yield 'human-friendly conditions' => [fn (RedirectCondition $cond) => $cond->toHumanFriendly(), [
|
||||
'en-UK language is accepted',
|
||||
'query string contains foo=bar',
|
||||
]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ArrayCollection<RedirectCondition> $conditions
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue