From 7036d91fe7332a797bf5cbccec8790bcef8437d4 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 21 May 2017 17:01:59 +0200 Subject: [PATCH] Tag: render tags case-insensitive by storing them in lowercase Fixes #2502 Signed-off-by: Kevin Decherf --- src/Wallabag/CoreBundle/Entity/Tag.php | 2 +- src/Wallabag/CoreBundle/Helper/TagsAssigner.php | 2 +- tests/Wallabag/CoreBundle/Controller/TagControllerTest.php | 6 ++++-- .../ImportBundle/Controller/WallabagV1ControllerTest.php | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php index c19023af..a6dc8c50 100644 --- a/src/Wallabag/CoreBundle/Entity/Tag.php +++ b/src/Wallabag/CoreBundle/Entity/Tag.php @@ -78,7 +78,7 @@ class Tag */ public function setLabel($label) { - $this->label = $label; + $this->label = mb_convert_case($label, MB_CASE_LOWER); return $this; } diff --git a/src/Wallabag/CoreBundle/Helper/TagsAssigner.php b/src/Wallabag/CoreBundle/Helper/TagsAssigner.php index a2fb0b9a..0bfe5c57 100644 --- a/src/Wallabag/CoreBundle/Helper/TagsAssigner.php +++ b/src/Wallabag/CoreBundle/Helper/TagsAssigner.php @@ -45,7 +45,7 @@ class TagsAssigner } foreach ($tags as $label) { - $label = trim($label); + $label = trim(mb_convert_case($label, MB_CASE_LOWER)); // avoid empty tag if (0 === strlen($label)) { diff --git a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php index be25a8b5..5a973a7e 100644 --- a/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/TagControllerTest.php @@ -9,6 +9,7 @@ use Wallabag\CoreBundle\Entity\Tag; class TagControllerTest extends WallabagCoreTestCase { public $tagName = 'opensource'; + public $caseTagName = 'OpenSource'; public function testList() { @@ -36,7 +37,7 @@ class TagControllerTest extends WallabagCoreTestCase $form = $crawler->filter('form[name=tag]')->form(); $data = [ - 'tag[label]' => $this->tagName, + 'tag[label]' => $this->caseTagName, ]; $client->submit($form, $data); @@ -45,6 +46,7 @@ class TagControllerTest extends WallabagCoreTestCase // be sure to reload the entry $entry = $this->getEntityManager()->getRepository(Entry::class)->find($entry->getId()); $this->assertCount(1, $entry->getTags()); + $this->assertContains($this->tagName, $entry->getTags()); // tag already exists and already assigned $client->submit($form, $data); @@ -80,7 +82,7 @@ class TagControllerTest extends WallabagCoreTestCase $form = $crawler->filter('form[name=tag]')->form(); $data = [ - 'tag[label]' => 'foo2, bar2', + 'tag[label]' => 'foo2, Bar2', ]; $client->submit($form, $data); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index 25625c35..4bc982e0 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -125,7 +125,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase $tags = $content->getTags(); $this->assertContains('foot', $tags, 'It includes the "foot" tag'); - $this->assertContains('Framabag', $tags, 'It includes the "Framabag" tag'); + $this->assertContains('framabag', $tags, 'It includes the "framabag" tag'); $this->assertSame(2, count($tags)); $this->assertInstanceOf(\DateTime::class, $content->getCreatedAt()); -- 2.41.0