+ public function testAssignTagsWithArrayAndExtraSpaces()
+ {
+ $graby = $this->getMockBuilder('Graby\Graby')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $tagRepo = $this->getTagRepositoryMock();
+ $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
+
+ $entry = new Entry(new User());
+
+ $proxy->assignTagsToEntry($entry, array(' tag1', 'tag2 '));
+
+ $this->assertCount(2, $entry->getTags());
+ $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
+ $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
+ }
+
+ public function testAssignTagsWithString()
+ {
+ $graby = $this->getMockBuilder('Graby\Graby')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $tagRepo = $this->getTagRepositoryMock();
+ $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
+
+ $entry = new Entry(new User());
+
+ $proxy->assignTagsToEntry($entry, 'tag1, tag2');
+
+ $this->assertCount(2, $entry->getTags());
+ $this->assertEquals('tag1', $entry->getTags()[0]->getLabel());
+ $this->assertEquals('tag2', $entry->getTags()[1]->getLabel());
+ }
+
+ public function testAssignTagsWithEmptyArray()
+ {
+ $graby = $this->getMockBuilder('Graby\Graby')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $tagRepo = $this->getTagRepositoryMock();
+ $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
+
+ $entry = new Entry(new User());
+
+ $proxy->assignTagsToEntry($entry, array());
+
+ $this->assertCount(0, $entry->getTags());
+ }
+
+ public function testAssignTagsWithEmptyString()
+ {
+ $graby = $this->getMockBuilder('Graby\Graby')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $tagRepo = $this->getTagRepositoryMock();
+ $proxy = new ContentProxy($graby, $this->getTaggerMock(), $tagRepo, $this->getLogger());
+
+ $entry = new Entry(new User());
+
+ $proxy->assignTagsToEntry($entry, '');
+
+ $this->assertCount(0, $entry->getTags());
+ }
+
+ 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());
+ }
+