From 80464e45e84ee7b7b3bb6217adb3649132d43708 Mon Sep 17 00:00:00 2001 From: cweiske Date: Wed, 28 Oct 2009 22:16:37 +0000 Subject: test previously fixed bug: voting was updated for all bookmarks, not only the current one git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@449 b3834d28-1941-0410-a4f8-b48e95affb8f --- tests/BookmarkTest.php | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'tests/BookmarkTest.php') diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index 1224dfe..e5cf760 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -182,6 +182,97 @@ class BookmarkTest extends TestBase $this->assertTrue($this->vs->hasVoted($bid2, $uid)); } + + + /** + * Verify that getBookmark() does not include user voting + * data when no user is logged on. + * + * @return void + */ + public function testGetBookmarkUserVotingNoUser() + { + $uid = $this->addUser(); + $bid = $this->addBookmark($uid); + //no user + $this->us->setCurrentUserId(null); + + $bm = $this->bs->getBookmark($bid); + $this->assertArrayNotHasKey('hasVoted', $bm); + $this->assertArrayNotHasKey('vote', $bm); + } + + + + /** + * Verify that getBookmark() automatically includes + * voting data of the currently logged on user, + * even if he did not vote yet. + * + * @return void + */ + public function testGetBookmarkUserVotingWithUserNoVote() + { + $uid = $this->addUser(); + $bid = $this->addBookmark($uid); + //log user in + $this->us->setCurrentUserId($uid); + + $bm = $this->bs->getBookmark($bid); + $this->assertArrayHasKey('hasVoted', $bm); + $this->assertArrayHasKey('vote', $bm); + $this->assertEquals(0, $bm['hasVoted']); + $this->assertEquals(null, $bm['vote']); + } + + + + /** + * Verify that getBookmark() automatically includes + * voting data of the currently logged on user + * when he voted positive. + * + * @return void + */ + public function testGetBookmarkUserVotingWithUserPositiveVote() + { + $uid = $this->addUser(); + $bid = $this->addBookmark($uid); + //log user in + $this->us->setCurrentUserId($uid); + $this->assertTrue($this->vs->vote($bid, $uid, 1)); + + $bm = $this->bs->getBookmark($bid); + $this->assertArrayHasKey('hasVoted', $bm); + $this->assertArrayHasKey('vote', $bm); + $this->assertEquals(1, $bm['hasVoted']); + $this->assertEquals(1, $bm['vote']); + } + + + + /** + * Verify that getBookmark() automatically includes + * voting data of the currently logged on user + * when he voted positive. + * + * @return void + */ + public function testGetBookmarkUserVotingWithUserNegativeVote() + { + $uid = $this->addUser(); + $bid = $this->addBookmark($uid); + //log user in + $this->us->setCurrentUserId($uid); + $this->assertTrue($this->vs->vote($bid, $uid, -1)); + + $bm = $this->bs->getBookmark($bid); + $this->assertArrayHasKey('hasVoted', $bm); + $this->assertArrayHasKey('vote', $bm); + $this->assertEquals(1, $bm['hasVoted']); + $this->assertEquals(-1, $bm['vote']); + } + } -- cgit v1.2.3-54-g00ecf