Rename loosely mode to loose mode

This commit is contained in:
Alejandro Celaya
2023-01-29 10:29:26 +01:00
parent c140db16d1
commit d847c7648e
8 changed files with 39 additions and 16 deletions

View File

@@ -22,8 +22,8 @@ final class UrlShortenerOptions
) {
}
public function isLooselyMode(): bool
public function isLooseMode(): bool
{
return $this->mode === ShortUrlMode::LOOSELY;
return $this->mode === ShortUrlMode::LOOSE;
}
}

View File

@@ -5,5 +5,11 @@ namespace Shlinkio\Shlink\Core\ShortUrl\Model;
enum ShortUrlMode: string
{
case STRICT = 'strict';
case LOOSELY = 'loosely';
case LOOSE = 'loose';
/** @deprecated */
public static function tryDeprecated(string $mode): ?self
{
return $mode === 'loosely' ? self::LOOSE : self::tryFrom($mode);
}
}

View File

@@ -24,7 +24,7 @@ class CustomSlugFilter implements FilterInterface
return $value;
}
$value = $this->options->isLooselyMode() ? strtolower($value) : $value;
$value = $this->options->isLooseMode() ? strtolower($value) : $value;
return (match ($this->options->multiSegmentSlugsEnabled) {
true => trim(str_replace(' ', '-', $value), '/'),
false => str_replace([' ', '/'], '-', $value),

View File

@@ -55,13 +55,13 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
));
self::assertSame($regularOne, $this->repo->findOneWithDomainFallback(
ShortUrlIdentifier::fromShortCodeAndDomain('foo'),
ShortUrlMode::LOOSELY,
ShortUrlMode::LOOSE,
));
self::assertSame($regularOne, $this->repo->findOneWithDomainFallback(
ShortUrlIdentifier::fromShortCodeAndDomain('fOo'),
ShortUrlMode::LOOSELY,
ShortUrlMode::LOOSE,
));
// TODO MS is doing loosely checks always, making this fail.
// TODO MS is doing loose checks always, making this fail.
if (! $this->getEntityManager()->getConnection()->getDatabasePlatform() instanceof SQLServerPlatform) {
self::assertNull($this->repo->findOneWithDomainFallback(
ShortUrlIdentifier::fromShortCodeAndDomain('foo'),

View File

@@ -139,7 +139,7 @@ class ShortUrlTest extends TestCase
}
/** @test */
public function generatesLowercaseOnlyShortCodesInLooselyMode(): void
public function generatesLowercaseOnlyShortCodesInLooseMode(): void
{
$range = range(1, 1000); // Use a "big" number to reduce false negatives
$allFor = static fn (ShortUrlMode $mode): bool => every($range, static function () use ($mode): bool {
@@ -152,7 +152,7 @@ class ShortUrlTest extends TestCase
return $shortCode === strtolower($shortCode);
});
self::assertTrue($allFor(ShortUrlMode::LOOSELY));
self::assertTrue($allFor(ShortUrlMode::LOOSE));
self::assertFalse($allFor(ShortUrlMode::STRICT));
}
}

View File

@@ -140,20 +140,20 @@ class ShortUrlCreationTest extends TestCase
{
yield ['🔥', '🔥'];
yield ['🦣 🍅', '🦣-🍅'];
yield ['🦣 🍅', '🦣-🍅', false, ShortUrlMode::LOOSELY];
yield ['🦣 🍅', '🦣-🍅', false, ShortUrlMode::LOOSE];
yield ['foobar', 'foobar'];
yield ['foo bar', 'foo-bar'];
yield ['foo bar baz', 'foo-bar-baz'];
yield ['foo bar-baz', 'foo-bar-baz'];
yield ['foo BAR-baz', 'foo-bar-baz', false, ShortUrlMode::LOOSELY];
yield ['foo BAR-baz', 'foo-bar-baz', false, ShortUrlMode::LOOSE];
yield ['foo/bar/baz', 'foo/bar/baz', true];
yield ['/foo/bar/baz', 'foo/bar/baz', true];
yield ['/foo/baR/baZ', 'foo/bar/baz', true, ShortUrlMode::LOOSELY];
yield ['/foo/baR/baZ', 'foo/bar/baz', true, ShortUrlMode::LOOSE];
yield ['foo/bar/baz', 'foo-bar-baz'];
yield ['/foo/bar/baz', '-foo-bar-baz'];
yield ['wp-admin.php', 'wp-admin.php'];
yield ['UPPER_lower', 'UPPER_lower'];
yield ['UPPER_lower', 'upper_lower', false, ShortUrlMode::LOOSELY];
yield ['UPPER_lower', 'upper_lower', false, ShortUrlMode::LOOSE];
yield ['more~url_special.chars', 'more~url_special.chars'];
yield ['구글', '구글'];
yield ['グーグル', 'グーグル'];