aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle')
-rw-r--r--src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTaggingRuleData.php41
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php8
-rw-r--r--src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php1
-rw-r--r--src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php46
4 files changed, 95 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTaggingRuleData.php b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTaggingRuleData.php
new file mode 100644
index 00000000..09a08bb2
--- /dev/null
+++ b/src/Wallabag/CoreBundle/DataFixtures/ORM/LoadTaggingRuleData.php
@@ -0,0 +1,41 @@
1<?php
2
3namespace Wallabag\CoreBundle\DataFixtures\ORM;
4
5use Doctrine\Common\DataFixtures\AbstractFixture;
6use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
7use Doctrine\Common\Persistence\ObjectManager;
8use Wallabag\CoreBundle\Entity\TaggingRule;
9
10class LoadTaggingRuleData extends AbstractFixture implements OrderedFixtureInterface
11{
12 /**
13 * {@inheritdoc}
14 */
15 public function load(ObjectManager $manager)
16 {
17 $tr1 = new TaggingRule();
18 $tr1->setRule('content matches "spurs"');
19 $tr1->setTags(array('sport'));
20 $tr1->setConfig($this->getReference('admin-config'));
21
22 $manager->persist($tr1);
23
24 $tr2 = new TaggingRule();
25 $tr2->setRule('content matches "basket"');
26 $tr2->setTags(array('sport'));
27 $tr2->setConfig($this->getReference('admin-config'));
28
29 $manager->persist($tr2);
30
31 $manager->flush();
32 }
33
34 /**
35 * {@inheritdoc}
36 */
37 public function getOrder()
38 {
39 return 40;
40 }
41}
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 608ed2f0..2813c944 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -462,6 +462,14 @@ class Entry
462 return; 462 return;
463 } 463 }
464 464
465 // check if tag already exist but has not yet be persisted
466 // it seems that the previous condition with `contains()` doesn't check that case
467 foreach ($this->tags as $existingTag) {
468 if ($existingTag->getUser() !== $tag->getUser() || $existingTag->getLabel() === $tag->getLabel()) {
469 return;
470 }
471 }
472
465 $this->tags[] = $tag; 473 $this->tags[] = $tag;
466 $tag->addEntry($this); 474 $tag->addEntry($this);
467 } 475 }
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
65 $tag = $this->getTag($user, $label); 65 $tag = $this->getTag($user, $label);
66 66
67 $entry->addTag($tag); 67 $entry->addTag($tag);
68 $entries[] = $entry;
69 } 68 }
70 } 69 }
71 } 70 }
diff --git a/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php b/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php
index 37e137bf..1de134b8 100644
--- a/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Helper/RuleBasedTaggerTest.php
@@ -121,6 +121,52 @@ class RuleBasedTaggerTest extends \PHPUnit_Framework_TestCase
121 $this->assertSame($tag, $tags[0]); 121 $this->assertSame($tag, $tags[0]);
122 } 122 }
123 123
124 public function testSameTagWithDifferentfMatchingRules()
125 {
126 $taggingRule = $this->getTaggingRule('bla bla', array('hey'));
127 $otherTaggingRule = $this->getTaggingRule('rule as string', array('hey'));
128
129 $user = $this->getUser([$taggingRule, $otherTaggingRule]);
130 $entry = new Entry($user);
131
132 $this->rulerz
133 ->method('satisfies')
134 ->willReturn(true);
135
136 $this->tagger->tag($entry);
137
138 $this->assertFalse($entry->getTags()->isEmpty());
139
140 $tags = $entry->getTags();
141 $this->assertCount(1, $tags);
142 }
143
144 public function testTagAllEntriesForAUser()
145 {
146 $taggingRule = $this->getTaggingRule('bla bla', array('hey'));
147
148 $user = $this->getUser([$taggingRule]);
149
150 $this->rulerz
151 ->method('satisfies')
152 ->willReturn(true);
153
154 $this->rulerz
155 ->method('filter')
156 ->willReturn(array(new Entry($user), new Entry($user)));
157
158 $entries = $this->tagger->tagAllForUser($user);
159
160 $this->assertCount(2, $entries);
161
162 foreach ($entries as $entry) {
163 $tags = $entry->getTags();
164
165 $this->assertCount(1, $tags);
166 $this->assertEquals('hey', $tags[0]->getLabel());
167 }
168 }
169
124 private function getUser(array $taggingRules = []) 170 private function getUser(array $taggingRules = [])
125 { 171 {
126 $user = new User(); 172 $user = new User();