assignTagsToEntry() public method

Assign some tags to an entry.
public assignTagsToEntry ( Entry $entry, array | string $tags, array $entitiesReady = [] )
$entry Wallabag\CoreBundle\Entity\Entry
$tags array | string An array of tag or a string coma separated of tag
$entitiesReady array Entities from the EntityManager which are persisted but not yet flushed It is mostly to fix duplicate tag on import @see http://stackoverflow.com/a/7879164/569101
Ejemplo n.º 1
0
 public function testAssignTagsNotFlushed()
 {
     $graby = $this->getMockBuilder('Graby\\Graby')->disableOriginalConstructor()->getMock();
     $tagRepo = $this->getTagRepositoryMock();
     $tagRepo->expects($this->never())->method('__call');
     $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
     $tagEntity = new Tag();
     $tagEntity->setLabel('tag1');
     $entry = new Entry(new User());
     $proxy->assignTagsToEntry($entry, 'tag1', [$tagEntity]);
     $this->assertCount(1, $entry->getTags());
     $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
 }
Ejemplo n.º 2
0
 public function testAssignTagsAlreadyAssigned()
 {
     $graby = $this->getMockBuilder('Graby\\Graby')->disableOriginalConstructor()->getMock();
     $tagRepo = $this->getTagRepositoryMock();
     $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
     $tagEntity = new Tag();
     $tagEntity->setLabel('tag1');
     $entry = new Entry(new User());
     $entry->addTag($tagEntity);
     $proxy->assignTagsToEntry($entry, 'tag1, tag2');
     $this->assertCount(2, $entry->getTags());
     $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
     $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
 }