From fc031e5706acf89ff21f22ca8004ddc7f9b43089 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 27 Dec 2015 22:26:49 +0100 Subject: Avoid multiple tag creation When a new tag is created but not yet persisted, it can be duplicated. It could happen when multiple rules match the content and at least 2 of them should attach same new tag. Fix #1528 --- .../CoreBundle/Tests/Helper/RuleBasedTaggerTest.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php') diff --git a/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php b/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php index 37e137bf..70951d46 100644 --- a/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php @@ -121,6 +121,26 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $this->assertSame($tag, $tags[0]); } + public function testSameTagWithDifferentfMatchingRules() + { + $taggingRule = $this->getTaggingRule('bla bla', array('hey')); + $otherTaggingRule = $this->getTaggingRule('rule as string', array('hey')); + + $user = $this->getUser([$taggingRule, $otherTaggingRule]); + $entry = new Entry($user); + + $this->rulerz + ->method('satisfies') + ->willReturn(true); + + $this->tagger->tag($entry); + + $this->assertFalse($entry->getTags()->isEmpty()); + + $tags = $entry->getTags(); + $this->assertCount(1, $tags); + } + private function getUser(array $taggingRules = []) { $user = new User(); -- cgit v1.2.3 From e9fa8c40aaf1c4fc356057bc7b248ce80c0766b0 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 27 Dec 2015 23:48:57 +0100 Subject: Add test on tagAllForUser And fix multiplication of entries returned by `tagAllForUser`. --- .../Tests/Helper/RuleBasedTaggerTest.php | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php') diff --git a/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php b/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php index 70951d46..1de134b8 100644 --- a/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php @@ -141,6 +141,32 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase $this->assertCount(1, $tags); } + public function testTagAllEntriesForAUser() + { + $taggingRule = $this->getTaggingRule('bla bla', array('hey')); + + $user = $this->getUser([$taggingRule]); + + $this->rulerz + ->method('satisfies') + ->willReturn(true); + + $this->rulerz + ->method('filter') + ->willReturn(array(new Entry($user), new Entry($user))); + + $entries = $this->tagger->tagAllForUser($user); + + $this->assertCount(2, $entries); + + foreach ($entries as $entry) { + $tags = $entry->getTags(); + + $this->assertCount(1, $tags); + $this->assertEquals('hey', $tags[0]->getLabel()); + } + } + private function getUser(array $taggingRules = []) { $user = new User(); -- cgit v1.2.3