Permalink
Browse files

Added method to build an array of tag names

  • Loading branch information...
1 parent 6205ae4 commit c0b5f5ad40c72f711fb9281ec15f53c951f048cc @FabienPennequin FabienPennequin committed Aug 14, 2011
@@ -259,6 +259,24 @@ public function splitTagNames($names, $separator=',')
}
/**
+ * Returns an array of tag names for the given Taggable resource.
+ *
+ * @param Taggable $resource Taggable resource
+ */
+ public function getTagNames(Taggable $resource)
+ {
+ $names = array();
+
+ if (sizeof($resource->getTags()) > 0) {
+ foreach ($resource->getTags() as $tag) {
+ $names[] = $tag->getName();
+ }
+ }
+
+ return $names;
+ }
+
+ /**
* Creates a new Tag object
*
* @param string $name Tag name
@@ -295,4 +295,25 @@ public function testSplitTagNames()
$this->assertEquals(array('Smallville', 'Superman', 'TV'), $this->manager->splitTagNames(' Smallville Superman TV ', ' '));
}
+
+ /**
+ * @covers DoctrineExtensions\Taggable\TagManager::getTagNames
+ */
+ public function testGetTagNames()
+ {
+ $article = new Article();
+ $article->setTitle('Unit Test');
+
+ $this->assertEquals(array(), $this->manager->getTagNames($article));
+
+ $tag1 = new Tag('Smallville');
+ $this->manager->addTag($tag1, $article);
+ $this->assertEquals(array('Smallville'), $this->manager->getTagNames($article));
+
+ $tag2 = new Tag('Superman');
+ $tag3 = new Tag('TV');
+ $this->manager->addTags(array($tag2, $tag3), $article);
+ $this->assertEquals(array('Smallville', 'Superman', 'TV'), $this->manager->getTagNames($article));
+ }
+
}

0 comments on commit c0b5f5a

Please sign in to comment.