From 157adfd7eb157917d338571426ad94539c37c3f8 Mon Sep 17 00:00:00 2001 From: cweiske Date: Tue, 16 Feb 2010 21:55:50 +0000 Subject: multiple tests for SemanticScuttle_Service_Bookmark::countOthers() git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@655 b3834d28-1941-0410-a4f8-b48e95affb8f --- tests/BookmarkTest.php | 101 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) (limited to 'tests/BookmarkTest.php') diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index 741b6bf..ca4ff3e 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -778,6 +778,107 @@ class BookmarkTest extends TestBase $this->assertEquals('newShortNambb', $bm['bShort']); } + + + /** + * Test what countOther() returns when the address does not exist + * + * @return void + */ + public function testCountOthersAddressDoesNotExist() + { + $this->assertEquals(0, $this->bs->countOthers('http://example.org')); + } + + + + /** + * Test what countOther() returns when nobody else has the same bookmark + * + * @return void + */ + public function testCountOthersNone() + { + $uid = $this->addUser(); + $address = 'http://example.org'; + $this->addBookmark($uid, $address); + $this->assertEquals(0, $this->bs->countOthers($address)); + } + + + + /** + * Test what countOther() returns when the address exists only once + * and multiple bookmarks are in the database. + * + * @return void + */ + public function testCountOthersMultipleNone() + { + $uid = $this->addUser(); + $address = 'http://example.org'; + $this->addBookmark($uid, $address); + $this->addBookmark($uid); + $this->addBookmark($uid); + $this->assertEquals(0, $this->bs->countOthers($address)); + } + + + + /** + * Test what countOther() returns when the address exists only once + * and the same user and other users have other bookmarks + * + * @return void + */ + public function testCountOthersMultipleUsersNone() + { + $uid = $this->addUser(); + $uid2 = $this->addUser(); + $address = 'http://example.org'; + $this->addBookmark($uid, $address); + $this->addBookmark($uid); + $this->addBookmark($uid2); + $this->assertEquals(0, $this->bs->countOthers($address)); + } + + + + /** + * Test what countOther() returns when the address exists two + * times in the database. + * + * @return void + */ + public function testCountOthersOne() + { + $uid = $this->addUser(); + $uid2 = $this->addUser(); + $address = 'http://example.org'; + $this->addBookmark($uid, $address); + $this->addBookmark($uid2, $address); + $this->assertEquals(1, $this->bs->countOthers($address)); + } + + + + /** + * Test what countOther() returns when the address exists four + * times in the database. + * + * @return void + */ + public function testCountOthersThree() + { + $uid = $this->addUser(); + $address = 'http://example.org'; + $this->addBookmark($uid, $address); + $this->addBookmark(null, $address); + $this->addBookmark(null, $address); + $this->addBookmark(null, $address); + $this->assertEquals(3, $this->bs->countOthers($address)); + } + } -- cgit v1.2.3-54-g00ecf From 2f13a1c81956dba215ae37c7debf58de5e658ad4 Mon Sep 17 00:00:00 2001 From: cweiske Date: Tue, 16 Feb 2010 21:58:00 +0000 Subject: test complex combination of watches, publics and private bookmarks with countOthers() git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@657 b3834d28-1941-0410-a4f8-b48e95affb8f --- tests/BookmarkTest.php | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'tests/BookmarkTest.php') diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index ca4ff3e..d791b9e 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -879,6 +879,70 @@ class BookmarkTest extends TestBase $this->assertEquals(3, $this->bs->countOthers($address)); } + + + /** + * Test what countOther() returns when the user is logged in + * and friends (people on the watchlist) have bookmarked + * and shared the same address. + * + * @return void + */ + public function testCountOthersWatchlist() + { + $uid = $this->addUser(); + $address = 'http://example.org'; + //log user in + $this->us->setCurrentUserId($uid); + + //setup users + $otherPublic1 = $this->addUser(); + $otherPublic2 = $this->addUser(); + $otherShared1 = $this->addUser(); + $otherPrivate1 = $this->addUser(); + $friendPublic1 = $this->addUser(); + $friendShared1 = $this->addUser(); + $friendShared2 = $this->addUser(); + $friendPrivate1 = $this->addUser(); + $friendSharing1 = $this->addUser(); + + //setup watchlists + $us = SemanticScuttle_Service_Factory::get('User'); + $this->us->setCurrentUserId($friendPublic1); + $us->setWatchStatus($uid); + $this->us->setCurrentUserId($friendShared1); + $us->setWatchStatus($uid); + $this->us->setCurrentUserId($friendShared2); + $us->setWatchStatus($uid); + $this->us->setCurrentUserId($friendPrivate1); + $us->setWatchStatus($uid); + + //back to login of main user + $this->us->setCurrentUserId($uid); + $us->setWatchStatus($friendSharing1); + + //add bookmarks + $this->addBookmark($uid, $address, 0); + $this->addBookmark($otherPublic1, $address, 0); + $this->addBookmark($otherPublic2, $address, 0); + $this->addBookmark($otherShared1, $address, 1); + $this->addBookmark($otherPrivate1, $address, 2); + $this->addBookmark($friendPublic1, $address, 0); + $this->addBookmark($friendShared1, $address, 1); + $this->addBookmark($friendShared2, $address, 1); + $this->addBookmark($friendPrivate1, $address, 2); + //this user is on our watchlist, but we not on his + $this->addBookmark($friendSharing1, $address, 1); + + //2 public + //1 public (friend) + //2 shared + //-> 5 + $this->assertEquals(5, $this->bs->countOthers($address)); + } + + + } -- cgit v1.2.3-54-g00ecf From 6b7217daf298be65347205aa7a0fee17ff37b87c Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:03:20 +0000 Subject: make countOthers() accept an array of addresses git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@659 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 57 +++++++++++++++++------ tests/BookmarkTest.php | 80 ++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 13 deletions(-) (limited to 'tests/BookmarkTest.php') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 05ea060..c7bfb3b 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -891,17 +891,29 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService /** * Counts the number of bookmarks that have the same address - * as the given address - * - * @param string $address Address/URL to look for - * - * @return integer Number of bookmarks minus one that have the address + * as the given address. + * + * @internal + * We do support fetching counts for multiple addresses at once + * because that allows us to reduce the number of queries + * we need in the web interface when displaying i.e. + * 10 bookmarks - only one SQL query is needed then. + * + * @param string|array $addresses Address/URL to look for, string + * of one address or array with + * multiple ones + * + * @return integer Number of bookmarks minus one that have the address. + * In case $addresses was an array, key-value array + * with key being the address, value said number of + * bookmarks */ - public function countOthers($address) + public function countOthers($addresses) { - if (!$address) { + if (!$addresses) { return false; } + $bArray = is_array($addresses); $us = SemanticScuttle_Service_Factory::get('User'); $sId = (int)$us->getCurrentUserId(); @@ -922,12 +934,22 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $privacy = ' AND B.bStatus = 0'; } - $sql = 'SELECT COUNT(*) as "0" FROM ' + $addressesSql = ' AND (0'; + foreach ((array)$addresses as $address) { + $addressesSql .= ' OR B.bHash = "' + . $this->db->sql_escape(md5($address)) + . '"'; + } + $addressesSql .= ')'; + + + $sql = 'SELECT B.bAddress, COUNT(*) as count FROM ' . $us->getTableName() . ' AS U' . ', '. $GLOBALS['tableprefix'] . 'bookmarks AS B' . ' WHERE U.'. $us->getFieldName('primary') .' = B.uId' - . ' AND B.bHash = "'. md5($address) . '"' - . $privacy; + . $addressesSql + . $privacy + . ' GROUP BY B.bHash'; if (!($dbresult = $this->db->sql_query($sql))) { message_die( @@ -936,10 +958,19 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService ); } - $count = $this->db->sql_fetchfield(0, 0); - $count = ($count > 0) ? $count - 1 : (int)$count; + //be sure we also list urls in our array + // that are not found in the database + $counts = array_combine( + (array)$addresses, + array_fill(0, count((array)$addresses), 0) + ); + while ($row = $this->db->sql_fetchrow($dbresult)) { + $counts[$row['bAddress']] + = $row['count'] > 0 ? $row['count'] - 1 : 0; + } $this->db->sql_freeresult($dbresult); - return $count; + + return $bArray ? $counts : reset($counts); } diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index d791b9e..69e6e8a 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -943,6 +943,86 @@ class BookmarkTest extends TestBase + /** + * Test what countOther() returns when multiple addresses are + * passed to it and none of them exists. + * + * @return void + */ + public function testCountOthersArrayNone() + { + $this->assertEquals( + array('1' => 0, '2' => 0, '3' => 0), + $this->bs->countOthers(array('1', '2', '3')) + ); + } + + + + /** + * Test what countOther() returns when multiple addresses are + * passed to it and only one of them exists. + * + * @return void + */ + public function testCountOthersArrayOneNone() + { + $uid = $this->addUser(); + $uid2 = $this->addUser(); + $address1 = 'http://example.org/1'; + $address2 = 'http://example.org/2'; + $this->addBookmark($uid, $address1); + $this->addBookmark($uid, $address2); + $this->addBookmark($uid2, $address1); + $this->assertEquals( + array( + $address1 => 1, + $address2 => 0 + ), + $this->bs->countOthers( + array($address1, $address2) + ) + ); + } + + + + /** + * Test what countOther() returns when multiple addresses are passed + * to it and both of them exist with different numbers for each. + * + * @return void + */ + public function testCountOthersArrayTwoOne() + { + $uid = $this->addUser(); + $uid2 = $this->addUser(); + $uid3 = $this->addUser(); + + $address1 = 'http://example.org/1'; + $address2 = 'http://example.org/2'; + + $this->addBookmark($uid, $address1); + $this->addBookmark($uid, $address2); + + $this->addBookmark($uid2, $address1); + $this->addBookmark($uid2, $address2); + + $this->addBookmark($uid3, $address1); + + $this->assertEquals( + array( + $address1 => 2, + $address2 => 1 + ), + $this->bs->countOthers( + array($address1, $address2) + ) + ); + } + + + } -- cgit v1.2.3-54-g00ecf From 46b96044fb2375d4b522fa074788199d80b4d243 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:07:37 +0000 Subject: test getBookmarks() with tag loading functionality git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@662 b3834d28-1941-0410-a4f8-b48e95affb8f --- tests/BookmarkTest.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests/BookmarkTest.php') diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index 69e6e8a..39a9974 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -331,6 +331,40 @@ class BookmarkTest extends TestBase + /** + * Check tag loading functionality of getBookmarks() + * + * @return void + */ + public function testGetBookmarksIncludeTags() + { + $uid = $this->addUser(); + $bid = $this->addBookmark($uid); + $this->b2ts->attachTags($bid, array('foo', 'bar')); + $bid2 = $this->addBookmark($uid); + $this->b2ts->attachTags($bid2, array('fuu', 'baz')); + + $bms = $this->bs->getBookmarks(); + $this->assertEquals(2, count($bms['bookmarks'])); + $this->assertEquals(2, $bms['total']); + + foreach ($bms['bookmarks'] as $bm) { + $this->assertArrayHasKey('tags', $bm); + $this->assertType('array', $bm['tags']); + if ($bm['bId'] == $bid) { + $this->assertContains('foo', $bm['tags']); + $this->assertContains('bar', $bm['tags']); + } else if ($bm['bId'] == $bid2) { + $this->assertContains('fuu', $bm['tags']); + $this->assertContains('baz', $bm['tags']); + } else { + $this->assertTrue(false, 'Unknown bookmark id'); + } + } + } + + + /** * Test if deleting a bookmark works. * -- cgit v1.2.3-54-g00ecf From 17374001b8ccfe806851862c91b29671ba998828 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:39:03 +0000 Subject: add SemanticScuttle_Service_Bookmark::bookmarksExist() method to check for existance of multiple bookmarks at once for future sql optimization git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@680 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 56 +++++++++++++- tests/BookmarkTest.php | 122 +++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+), 1 deletion(-) (limited to 'tests/BookmarkTest.php') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 10b0b8b..a1bb1a5 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -312,7 +312,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService * @return boolean True when the bookmark with the given URL * exists for the user, false if not. */ - function bookmarkExists($address = false, $uid = null) + public function bookmarkExists($address = false, $uid = null) { if (!$address) { return false; @@ -346,6 +346,60 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService + /** + * Checks if the given addresses exist + * + * @param array $addresses Array of addresses + * @param integer $uid User ID the addresses shall belong to + * + * @return array Array with addresses as keys, true/false for existence + * as value + */ + public function bookmarksExist($addresses, $uid = null) + { + if (count($addresses) == 0) { + return array(); + } + + $hashes = array(); + $sql = '(1'; + foreach ($addresses as $key => $address) { + $hash = md5($this->normalize($address)); + $hashes[$hash] = $address; + $sql .= ' OR bHash = "' + . $this->db->sql_escape($hash) + . '"'; + } + $sql .= ')'; + if ($uid !== null) { + $sql .= ' AND uId = ' . intval($uid); + } + + $sql = 'SELECT bHash, COUNT(*) as "count" FROM ' + . $this->getTableName() + . ' WHERE ' . $sql + . ' GROUP BY bHash'; + + if (!($dbresult = $this->db->sql_query($sql))) { + message_die( + GENERAL_ERROR, 'Could not get bookmark counts', '', + __LINE__, __FILE__, $sql, $this->db + ); + } + + $existence = array_combine( + $addresses, + array_fill(0, count($addresses), false) + ); + while ($row = $this->db->sql_fetchrow($dbresult)) { + $existence[$hashes[$row['bHash']]] = $row['count'] > 0; + } + + return $existence; + } + + + /** * Adds a bookmark to the database. * diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index 39a9974..74685c4 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -252,6 +252,128 @@ class BookmarkTest extends TestBase + /** + * Tests if bookmarksExist() returns true when a bookmark + * exists + * + * @return void + */ + public function testBookmarksExistTrueSingle() + { + $bid = $this->addBookmark(); + $bookmark = $this->bs->getBookmark($bid); + + $ret = $this->bs->bookmarksExist(array($bookmark['bAddress'])); + $this->assertType('array', $ret); + $this->assertEquals(1, count($ret)); + $this->assertTrue($ret[$bookmark['bAddress']]); + } + + + + /** + * Tests if bookmarksExist() returns true when all bookmarks + * exist + * + * @return void + */ + public function testBookmarksExistTrueMultiple() + { + $bid = $this->addBookmark(); + $bookmark = $this->bs->getBookmark($bid); + + $bid2 = $this->addBookmark(); + $bookmark2 = $this->bs->getBookmark($bid2); + + + $ret = $this->bs->bookmarksExist( + array( + $bookmark['bAddress'], + $bookmark2['bAddress'] + ) + ); + $this->assertType('array', $ret); + $this->assertEquals(2, count($ret)); + $this->assertTrue($ret[$bookmark['bAddress']]); + $this->assertTrue($ret[$bookmark2['bAddress']]); + } + + + + /** + * Tests if bookmarksExist() returns false when a bookmark + * does not exist + * + * @return void + */ + public function testBookmarksExistFalseSingle() + { + $ret = $this->bs->bookmarksExist(array('does-not-exist')); + $this->assertType('array', $ret); + $this->assertEquals(1, count($ret)); + $this->assertFalse($ret['does-not-exist']); + } + + + + /** + * Tests if bookmarksExist() returns false when all bookmarks + * do not exist + * + * @return void + */ + public function testBookmarksExistFalseMultiple() + { + $bms = array( + 'does-not-exist', + 'does-not-exist-2', + 'does-not-exist-3', + ); + $ret = $this->bs->bookmarksExist($bms); + $this->assertType('array', $ret); + $this->assertEquals(3, count($ret)); + $this->assertFalse($ret['does-not-exist']); + $this->assertFalse($ret['does-not-exist-2']); + $this->assertFalse($ret['does-not-exist-3']); + } + + + + /** + * Tests if bookmarksExist() returns true when some bookmarks + * exist. + * + * @return void + */ + public function testBookmarksExistSome() + { + $bid = $this->addBookmark(); + $bookmark = $this->bs->getBookmark($bid); + + $bid2 = $this->addBookmark(); + $bookmark2 = $this->bs->getBookmark($bid2); + + + $ret = $this->bs->bookmarksExist( + array( + $bookmark['bAddress'], + 'does-not-exist', + $bookmark2['bAddress'], + 'does-not-exist-2', + 'does-not-exist-3' + ) + ); + $this->assertType('array', $ret); + $this->assertEquals(5, count($ret)); + $this->assertTrue($ret[$bookmark['bAddress']]); + $this->assertTrue($ret[$bookmark2['bAddress']]); + $this->assertFalse($ret['does-not-exist']); + $this->assertFalse($ret['does-not-exist-2']); + $this->assertFalse($ret['does-not-exist-3']); + } + + + /** * Test if countBookmarks() works with no bookmarks * -- cgit v1.2.3-54-g00ecf From 858b188f87898099a4824d07fbcdf892a76c1876 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:44:06 +0000 Subject: add missing piece of faulty merge git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@683 b3834d28-1941-0410-a4f8-b48e95affb8f --- tests/BookmarkTest.php | 165 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) (limited to 'tests/BookmarkTest.php') diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index 74685c4..0b4f01d 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -1179,6 +1179,171 @@ class BookmarkTest extends TestBase + + + /** + * Test what countOther() returns when the address does not exist + * + * @return void + */ + public function testCountOthersAddressDoesNotExist() + { + $this->assertEquals(0, $this->bs->countOthers('http://example.org')); + } + + + + /** + * Test what countOther() returns when nobody else has the same bookmark + * + * @return void + */ + public function testCountOthersNone() + { + $uid = $this->addUser(); + $address = 'http://example.org'; + $this->addBookmark($uid, $address); + $this->assertEquals(0, $this->bs->countOthers($address)); + } + + + + /** + * Test what countOther() returns when the address exists only once + * and multiple bookmarks are in the database. + * + * @return void + */ + public function testCountOthersMultipleNone() + { + $uid = $this->addUser(); + $address = 'http://example.org'; + $this->addBookmark($uid, $address); + $this->addBookmark($uid); + $this->addBookmark($uid); + $this->assertEquals(0, $this->bs->countOthers($address)); + } + + + + /** + * Test what countOther() returns when the address exists only once + * and the same user and other users have other bookmarks + * + * @return void + */ + public function testCountOthersMultipleUsersNone() + { + $uid = $this->addUser(); + $uid2 = $this->addUser(); + $address = 'http://example.org'; + $this->addBookmark($uid, $address); + $this->addBookmark($uid); + $this->addBookmark($uid2); + $this->assertEquals(0, $this->bs->countOthers($address)); + } + + + + /** + * Test what countOther() returns when the address exists two + * times in the database. + * + * @return void + */ + public function testCountOthersOne() + { + $uid = $this->addUser(); + $uid2 = $this->addUser(); + $address = 'http://example.org'; + $this->addBookmark($uid, $address); + $this->addBookmark($uid2, $address); + $this->assertEquals(1, $this->bs->countOthers($address)); + } + + + + /** + * Test what countOther() returns when the address exists four + * times in the database. + * + * @return void + */ + public function testCountOthersThree() + { + $uid = $this->addUser(); + $address = 'http://example.org'; + $this->addBookmark($uid, $address); + $this->addBookmark(null, $address); + $this->addBookmark(null, $address); + $this->addBookmark(null, $address); + $this->assertEquals(3, $this->bs->countOthers($address)); + } + + + + /** + * Test what countOther() returns when the user is logged in + * and friends (people on the watchlist) have bookmarked + * and shared the same address. + * + * @return void + */ + public function testCountOthersWatchlist() + { + $uid = $this->addUser(); + $address = 'http://example.org'; + //log user in + $this->us->setCurrentUserId($uid); + + //setup users + $otherPublic1 = $this->addUser(); + $otherPublic2 = $this->addUser(); + $otherShared1 = $this->addUser(); + $otherPrivate1 = $this->addUser(); + $friendPublic1 = $this->addUser(); + $friendShared1 = $this->addUser(); + $friendShared2 = $this->addUser(); + $friendPrivate1 = $this->addUser(); + $friendSharing1 = $this->addUser(); + + //setup watchlists + $us = SemanticScuttle_Service_Factory::get('User'); + $this->us->setCurrentUserId($friendPublic1); + $us->setWatchStatus($uid); + $this->us->setCurrentUserId($friendShared1); + $us->setWatchStatus($uid); + $this->us->setCurrentUserId($friendShared2); + $us->setWatchStatus($uid); + $this->us->setCurrentUserId($friendPrivate1); + $us->setWatchStatus($uid); + + //back to login of main user + $this->us->setCurrentUserId($uid); + $us->setWatchStatus($friendSharing1); + + //add bookmarks + $this->addBookmark($uid, $address, 0); + $this->addBookmark($otherPublic1, $address, 0); + $this->addBookmark($otherPublic2, $address, 0); + $this->addBookmark($otherShared1, $address, 1); + $this->addBookmark($otherPrivate1, $address, 2); + $this->addBookmark($friendPublic1, $address, 0); + $this->addBookmark($friendShared1, $address, 1); + $this->addBookmark($friendShared2, $address, 1); + $this->addBookmark($friendPrivate1, $address, 2); + //this user is on our watchlist, but we not on his + $this->addBookmark($friendSharing1, $address, 1); + + //2 public + //1 public (friend) + //2 shared + //-> 5 + $this->assertEquals(5, $this->bs->countOthers($address)); + } + + + } -- cgit v1.2.3-54-g00ecf From e0dff57cbb4d2093ef58b3da7654d1305beb043f Mon Sep 17 00:00:00 2001 From: cweiske Date: Wed, 17 Mar 2010 20:04:47 +0000 Subject: remove part of broken merge :/ git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@686 b3834d28-1941-0410-a4f8-b48e95affb8f --- tests/BookmarkTest.php | 165 ------------------------------------------------- 1 file changed, 165 deletions(-) (limited to 'tests/BookmarkTest.php') diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index 0b4f01d..74685c4 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -1179,171 +1179,6 @@ class BookmarkTest extends TestBase - - - /** - * Test what countOther() returns when the address does not exist - * - * @return void - */ - public function testCountOthersAddressDoesNotExist() - { - $this->assertEquals(0, $this->bs->countOthers('http://example.org')); - } - - - - /** - * Test what countOther() returns when nobody else has the same bookmark - * - * @return void - */ - public function testCountOthersNone() - { - $uid = $this->addUser(); - $address = 'http://example.org'; - $this->addBookmark($uid, $address); - $this->assertEquals(0, $this->bs->countOthers($address)); - } - - - - /** - * Test what countOther() returns when the address exists only once - * and multiple bookmarks are in the database. - * - * @return void - */ - public function testCountOthersMultipleNone() - { - $uid = $this->addUser(); - $address = 'http://example.org'; - $this->addBookmark($uid, $address); - $this->addBookmark($uid); - $this->addBookmark($uid); - $this->assertEquals(0, $this->bs->countOthers($address)); - } - - - - /** - * Test what countOther() returns when the address exists only once - * and the same user and other users have other bookmarks - * - * @return void - */ - public function testCountOthersMultipleUsersNone() - { - $uid = $this->addUser(); - $uid2 = $this->addUser(); - $address = 'http://example.org'; - $this->addBookmark($uid, $address); - $this->addBookmark($uid); - $this->addBookmark($uid2); - $this->assertEquals(0, $this->bs->countOthers($address)); - } - - - - /** - * Test what countOther() returns when the address exists two - * times in the database. - * - * @return void - */ - public function testCountOthersOne() - { - $uid = $this->addUser(); - $uid2 = $this->addUser(); - $address = 'http://example.org'; - $this->addBookmark($uid, $address); - $this->addBookmark($uid2, $address); - $this->assertEquals(1, $this->bs->countOthers($address)); - } - - - - /** - * Test what countOther() returns when the address exists four - * times in the database. - * - * @return void - */ - public function testCountOthersThree() - { - $uid = $this->addUser(); - $address = 'http://example.org'; - $this->addBookmark($uid, $address); - $this->addBookmark(null, $address); - $this->addBookmark(null, $address); - $this->addBookmark(null, $address); - $this->assertEquals(3, $this->bs->countOthers($address)); - } - - - - /** - * Test what countOther() returns when the user is logged in - * and friends (people on the watchlist) have bookmarked - * and shared the same address. - * - * @return void - */ - public function testCountOthersWatchlist() - { - $uid = $this->addUser(); - $address = 'http://example.org'; - //log user in - $this->us->setCurrentUserId($uid); - - //setup users - $otherPublic1 = $this->addUser(); - $otherPublic2 = $this->addUser(); - $otherShared1 = $this->addUser(); - $otherPrivate1 = $this->addUser(); - $friendPublic1 = $this->addUser(); - $friendShared1 = $this->addUser(); - $friendShared2 = $this->addUser(); - $friendPrivate1 = $this->addUser(); - $friendSharing1 = $this->addUser(); - - //setup watchlists - $us = SemanticScuttle_Service_Factory::get('User'); - $this->us->setCurrentUserId($friendPublic1); - $us->setWatchStatus($uid); - $this->us->setCurrentUserId($friendShared1); - $us->setWatchStatus($uid); - $this->us->setCurrentUserId($friendShared2); - $us->setWatchStatus($uid); - $this->us->setCurrentUserId($friendPrivate1); - $us->setWatchStatus($uid); - - //back to login of main user - $this->us->setCurrentUserId($uid); - $us->setWatchStatus($friendSharing1); - - //add bookmarks - $this->addBookmark($uid, $address, 0); - $this->addBookmark($otherPublic1, $address, 0); - $this->addBookmark($otherPublic2, $address, 0); - $this->addBookmark($otherShared1, $address, 1); - $this->addBookmark($otherPrivate1, $address, 2); - $this->addBookmark($friendPublic1, $address, 0); - $this->addBookmark($friendShared1, $address, 1); - $this->addBookmark($friendShared2, $address, 1); - $this->addBookmark($friendPrivate1, $address, 2); - //this user is on our watchlist, but we not on his - $this->addBookmark($friendSharing1, $address, 1); - - //2 public - //1 public (friend) - //2 shared - //-> 5 - $this->assertEquals(5, $this->bs->countOthers($address)); - } - - - } -- cgit v1.2.3-54-g00ecf From f9e0714350cbb8efdfeac632fe2211c6c59bdbae Mon Sep 17 00:00:00 2001 From: cweiske Date: Wed, 17 Mar 2010 20:05:43 +0000 Subject: write failing test for bug #2953732 git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@687 b3834d28-1941-0410-a4f8-b48e95affb8f --- tests/BookmarkTest.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/BookmarkTest.php') diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index 74685c4..7885876 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -859,6 +859,50 @@ class BookmarkTest extends TestBase + /** + * Tests if getBookmarkByAddress() works correctly. + * + * @return void + */ + public function testGetBookmarkByAddress() + { + $url = 'http://example.org'; + $uid = $this->addUser(); + $bid = $this->addBookmark($uid, $url); + + $bm = $this->bs->getBookmarkByAddress($url); + $this->assertType('array', $bm); + $this->assertEquals($url, $bm['bAddress']); + } + + + + /** + * Tests if getBookmarkByAddress() works correctly with aliases. + * When passing an incomplete address i.e. without protocol, + * the full URL needs to be searched for. + * + * The failure of this test lead to #2953732. + * + * @return void + * + * @link https://sourceforge.net/tracker/?func=detail&atid=1017430&aid=2953732&group_id=211356 + */ + public function testGetBookmarkByAddressAlias() + { + $url = 'http://example.org'; + $incomplete = 'example.org'; + + $uid = $this->addUser(); + $bid = $this->addBookmark($uid, $url); + + $bm = $this->bs->getBookmarkByAddress($incomplete); + $this->assertType('array', $bm); + $this->assertEquals($url, $bm['bAddress']); + } + + + public function testNormalize() { $this->assertEquals( -- cgit v1.2.3-54-g00ecf From a42a6eb2ba7aab80b50cf641d643a911e5f032ca Mon Sep 17 00:00:00 2001 From: cweiske Date: Thu, 18 Mar 2010 19:28:42 +0000 Subject: test for the failure we fixed one commit ago git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@694 b3834d28-1941-0410-a4f8-b48e95affb8f --- tests/BookmarkTest.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/BookmarkTest.php') diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index 7885876..40869b2 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -353,6 +353,10 @@ class BookmarkTest extends TestBase $bid2 = $this->addBookmark(); $bookmark2 = $this->bs->getBookmark($bid2); + //do not search for this one + $bid3 = $this->addBookmark(); + $bookmark3 = $this->bs->getBookmark($bid3); + $ret = $this->bs->bookmarksExist( array( -- cgit v1.2.3-54-g00ecf