*
* @returns array
*/
- public function tags();
+ public function getTags();
/**
* Get the a list if items tagged with $tag.
* @param string|integer $tag Tag id or name.
* @return array An array of object ids or false on error.
*/
- public function idsForTag($tag);
+ public function getIdsForTag($tag);
/**
* Checks whether a tag is already saved.
* @param int|null $id int Optional object id to add to this|these tag(s)
* @return bool Returns false on error.
*/
- public function addMulti($names, $sync=false, $id = null);
+ public function addMultiple($names, $sync=false, $id = null);
/**
* Delete tag/object relations from the db
}
if(count($defaultTags) > 0 && count($this->tags) === 0) {
- $this->addMulti($defaultTags, true);
+ $this->addMultiple($defaultTags, true);
}
\OCP\Util::writeLog('core', __METHOD__.', tags: ' . print_r($this->tags, true),
\OCP\Util::DEBUG);
\OCP\Util::writeLog('core', __METHOD__. ', DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
return false;
}
- return ($result->numRows() === 0);
+ return ((int)$result->numRows() === 0);
} catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
\OCP\Util::ERROR);
*
* @return array
*/
- public function tags() {
+ public function getTags() {
if(!count($this->tags)) {
return array();
}
* @param string|integer $tag Tag id or name.
* @return array An array of object ids or false on error.
*/
- public function idsForTag($tag) {
+ public function getIdsForTag($tag) {
$result = null;
if(is_numeric($tag)) {
$tagId = $tag;
* @param int|null $id int Optional object id to add to this|these tag(s)
* @return bool Returns false on error.
*/
- public function addMulti($names, $sync=false, $id = null) {
+ public function addMultiple($names, $sync=false, $id = null) {
if(!is_array($names)) {
$names = array($names);
}
*/
public function getFavorites() {
try {
- return $this->idsForTag(self::TAG_FAVORITE);
+ return $this->getIdsForTag(self::TAG_FAVORITE);
} catch(\Exception $e) {
\OCP\Util::writeLog('core', __METHOD__.', exception: ' . $e->getMessage(),
\OCP\Util::ERROR);
$tagMgr = new OC\Tags($this->user);
$tagMgr->loadTagsFor($this->objectType, $defaultTags);
- $this->assertEquals(4, count($tagMgr->tags()));
+ $this->assertEquals(4, count($tagMgr->getTags()));
}
public function testAddTags() {
$this->assertFalse($tagMgr->add('Family'));
$this->assertFalse($tagMgr->add('fAMILY'));
- $this->assertEquals(4, count($tagMgr->tags()));
+ $this->assertEquals(4, count($tagMgr->getTags()));
+ }
+
+ public function testAddMultiple() {
+ $tags = array('Friends', 'Family', 'Work', 'Other');
+
+ $tagMgr = new OC\Tags($this->user);
+ $tagMgr->loadTagsFor($this->objectType);
+
+ foreach($tags as $tag) {
+ $this->assertFalse($tagMgr->hasTag($tag));
+ }
+
+ $result = $tagMgr->addMultiple($tags);
+ $this->assertTrue((bool)$result);
+
+ foreach($tags as $tag) {
+ $this->assertTrue($tagMgr->hasTag($tag));
+ }
+
+ $this->assertEquals(4, count($tagMgr->getTags()));
+ }
+
+ public function testIsEmpty() {
+ $tagMgr = new OC\Tags($this->user);
+ $tagMgr->loadTagsFor($this->objectType);
+
+ $this->assertEquals(0, count($tagMgr->getTags()));
+ $this->assertTrue($tagMgr->isEmpty());
+ $tagMgr->add('Tag');
+ $this->assertFalse($tagMgr->isEmpty());
}
public function testdeleteTags() {
$tagMgr = new OC\Tags($this->user);
$tagMgr->loadTagsFor($this->objectType, $defaultTags);
- $this->assertEquals(4, count($tagMgr->tags()));
+ $this->assertEquals(4, count($tagMgr->getTags()));
$tagMgr->delete('family');
- $this->assertEquals(3, count($tagMgr->tags()));
+ $this->assertEquals(3, count($tagMgr->getTags()));
$tagMgr->delete(array('Friends', 'Work', 'Other'));
- $this->assertEquals(0, count($tagMgr->tags()));
+ $this->assertEquals(0, count($tagMgr->getTags()));
}
$tagMgr->tagAs($id, 'Family');
}
- $this->assertEquals(1, count($tagMgr->tags()));
- $this->assertEquals(9, count($tagMgr->idsForTag('Family')));
+ $this->assertEquals(1, count($tagMgr->getTags()));
+ $this->assertEquals(9, count($tagMgr->getIdsForTag('Family')));
}
/**
$tagMgr->loadTagsFor($this->objectType);
foreach($objIds as $id) {
- $this->assertTrue(in_array($id, $tagMgr->idsForTag('Family')));
+ $this->assertTrue(in_array($id, $tagMgr->getIdsForTag('Family')));
$tagMgr->unTag($id, 'Family');
- $this->assertFalse(in_array($id, $tagMgr->idsForTag('Family')));
+ $this->assertFalse(in_array($id, $tagMgr->getIdsForTag('Family')));
}
- $this->assertEquals(1, count($tagMgr->tags()));
- $this->assertEquals(0, count($tagMgr->idsForTag('Family')));
+ $this->assertEquals(1, count($tagMgr->getTags()));
+ $this->assertEquals(0, count($tagMgr->getIdsForTag('Family')));
+ }
+
+ public function testFavorite() {
+ $tagMgr = new OC\Tags($this->user);
+ $tagMgr->loadTagsFor($this->objectType);
+ $this->assertTrue($tagMgr->addToFavorites(1));
+ $this->assertTrue($tagMgr->removeFromFavorites(1));
}
}