]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Add test on tagAllForUser 1542/head
authorJeremy Benoist <jeremy.benoist@gmail.com>
Sun, 27 Dec 2015 22:48:57 +0000 (23:48 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Mon, 28 Dec 2015 12:20:48 +0000 (13:20 +0100)
And fix multiplication of entries returned by `tagAllForUser`.

src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php
src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php

index fb2d1f87d584bb8271f740ecedec49b28116e147..41ef25b8ce85f3e5df17088ef29601dfa45e3752 100644 (file)
@@ -65,7 +65,6 @@ class RuleBasedTagger
                     $tag = $this->getTag($user, $label);
 
                     $entry->addTag($tag);
-                    $entries[] = $entry;
                 }
             }
         }
index 70951d46f64f3b50f826866f3d2708589aae0c3d..1de134b8a4bee5d0dc05101c54ae83acdda95d71 100644 (file)
@@ -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();