mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Created new repository method which will look for short URLs without doing domain fallback
This commit is contained in:
@@ -37,7 +37,7 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function findOneByShortCodeReturnsProperData(): void
|
||||
public function findOneWithDomainFallbackReturnsProperData(): void
|
||||
{
|
||||
$regularOne = new ShortUrl('foo', ShortUrlMeta::fromRawData(['customSlug' => 'foo']));
|
||||
$this->getEntityManager()->persist($regularOne);
|
||||
@@ -54,20 +54,25 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$this->assertSame($regularOne, $this->repo->findOneByShortCode($regularOne->getShortCode()));
|
||||
$this->assertSame($regularOne, $this->repo->findOneByShortCode($withDomainDuplicatingRegular->getShortCode()));
|
||||
$this->assertSame($withDomain, $this->repo->findOneByShortCode($withDomain->getShortCode(), 'example.com'));
|
||||
$this->assertSame($regularOne, $this->repo->findOneWithDomainFallback($regularOne->getShortCode()));
|
||||
$this->assertSame($regularOne, $this->repo->findOneWithDomainFallback(
|
||||
$withDomainDuplicatingRegular->getShortCode(),
|
||||
));
|
||||
$this->assertSame($withDomain, $this->repo->findOneWithDomainFallback(
|
||||
$withDomain->getShortCode(),
|
||||
'example.com',
|
||||
));
|
||||
$this->assertSame(
|
||||
$withDomainDuplicatingRegular,
|
||||
$this->repo->findOneByShortCode($withDomainDuplicatingRegular->getShortCode(), 'doma.in'),
|
||||
$this->repo->findOneWithDomainFallback($withDomainDuplicatingRegular->getShortCode(), 'doma.in'),
|
||||
);
|
||||
$this->assertSame(
|
||||
$regularOne,
|
||||
$this->repo->findOneByShortCode($withDomainDuplicatingRegular->getShortCode(), 'other-domain.com'),
|
||||
$this->repo->findOneWithDomainFallback($withDomainDuplicatingRegular->getShortCode(), 'other-domain.com'),
|
||||
);
|
||||
$this->assertNull($this->repo->findOneByShortCode('invalid'));
|
||||
$this->assertNull($this->repo->findOneByShortCode($withDomain->getShortCode()));
|
||||
$this->assertNull($this->repo->findOneByShortCode($withDomain->getShortCode(), 'other-domain.com'));
|
||||
$this->assertNull($this->repo->findOneWithDomainFallback('invalid'));
|
||||
$this->assertNull($this->repo->findOneWithDomainFallback($withDomain->getShortCode()));
|
||||
$this->assertNull($this->repo->findOneWithDomainFallback($withDomain->getShortCode(), 'other-domain.com'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
@@ -183,4 +188,26 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
||||
$this->assertFalse($this->repo->shortCodeIsInUse('another-slug', 'example.com'));
|
||||
$this->assertTrue($this->repo->shortCodeIsInUse('another-slug', 'doma.in'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function findOneLooksForShortUrlInProperSetOfTables(): void
|
||||
{
|
||||
$shortUrlWithoutDomain = new ShortUrl('foo', ShortUrlMeta::fromRawData(['customSlug' => 'my-cool-slug']));
|
||||
$this->getEntityManager()->persist($shortUrlWithoutDomain);
|
||||
|
||||
$shortUrlWithDomain = new ShortUrl(
|
||||
'foo',
|
||||
ShortUrlMeta::fromRawData(['domain' => 'doma.in', 'customSlug' => 'another-slug']),
|
||||
);
|
||||
$this->getEntityManager()->persist($shortUrlWithDomain);
|
||||
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
$this->assertNotNull($this->repo->findOne('my-cool-slug'));
|
||||
$this->assertNull($this->repo->findOne('my-cool-slug', 'doma.in'));
|
||||
$this->assertNull($this->repo->findOne('slug-not-in-use'));
|
||||
$this->assertNull($this->repo->findOne('another-slug'));
|
||||
$this->assertNull($this->repo->findOne('another-slug', 'example.com'));
|
||||
$this->assertNotNull($this->repo->findOne('another-slug', 'doma.in'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user