]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
fix privacy protection issue when fetching tags of several users
authorChristian Weiske <cweiske@cweiske.de>
Thu, 24 Mar 2011 18:07:50 +0000 (19:07 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 24 Mar 2011 18:07:50 +0000 (19:07 +0100)
src/SemanticScuttle/Service/Bookmark2Tag.php
tests/Bookmark2TagTest.php

index b69cfd430e6a75de350eec63502af3d5638ad4d9..21ea0d5a8ab8badb9f39d4f0f1c0896631090530 100644 (file)
@@ -565,7 +565,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
                 $query .= ' OR B.uId = ' . $this->db->sql_escape($u)
                     . ' AND B.bId = T.bId';
             }
-            $query .= ' )';
+            $query .= ' )' . $privacy;
         } else {
             $query .= ' B.uId = ' . $this->db->sql_escape($user)
                 . ' AND B.bId = T.bId' . $privacy;
index ad64bf6a00f9a169787fb432f39e517c89f2f82d..e2020dc5d36dcf435db297142540278bd8195246 100644 (file)
@@ -37,6 +37,26 @@ class Bookmark2TagTest extends TestBase
     protected $tts;
 
 
+    /**
+     * Create a bookmark. Like addBookmark(), just with other paramter order
+     * to make some tests in that class easier to write.
+     *
+     * @param integer $user    User ID the bookmark shall belong
+     * @param array   $tags    Array of tags to attach. If "null" is given,
+     *                         it will automatically be "unittest"
+     * @param string  $date    strtotime-compatible string
+     * @param string  $title   Bookmark title
+     *
+     * @return integer ID of bookmark
+     */
+    protected function addTagBookmark($user, $tags, $date = null, $title = null)
+    {
+        return $this->addBookmark(
+            $user, null, 0, $tags, $title, $date
+        );
+    }
+
+
 
     /**
      * Used to run this test class standalone
@@ -207,25 +227,6 @@ class Bookmark2TagTest extends TestBase
     }
 
 
-    /**
-     * Create a bookmark
-     *
-     * @param integer $user    User ID the bookmark shall belong
-     * @param array   $tags    Array of tags to attach. If "null" is given,
-     *                         it will automatically be "unittest"
-     * @param string  $date    strtotime-compatible string
-     * @param string  $title   Bookmark title
-     *
-     * @return integer ID of bookmark
-     */
-    protected function addTagBookmark($user, $tags, $date = null, $title = null)
-    {
-        return $this->addBookmark(
-            $user, null, 0, $tags, $title, $date
-        );
-    }
-
-
 
     /**
      * Fetch the most popular tags in descending order
@@ -398,10 +399,12 @@ class Bookmark2TagTest extends TestBase
         $this->assertContains(array('tag' => 'thr', 'bCount' => '1'), $arTags);
     }
 
+
+
     /**
      * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags
      */
-    public function testGetPopularTagsPublicOnly()
+    public function testGetPopularTagsPublicOnlyNoUser()
     {
         $user1 = $this->addUser();
         $this->addBookmark($user1, null, 0, array('one'));
@@ -416,7 +419,13 @@ class Bookmark2TagTest extends TestBase
             ),
             $arTags
         );
+    }
 
+    /**
+     * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags
+     */
+    public function testGetPopularTagsPublicOnlySingleUser()
+    {
         $user1 = $this->addUser();
         $this->addBookmark($user1, null, 0, array('one'));
         $this->addBookmark($user1, null, 1, array('one', 'two'));
@@ -432,6 +441,26 @@ class Bookmark2TagTest extends TestBase
         );
     }
 
+    /**
+     * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags
+     */
+    public function testGetPopularTagsPublicOnlySeveralUsers()
+    {
+        $user1 = $this->addUser();
+        $user2 = $this->addUser();
+        $this->addBookmark($user1, null, 0, array('one'));
+        $this->addBookmark($user1, null, 1, array('one', 'two'));
+        $this->addBookmark($user1, null, 2, array('thr'));
+        $this->addBookmark($user2, null, 0, array('fou'));
+        $this->addBookmark($user2, null, 1, array('fiv'));
+        $this->addBookmark($user2, null, 2, array('six'));
+
+        $arTags = $this->b2ts->getPopularTags(array($user1, $user2));
+        $this->assertEquals(2, count($arTags));
+        $this->assertContains(array('tag' => 'one', 'bCount' => '1'), $arTags);
+        $this->assertContains(array('tag' => 'fou', 'bCount' => '1'), $arTags);
+    }
+
     /**
      * @covers SemanticScuttle_Service_Bookmark2Tag::getPopularTags
      */