]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
unittest for Bookmark2Tag::getContactTags, CS and docblock
authorChristian Weiske <cweiske@cweiske.de>
Thu, 24 Mar 2011 07:36:54 +0000 (08:36 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 24 Mar 2011 07:36:54 +0000 (08:36 +0100)
src/SemanticScuttle/Service/Bookmark2Tag.php
tests/Bookmark2TagTest.php

index d367b62a87908f959c43cd7cc0e3187d2f60b110..478b47edba88bf48d4e1e3d7842c4094d16eaab8 100644 (file)
@@ -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
index d85cf73b58190de8f13434039bb76b645e81334e..ad64bf6a00f9a169787fb432f39e517c89f2f82d 100644 (file)
@@ -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') {