Convert tag label to lowercase in RuleBasedTagger

Fixes #4266

Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
This commit is contained in:
Kevin Decherf 2021-03-06 13:34:36 +01:00
parent af5e79c425
commit 7acd207054
2 changed files with 32 additions and 0 deletions

View file

@ -94,6 +94,7 @@ class RuleBasedTagger
*/
private function getTag($label)
{
$label = mb_convert_case($label, \MB_CASE_LOWER);
$tag = $this->tagRepository->findOneByLabel($label);
if (!$tag) {

View file

@ -139,6 +139,37 @@ class RuleBasedTaggerTest extends TestCase
$this->assertCount(1, $records);
}
public function testWithMixedCaseTag()
{
$taggingRule = $this->getTaggingRule('rule as string', ['Foo']);
$user = $this->getUser([$taggingRule]);
$entry = new Entry($user);
$tag = new Tag();
$this->rulerz
->expects($this->once())
->method('satisfies')
->with($entry, 'rule as string')
->willReturn(true);
$this->tagRepository
->expects($this->once())
// the method `findOneByLabel` doesn't exist, EntityRepository will then call `_call` method
// to magically call the `findOneBy` with ['label' => 'foo']
->method('__call')
->with('findOneByLabel', ['foo'])
->willReturn($tag);
$this->tagger->tag($entry);
$this->assertFalse($entry->getTags()->isEmpty());
$tags = $entry->getTags();
$this->assertSame($tag, $tags[0]);
$records = $this->handler->getRecords();
$this->assertCount(1, $records);
}
public function testSameTagWithDifferentfMatchingRules()
{
$taggingRule = $this->getTaggingRule('bla bla', ['hey']);