Add test on tagAllForUser

And fix multiplication of entries returned by `tagAllForUser`.
This commit is contained in:
Jeremy Benoist 2015-12-27 23:48:57 +01:00
parent fc031e5706
commit e9fa8c40aa
2 changed files with 26 additions and 1 deletions

View File

@ -65,7 +65,6 @@ class RuleBasedTagger
$tag = $this->getTag($user, $label);
$entry->addTag($tag);
$entries[] = $entry;
}
}
}

View 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();