From 080965e166fbbd62af9dccc6fba170eab5e7485d Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 4 Aug 2018 16:21:01 +0200 Subject: [PATCH] Improved ShortUrlRepositoryTest covering listing case with filter by tag and search term at the same time --- .../Repository/ShortUrlRepositoryTest.php | 35 ++++++++++++++++++- .../Repository/TagRepositoryTest.php | 2 +- .../Repository/VisitRepositoryTest.php | 2 +- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/module/Core/test-func/Repository/ShortUrlRepositoryTest.php b/module/Core/test-func/Repository/ShortUrlRepositoryTest.php index 184ca054..1a0cf1e6 100644 --- a/module/Core/test-func/Repository/ShortUrlRepositoryTest.php +++ b/module/Core/test-func/Repository/ShortUrlRepositoryTest.php @@ -5,15 +5,17 @@ namespace ShlinkioTest\Shlink\Core\Repository; use Doctrine\Common\Collections\ArrayCollection; use Shlinkio\Shlink\Core\Entity\ShortUrl; +use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Entity\Visit; use Shlinkio\Shlink\Core\Repository\ShortUrlRepository; use ShlinkioTest\Shlink\Common\DbUnit\DatabaseTestCase; class ShortUrlRepositoryTest extends DatabaseTestCase { - const ENTITIES_TO_EMPTY = [ + protected const ENTITIES_TO_EMPTY = [ ShortUrl::class, Visit::class, + Tag::class, ]; /** @@ -79,4 +81,35 @@ class ShortUrlRepositoryTest extends DatabaseTestCase $this->assertEquals($count, $this->repo->countList()); } + + /** + * @test + */ + public function findListProperlyFiltersByTagAndSearchTerm() + { + $tag = new Tag('bar'); + $this->getEntityManager()->persist($tag); + + $foo = new ShortUrl(); + $foo->setOriginalUrl('foo') + ->setShortCode('foo') + ->setTags(new ArrayCollection([$tag])); + $this->getEntityManager()->persist($foo); + + $bar = new ShortUrl(); + $bar->setOriginalUrl('bar') + ->setShortCode('bar_very_long_text'); + $this->getEntityManager()->persist($bar); + + $foo2 = new ShortUrl(); + $foo2->setOriginalUrl('foo_2') + ->setShortCode('foo_2'); + $this->getEntityManager()->persist($foo2); + + $this->getEntityManager()->flush(); + + $result = $this->repo->findList(null, null, 'foo', ['bar']); + $this->assertCount(1, $result); + $this->assertSame($foo, $result[0]); + } } diff --git a/module/Core/test-func/Repository/TagRepositoryTest.php b/module/Core/test-func/Repository/TagRepositoryTest.php index b6a96d85..1fce379f 100644 --- a/module/Core/test-func/Repository/TagRepositoryTest.php +++ b/module/Core/test-func/Repository/TagRepositoryTest.php @@ -9,7 +9,7 @@ use ShlinkioTest\Shlink\Common\DbUnit\DatabaseTestCase; class TagRepositoryTest extends DatabaseTestCase { - const ENTITIES_TO_EMPTY = [ + protected const ENTITIES_TO_EMPTY = [ Tag::class, ]; diff --git a/module/Core/test-func/Repository/VisitRepositoryTest.php b/module/Core/test-func/Repository/VisitRepositoryTest.php index b13e4053..00c2eaf3 100644 --- a/module/Core/test-func/Repository/VisitRepositoryTest.php +++ b/module/Core/test-func/Repository/VisitRepositoryTest.php @@ -12,7 +12,7 @@ use ShlinkioTest\Shlink\Common\DbUnit\DatabaseTestCase; class VisitRepositoryTest extends DatabaseTestCase { - const ENTITIES_TO_EMPTY = [ + protected const ENTITIES_TO_EMPTY = [ VisitLocation::class, Visit::class, ShortUrl::class,