summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/SemanticScuttle/Service/Bookmark2Tag.php31
-rw-r--r--tests/Bookmark2TagTest.php62
2 files changed, 83 insertions, 10 deletions
diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php
index d367b62..478b47e 100644
--- a/src/SemanticScuttle/Service/Bookmark2Tag.php
+++ b/src/SemanticScuttle/Service/Bookmark2Tag.php
@@ -485,13 +485,33 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
- function &getContactTags($user, $limit = 30, $logged_on_user = NULL, $days = NULL) {
+
+ /**
+ * Returns the tags used by users that are part of the user's watchlist,
+ * and the current user's own tags.
+ *
+ * @param integer $user ID of the user to get the watchlist from
+ * @param integer $limit Number of tags to return
+ * @param integer $logged_on_user ID of the user that's currently logged in.
+ * If set, that user is added to the list of
+ * people to get the tags from
+ * @param integer $days Bookmarks have to be changed in the last X days
+ * if their tags shall count*
+ *
+ * @return array Array of found tags. Each tag entry is an array with two keys,
+ * 'tag' (tag name) and 'bCount'.
+ *
+ * @see getPopularTags()
+ */
+ public function getContactTags(
+ $user, $limit = 30, $logged_on_user = null, $days = null
+ ) {
// look for contact ids
- $userservice = SemanticScuttle_Service_Factory :: get('User');
+ $userservice = SemanticScuttle_Service_Factory::get('User');
$contacts = $userservice->getWatchlist($user);
- // add the user (to show him/her also his/her tags)
- if(!is_null($logged_on_user)) {
+ // add the user (to show him also his own tags)
+ if (!is_null($logged_on_user)) {
$contacts[] = $logged_on_user;
}
@@ -516,6 +536,9 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
*
* @return array Array of found tags. Each tag entry is an array with two keys,
* 'tag' (tag name) and 'bCount'.
+ *
+ * @see getAdminTags()
+ * @see getContactTags()
*/
public function getPopularTags(
$user = null, $limit = 30, $logged_on_user = null, $days = null
diff --git a/tests/Bookmark2TagTest.php b/tests/Bookmark2TagTest.php
index d85cf73..ad64bf6 100644
--- a/tests/Bookmark2TagTest.php
+++ b/tests/Bookmark2TagTest.php
@@ -74,7 +74,7 @@ class Bookmark2TagTest extends TestBase
/**
* Test getTagsForBookmark() when the bookmark has no tags
*
- * @return void
+ * @covers SemanticScuttle_Service_Bookmark2Tag::getTagsForBookmark
*/
public function testGetTagsForBookmarkNone()
{
@@ -92,7 +92,7 @@ class Bookmark2TagTest extends TestBase
/**
* Test getTagsForBookmark() when the bookmark has one tag
*
- * @return void
+ * @covers SemanticScuttle_Service_Bookmark2Tag::getTagsForBookmark
*/
public function testGetTagsForBookmarkOne()
{
@@ -109,9 +109,9 @@ class Bookmark2TagTest extends TestBase
/**
- * Test getTagsForBookmark() when the bookmark has thr tags
+ * Test getTagsForBookmark() when the bookmark has three tags
*
- * @return void
+ * @covers SemanticScuttle_Service_Bookmark2Tag::getTagsForBookmark
*/
public function testGetTagsForBookmarkThr()
{
@@ -132,7 +132,7 @@ class Bookmark2TagTest extends TestBase
/**
* Test getTagsForBookmarks() when no bookmarks have tags.
*
- * @return void
+ * @covers SemanticScuttle_Service_Bookmark2Tag::getTagsForBookmarks
*/
public function testGetTagsForBookmarksNone()
{
@@ -155,7 +155,7 @@ class Bookmark2TagTest extends TestBase
/**
* Test getTagsForBookmarks() when most bookmarks have tags.
*
- * @return void
+ * @covers SemanticScuttle_Service_Bookmark2Tag::getTagsForBookmarks
*/
public function testGetTagsForBookmarksMost()
{
@@ -450,6 +450,9 @@ class Bookmark2TagTest extends TestBase
}
+ /**
+ * @covers SemanticScuttle_Service_Bookmark2Tag::getAdminTags
+ */
public function testGetAdminTags()
{
$admin1 = $this->addUser('admin1');
@@ -467,6 +470,53 @@ class Bookmark2TagTest extends TestBase
$this->assertContains(array('tag' => 'admintag1', 'bCount' => '1'), $arTags);
$this->assertContains(array('tag' => 'admintag2', 'bCount' => '1'), $arTags);
}
+
+
+
+ /**
+ * @covers SemanticScuttle_Service_Bookmark2Tag::getContactTags
+ */
+ public function testGetContactTagsWatchlistOnly()
+ {
+ $user1 = $this->addUser();
+ $user2 = $this->addUser();
+ $user3 = $this->addUser();
+ $this->us->setCurrentUserId($user1);
+ $this->us->setWatchStatus($user2);
+ //user1 watches user2 now
+
+ $this->addBookmark($user1, null, 0, array('usertag', 'usertag1'));
+ $this->addBookmark($user2, null, 0, array('usertag', 'usertag2'));
+ $this->addBookmark($user3, null, 0, array('usertag', 'usertag3'));
+
+ $arTags = $this->b2ts->getContactTags($user1, 10);
+ $this->assertEquals(2, count($arTags));
+ $this->assertContains(array('tag' => 'usertag', 'bCount' => '1'), $arTags);
+ $this->assertContains(array('tag' => 'usertag2', 'bCount' => '1'), $arTags);
+ }
+
+ /**
+ * @covers SemanticScuttle_Service_Bookmark2Tag::getContactTags
+ */
+ public function testGetContactTagsIncludingUser()
+ {
+ $user1 = $this->addUser();
+ $user2 = $this->addUser();
+ $user3 = $this->addUser();
+ $this->us->setCurrentUserId($user1);
+ $this->us->setWatchStatus($user2);
+ //user1 watches user2 now
+
+ $this->addBookmark($user1, null, 0, array('usertag', 'usertag1'));
+ $this->addBookmark($user2, null, 0, array('usertag', 'usertag2'));
+ $this->addBookmark($user3, null, 0, array('usertag', 'usertag3'));
+
+ $arTags = $this->b2ts->getContactTags($user1, 10, $user1);
+ $this->assertEquals(3, count($arTags));
+ $this->assertContains(array('tag' => 'usertag', 'bCount' => '2'), $arTags);
+ $this->assertContains(array('tag' => 'usertag1', 'bCount' => '1'), $arTags);
+ $this->assertContains(array('tag' => 'usertag2', 'bCount' => '1'), $arTags);
+ }
}
if (PHPUnit_MAIN_METHOD == 'Bookmark2TagTest::main') {