Merge pull request #5111 from wallabag/fix/4266-autotagging-uppercase

Convert tag label to lowercase in RuleBasedTagger
This commit is contained in:
Jérémy Benoist 2021-03-08 09:27:51 +01:00 committed by GitHub
commit dd6a5ab047
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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']);