Remove name and uniqueness in redirect condition table

This commit is contained in:
Alejandro Celaya
2024-02-29 09:05:30 +01:00
parent 23c07c4e82
commit 070d74830b
9 changed files with 36 additions and 104 deletions

View File

@@ -13,13 +13,11 @@ use function sprintf;
class ListRedirectRulesTest extends ApiTestCase
{
private const LANGUAGE_EN_CONDITION = [
'name' => 'language-en',
'type' => 'language',
'matchKey' => null,
'matchValue' => 'en',
];
private const QUERY_FOO_BAR_CONDITION = [
'name' => 'query-foo-bar',
'type' => 'query',
'matchKey' => 'foo',
'matchValue' => 'bar',
@@ -54,13 +52,12 @@ class ListRedirectRulesTest extends ApiTestCase
'longUrl' => 'https://example.com/multiple-query-params',
'priority' => 2,
'conditions' => [
self::QUERY_FOO_BAR_CONDITION,
[
'name' => 'query-hello-world',
'type' => 'query',
'matchKey' => 'hello',
'matchValue' => 'world',
],
self::QUERY_FOO_BAR_CONDITION,
],
],
[
@@ -73,7 +70,6 @@ class ListRedirectRulesTest extends ApiTestCase
'priority' => 4,
'conditions' => [
[
'name' => 'device-android',
'type' => 'device',
'matchKey' => null,
'matchValue' => 'android',
@@ -85,7 +81,6 @@ class ListRedirectRulesTest extends ApiTestCase
'priority' => 5,
'conditions' => [
[
'name' => 'device-ios',
'type' => 'device',
'matchKey' => null,
'matchValue' => 'ios',

View File

@@ -25,27 +25,14 @@ class ShortUrlRedirectRulesFixture extends AbstractFixture implements DependentF
/** @var ShortUrl $defShortUrl */
$defShortUrl = $this->getReference('def456_short_url');
$englishCondition = RedirectCondition::forLanguage('en');
$manager->persist($englishCondition);
$fooQueryCondition = RedirectCondition::forQueryParam('foo', 'bar');
$manager->persist($fooQueryCondition);
$helloQueryCondition = RedirectCondition::forQueryParam('hello', 'world');
$manager->persist($helloQueryCondition);
$androidCondition = RedirectCondition::forDevice(DeviceType::ANDROID);
$manager->persist($androidCondition);
$iosCondition = RedirectCondition::forDevice(DeviceType::IOS);
$manager->persist($iosCondition);
// Create rules disordered to make sure the order by priority works
$multipleQueryParamsRule = new ShortUrlRedirectRule(
shortUrl: $defShortUrl,
priority: 2,
longUrl: 'https://example.com/multiple-query-params',
conditions: new ArrayCollection([$helloQueryCondition, $fooQueryCondition]),
conditions: new ArrayCollection(
[RedirectCondition::forQueryParam('hello', 'world'), RedirectCondition::forQueryParam('foo', 'bar')],
),
);
$manager->persist($multipleQueryParamsRule);
@@ -53,7 +40,9 @@ class ShortUrlRedirectRulesFixture extends AbstractFixture implements DependentF
shortUrl: $defShortUrl,
priority: 1,
longUrl: 'https://example.com/english-and-foo-query',
conditions: new ArrayCollection([$englishCondition, $fooQueryCondition]),
conditions: new ArrayCollection(
[RedirectCondition::forLanguage('en'), RedirectCondition::forQueryParam('foo', 'bar')],
),
);
$manager->persist($englishAndFooQueryRule);
@@ -61,7 +50,7 @@ class ShortUrlRedirectRulesFixture extends AbstractFixture implements DependentF
shortUrl: $defShortUrl,
priority: 4,
longUrl: 'https://blog.alejandrocelaya.com/android',
conditions: new ArrayCollection([$androidCondition]),
conditions: new ArrayCollection([RedirectCondition::forDevice(DeviceType::ANDROID)]),
);
$manager->persist($androidRule);
@@ -69,7 +58,7 @@ class ShortUrlRedirectRulesFixture extends AbstractFixture implements DependentF
shortUrl: $defShortUrl,
priority: 3,
longUrl: 'https://example.com/only-english',
conditions: new ArrayCollection([$englishCondition]),
conditions: new ArrayCollection([RedirectCondition::forLanguage('en')]),
);
$manager->persist($onlyEnglishRule);
@@ -77,7 +66,7 @@ class ShortUrlRedirectRulesFixture extends AbstractFixture implements DependentF
shortUrl: $defShortUrl,
priority: 5,
longUrl: 'https://blog.alejandrocelaya.com/ios',
conditions: new ArrayCollection([$iosCondition]),
conditions: new ArrayCollection([RedirectCondition::forDevice(DeviceType::IOS)]),
);
$manager->persist($iosRule);