summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/SemanticScuttle/Service/Bookmark.php7
-rw-r--r--tests/BookmarkTest.php53
2 files changed, 60 insertions, 0 deletions
diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php
index 1975b22..f671fba 100644
--- a/src/SemanticScuttle/Service/Bookmark.php
+++ b/src/SemanticScuttle/Service/Bookmark.php
@@ -778,6 +778,13 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
+ /**
+ * Deletes all bookmarks of the given user
+ *
+ * @param integer $uId User ID
+ *
+ * @return boolean true when all went well
+ */
public function deleteBookmarksForUser($uId)
{
$query = 'DELETE FROM '. $GLOBALS['tableprefix'] .'bookmarks WHERE uId = '. intval($uId);
diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php
index f7d8ead..0b47bc2 100644
--- a/tests/BookmarkTest.php
+++ b/tests/BookmarkTest.php
@@ -343,6 +343,59 @@ class BookmarkTest extends TestBase
/**
+ * Test if deleting all bookmarks for a user works.
+ *
+ * @return void
+ */
+ public function testDeleteBookmarksForUser()
+ {
+ $uid = $this->addUser();
+ $bookmarks = $this->bs->getBookmarks(0, null, $uid);
+ $this->assertEquals(0, $bookmarks['total']);
+
+ $this->addBookmark($uid);
+ $this->addBookmark($uid);
+ $bookmarks = $this->bs->getBookmarks(0, null, $uid);
+ $this->assertEquals(2, $bookmarks['total']);
+
+ $this->bs->deleteBookmarksForUser($uid);
+ $bookmarks = $this->bs->getBookmarks(0, null, $uid);
+ $this->assertEquals(0, $bookmarks['total']);
+ }
+
+
+
+ /**
+ * Test if deleting all bookmarks for a user works
+ * and does not damage other user's bookmarks.
+ *
+ * @return void
+ */
+ public function testDeleteBookmarksForUserOthers()
+ {
+ $uidOther = $this->addUser();
+ $this->addBookmark($uidOther);
+
+ $uid = $this->addUser();
+ $bookmarks = $this->bs->getBookmarks(0, null, $uid);
+ $this->assertEquals(0, $bookmarks['total']);
+
+ $this->addBookmark($uid);
+ $this->addBookmark($uid);
+ $bookmarks = $this->bs->getBookmarks(0, null, $uid);
+ $this->assertEquals(2, $bookmarks['total']);
+
+ $this->bs->deleteBookmarksForUser($uid);
+ $bookmarks = $this->bs->getBookmarks(0, null, $uid);
+ $this->assertEquals(0, $bookmarks['total']);
+
+ $bookmarks = $this->bs->getBookmarks(0, null, $uidOther);
+ $this->assertEquals(1, $bookmarks['total']);
+ }
+
+
+
+ /**
* Test if deleting a bookmark with a vote works.
*
* @return void