From: Jeremy Benoist Date: Sun, 27 Dec 2015 22:48:57 +0000 (+0100) Subject: Add test on tagAllForUser X-Git-Tag: 2.0.0-alpha.1~7^2 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=e9fa8c40aaf1c4fc356057bc7b248ce80c0766b0;p=github%2Fwallabag%2Fwallabag.git Add test on tagAllForUser And fix multiplication of entries returned by `tagAllForUser`. --- diff --git a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php index fb2d1f87..41ef25b8 100644 --- a/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php +++ b/src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php @@ -65,7 +65,6 @@ class RuleBasedTagger $tag = $this->getTag($user, $label); $entry->addTag($tag); - $entries[] = $entry; } } } 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();