mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-24 08:00:13 -06:00
Added more database cases covering different combinations of finding short URL by short code and domain
This commit is contained in:
parent
49c3c9bec1
commit
eced1af21d
@ -36,31 +36,58 @@ class ShortUrlRepositoryTest extends DatabaseTestCase
|
|||||||
/** @test */
|
/** @test */
|
||||||
public function findOneByShortCodeReturnsProperData(): void
|
public function findOneByShortCodeReturnsProperData(): void
|
||||||
{
|
{
|
||||||
$foo = new ShortUrl('foo');
|
$regularOne = new ShortUrl('foo');
|
||||||
$foo->setShortCode('foo');
|
$regularOne->setShortCode('foo');
|
||||||
$this->getEntityManager()->persist($foo);
|
$this->getEntityManager()->persist($regularOne);
|
||||||
|
|
||||||
$bar = new ShortUrl('bar', ShortUrlMeta::createFromParams(Chronos::now()->addMonth()));
|
$notYetValid = new ShortUrl('bar', ShortUrlMeta::createFromParams(Chronos::now()->addMonth()));
|
||||||
$bar->setShortCode('bar_very_long_text');
|
$notYetValid->setShortCode('bar_very_long_text');
|
||||||
$this->getEntityManager()->persist($bar);
|
$this->getEntityManager()->persist($notYetValid);
|
||||||
|
|
||||||
$baz = new ShortUrl('baz', ShortUrlMeta::createFromRawData(['maxVisits' => 3]));
|
$expired = new ShortUrl('expired', ShortUrlMeta::createFromParams(null, Chronos::now()->subMonth()));
|
||||||
|
$expired->setShortCode('expired');
|
||||||
|
$this->getEntityManager()->persist($expired);
|
||||||
|
|
||||||
|
$allVisitsComplete = new ShortUrl('baz', ShortUrlMeta::createFromRawData(['maxVisits' => 3]));
|
||||||
$visits = [];
|
$visits = [];
|
||||||
for ($i = 0; $i < 3; $i++) {
|
for ($i = 0; $i < 3; $i++) {
|
||||||
$visit = new Visit($baz, Visitor::emptyInstance());
|
$visit = new Visit($allVisitsComplete, Visitor::emptyInstance());
|
||||||
$this->getEntityManager()->persist($visit);
|
$this->getEntityManager()->persist($visit);
|
||||||
$visits[] = $visit;
|
$visits[] = $visit;
|
||||||
}
|
}
|
||||||
$baz->setShortCode('baz')
|
$allVisitsComplete->setShortCode('baz')
|
||||||
->setVisits(new ArrayCollection($visits));
|
->setVisits(new ArrayCollection($visits));
|
||||||
$this->getEntityManager()->persist($baz);
|
$this->getEntityManager()->persist($allVisitsComplete);
|
||||||
|
|
||||||
|
$withDomain = new ShortUrl('foo', ShortUrlMeta::createFromRawData(['domain' => 'example.com']));
|
||||||
|
$withDomain->setShortCode('domain-short-code');
|
||||||
|
$this->getEntityManager()->persist($withDomain);
|
||||||
|
|
||||||
|
$withDomainDuplicatingRegular = new ShortUrl('foo', ShortUrlMeta::createFromRawData([
|
||||||
|
'domain' => 'doma.in',
|
||||||
|
]));
|
||||||
|
$withDomainDuplicatingRegular->setShortCode('foo');
|
||||||
|
$this->getEntityManager()->persist($withDomainDuplicatingRegular);
|
||||||
|
|
||||||
$this->getEntityManager()->flush();
|
$this->getEntityManager()->flush();
|
||||||
|
|
||||||
$this->assertSame($foo, $this->repo->findOneByShortCode($foo->getShortCode()));
|
$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(
|
||||||
|
$withDomainDuplicatingRegular,
|
||||||
|
$this->repo->findOneByShortCode($withDomainDuplicatingRegular->getShortCode(), 'doma.in')
|
||||||
|
);
|
||||||
|
$this->assertSame(
|
||||||
|
$regularOne,
|
||||||
|
$this->repo->findOneByShortCode($withDomainDuplicatingRegular->getShortCode(), 'other-domain.com')
|
||||||
|
);
|
||||||
$this->assertNull($this->repo->findOneByShortCode('invalid'));
|
$this->assertNull($this->repo->findOneByShortCode('invalid'));
|
||||||
$this->assertNull($this->repo->findOneByShortCode($bar->getShortCode()));
|
$this->assertNull($this->repo->findOneByShortCode($withDomain->getShortCode()));
|
||||||
$this->assertNull($this->repo->findOneByShortCode($baz->getShortCode()));
|
$this->assertNull($this->repo->findOneByShortCode($withDomain->getShortCode(), 'other-domain.com'));
|
||||||
|
$this->assertNull($this->repo->findOneByShortCode($notYetValid->getShortCode()));
|
||||||
|
$this->assertNull($this->repo->findOneByShortCode($expired->getShortCode()));
|
||||||
|
$this->assertNull($this->repo->findOneByShortCode($allVisitsComplete->getShortCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
Loading…
Reference in New Issue
Block a user