]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
unittest for getAdminTags as well as CS and docblock fixes on it
authorChristian Weiske <cweiske@cweiske.de>
Wed, 23 Mar 2011 18:11:38 +0000 (19:11 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 23 Mar 2011 18:11:38 +0000 (19:11 +0100)
src/SemanticScuttle/Service/Bookmark2Tag.php
tests/Bookmark2TagTest.php

index e3997ddd11c068df2e7bf11d483eb6cdbc8d412d..d367b62a87908f959c43cd7cc0e3187d2f60b110 100644 (file)
@@ -454,15 +454,37 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
         return $output;
     }
 
-    function &getAdminTags($limit = 30, $logged_on_user = NULL, $days = NULL) {
+
+
+    /**
+     * Returns the tags used by admin users
+     *
+     * @param integer $limit          Number of tags to return
+     * @param integer $logged_on_user ID of the user that's currently logged in.
+     *                                If the logged in user equals the $user to find
+     *                                tags for, tags of private bookmarks are
+     *                                returned.
+     * @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 getAdminTags(
+        $limit = 30, $logged_on_user = null, $days = null
+    ) {
         // look for admin ids
-        $userservice = SemanticScuttle_Service_Factory :: get('User');
-        $adminIds = $userservice->getAdminIds();
+        $userservice = SemanticScuttle_Service_Factory::get('User');
+        $adminIds    = $userservice->getAdminIds();
 
         // ask for their tags
         return $this->getPopularTags($adminIds, $limit, $logged_on_user, $days);
     }
 
+
+
     function &getContactTags($user, $limit = 30, $logged_on_user = NULL, $days = NULL) {
         // look for contact ids
         $userservice = SemanticScuttle_Service_Factory :: get('User');
@@ -477,6 +499,8 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
         return $this->getPopularTags($contacts, $limit, $logged_on_user, $days);
     }
 
+
+
     /**
      * The the most popular tags and their usage count
      *
index a83a8262c163d37b2a1d2c09febac78b401d35ca..d85cf73b58190de8f13434039bb76b645e81334e 100644 (file)
@@ -56,6 +56,7 @@ class Bookmark2TagTest extends TestBase
     protected function setUp()
     {
         $this->us = SemanticScuttle_Service_Factory::get('User');
+        $this->us->deleteAll();
         $this->bs = SemanticScuttle_Service_Factory::get('Bookmark');
         $this->bs->deleteAll();
         $this->b2ts= SemanticScuttle_Service_Factory::get('Bookmark2Tag');
@@ -447,6 +448,25 @@ class Bookmark2TagTest extends TestBase
         $this->assertContains(array('tag' => 'two', 'bCount' => '1'), $arTags);
         $this->assertContains(array('tag' => 'thr', 'bCount' => '1'), $arTags);
     }
+
+
+    public function testGetAdminTags()
+    {
+        $admin1 = $this->addUser('admin1');
+        $admin2 = $this->addUser('admin2');
+        $user1  = $this->addUser();
+        $this->addBookmark($admin1, null, 0, array('admintag', 'admintag1'));
+        $this->addBookmark($admin2, null, 0, array('admintag', 'admintag2'));
+        $this->addBookmark($user1, null, 0, array('usertag'));
+
+        $GLOBALS['admin_users'] = array('admin1', 'admin2');
+        
+        $arTags = $this->b2ts->getAdminTags(4);
+        $this->assertEquals(3, count($arTags));
+        $this->assertContains(array('tag' => 'admintag', 'bCount' => '2'), $arTags);
+        $this->assertContains(array('tag' => 'admintag1', 'bCount' => '1'), $arTags);
+        $this->assertContains(array('tag' => 'admintag2', 'bCount' => '1'), $arTags);
+    }
 }
 
 if (PHPUnit_MAIN_METHOD == 'Bookmark2TagTest::main') {