2008-01-23 17:58:00 +01:00
|
|
|
<?php
|
2009-10-25 16:31:31 +01:00
|
|
|
/**
|
|
|
|
* SemanticScuttle - your social bookmark manager.
|
|
|
|
*
|
|
|
|
* PHP version 5.
|
|
|
|
*
|
|
|
|
* @category Bookmarking
|
|
|
|
* @package SemanticScuttle
|
2009-10-26 07:39:59 +01:00
|
|
|
* @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
|
2009-10-25 16:31:31 +01:00
|
|
|
* @author Christian Weiske <cweiske@cweiske.de>
|
2009-10-26 07:39:59 +01:00
|
|
|
* @author Eric Dane <ericdane@users.sourceforge.net>
|
2009-10-25 16:31:31 +01:00
|
|
|
* @license GPL http://www.gnu.org/licenses/gpl.html
|
|
|
|
* @link http://sourceforge.net/projects/semanticscuttle
|
2008-12-18 11:59:43 +01:00
|
|
|
*/
|
2008-01-23 17:58:00 +01:00
|
|
|
|
2009-10-25 16:31:31 +01:00
|
|
|
require_once 'prepare.php';
|
|
|
|
|
|
|
|
if (!defined('PHPUnit_MAIN_METHOD')) {
|
|
|
|
define('PHPUnit_MAIN_METHOD', 'BookmarkTest::main');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for the SemanticScuttle bookmark service.
|
|
|
|
*
|
|
|
|
* @category Bookmarking
|
|
|
|
* @package SemanticScuttle
|
2009-10-26 07:39:59 +01:00
|
|
|
* @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
|
|
|
|
* @author Christian Weiske <cweiske@cweiske.de>
|
|
|
|
* @author Eric Dane <ericdane@users.sourceforge.net>
|
2009-10-25 16:31:31 +01:00
|
|
|
* @license GPL http://www.gnu.org/licenses/gpl.html
|
|
|
|
* @link http://sourceforge.net/projects/semanticscuttle
|
|
|
|
*/
|
|
|
|
class BookmarkTest extends TestBase
|
2008-01-23 17:58:00 +01:00
|
|
|
{
|
2009-10-25 20:32:48 +01:00
|
|
|
protected $us;
|
|
|
|
protected $bs;
|
|
|
|
protected $ts;
|
|
|
|
protected $tts;
|
2008-01-23 17:58:00 +01:00
|
|
|
|
2009-10-25 16:31:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to run this test class standalone
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function main()
|
|
|
|
{
|
|
|
|
require_once 'PHPUnit/TextUI/TestRunner.php';
|
|
|
|
PHPUnit_TextUI_TestRunner::run(
|
|
|
|
new PHPUnit_Framework_TestSuite(__CLASS__)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-25 20:32:48 +01:00
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
$this->us = SemanticScuttle_Service_Factory::get('User');
|
|
|
|
$this->bs = SemanticScuttle_Service_Factory::get('Bookmark');
|
|
|
|
$this->bs->deleteAll();
|
|
|
|
$this->b2ts= SemanticScuttle_Service_Factory::get('Bookmark2Tag');
|
|
|
|
$this->b2ts->deleteAll();
|
|
|
|
$this->tts = SemanticScuttle_Service_Factory::get('Tag2Tag');
|
|
|
|
$this->tts->deleteAll();
|
|
|
|
$this->tsts = SemanticScuttle_Service_Factory::get('TagStat');
|
|
|
|
$this->tsts->deleteAll();
|
|
|
|
$this->vs = SemanticScuttle_Service_Factory::get('Vote');
|
|
|
|
$this->vs->deleteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testHardCharactersInBookmarks()
|
|
|
|
{
|
|
|
|
$bs = $this->bs;
|
|
|
|
$title = "title&é\"'(-è_çà)=";
|
|
|
|
$desc = "description#{[|`\^@]}³<> ¹¡÷׿&é\"'(-è\\_çà)=";
|
|
|
|
$tag1 = "#{|`^@]³¹¡¿<&é\"'(-è\\_çà)";
|
|
|
|
$tag2 = "&é\"'(-è.[?./§!_çà)";
|
|
|
|
|
2009-10-28 23:32:15 +01:00
|
|
|
$uid = $this->addUser();
|
|
|
|
$bid = $bs->addBookmark(
|
2009-10-25 20:28:23 +01:00
|
|
|
'http://site1.com', $title, $desc, 'note',
|
|
|
|
0, array($tag1, $tag2),
|
2009-10-28 23:32:15 +01:00
|
|
|
null, false, false, $uid
|
2009-10-25 20:28:23 +01:00
|
|
|
);
|
2008-02-19 14:51:18 +01:00
|
|
|
|
2009-10-25 20:32:48 +01:00
|
|
|
$bookmarks = $bs->getBookmarks(0, 1);
|
2008-01-23 17:58:00 +01:00
|
|
|
|
2009-10-25 20:32:48 +01:00
|
|
|
$b0 = $bookmarks['bookmarks'][0];
|
|
|
|
$this->assertEquals($title, $b0['bTitle']);
|
|
|
|
$this->assertEquals($desc, $b0['bDescription']);
|
|
|
|
$this->assertEquals(
|
|
|
|
str_replace(array('"', '\'', '/'), "_", $tag1),
|
2009-10-25 20:28:23 +01:00
|
|
|
$b0['tags'][0]
|
|
|
|
);
|
2009-10-25 20:32:48 +01:00
|
|
|
$this->assertEquals(
|
2009-10-25 20:28:23 +01:00
|
|
|
str_replace(array('"', '\'', '/'), "_", $tag2),
|
|
|
|
$b0['tags'][1]
|
|
|
|
);
|
2009-10-25 20:32:48 +01:00
|
|
|
}
|
2008-01-23 17:58:00 +01:00
|
|
|
|
2009-10-25 20:32:48 +01:00
|
|
|
public function testUnificationOfBookmarks()
|
|
|
|
{
|
|
|
|
$bs = $this->bs;
|
2008-01-23 18:13:45 +01:00
|
|
|
|
2009-10-28 23:33:36 +01:00
|
|
|
$uid = $this->addUser();
|
|
|
|
$uid2 = $this->addUser();
|
|
|
|
|
2009-10-25 20:32:48 +01:00
|
|
|
$bs->addBookmark(
|
2009-10-25 20:28:23 +01:00
|
|
|
'http://site1.com', "title", "description", 'note',
|
|
|
|
0, array('tag1'), null, false, false,
|
2009-10-28 23:33:36 +01:00
|
|
|
$uid
|
2009-10-25 20:28:23 +01:00
|
|
|
);
|
2009-10-25 20:32:48 +01:00
|
|
|
$bs->addBookmark(
|
2009-10-25 20:28:23 +01:00
|
|
|
"http://site1.com", "title2", "description2", 'note',
|
|
|
|
0, array('tag2'), null, false, false,
|
2009-10-28 23:33:36 +01:00
|
|
|
$uid2
|
2009-10-25 20:28:23 +01:00
|
|
|
);
|
2008-02-19 09:07:23 +01:00
|
|
|
|
2009-10-25 20:32:48 +01:00
|
|
|
$bookmarks = $bs->getBookmarks();
|
|
|
|
$this->assertEquals(1, $bookmarks['total']);
|
|
|
|
}
|
2008-12-18 11:59:43 +01:00
|
|
|
|
2009-10-25 20:32:48 +01:00
|
|
|
/*public function testSearchingBookmarksAccentsInsensible()
|
|
|
|
{
|
|
|
|
$bs = $this->bs;
|
2008-12-18 11:59:43 +01:00
|
|
|
|
2009-10-25 20:32:48 +01:00
|
|
|
$bs->addBookmark("http://site1.com", "title", "éèüaàê", "status", array('tag1'), null, false, false, 1);
|
|
|
|
$bookmarks =& $bs->getBookmarks(0, NULL, NULL, NULL, $terms = "eeaae"); //void
|
|
|
|
$this->assertEquals(0, $bookmarks['total']);
|
|
|
|
$bookmarks =& $bs->getBookmarks(0, NULL, NULL, NULL, $terms = "eeuaae");
|
|
|
|
$this->assertEquals(1, $bookmarks['total']);
|
|
|
|
}*/
|
2008-02-19 09:07:23 +01:00
|
|
|
|
2009-10-25 16:31:31 +01:00
|
|
|
|
|
|
|
|
2009-10-31 11:19:38 +01:00
|
|
|
/**
|
|
|
|
* Test if countBookmarks() works with no bookmarks
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCountBookmarksNone()
|
|
|
|
{
|
|
|
|
$uid = $this->addUser();
|
|
|
|
$this->assertEquals(0, $this->bs->countBookmarks($uid));
|
|
|
|
$this->assertEquals(0, $this->bs->countBookmarks($uid, 'public'));
|
|
|
|
$this->assertEquals(0, $this->bs->countBookmarks($uid, 'private'));
|
|
|
|
$this->assertEquals(0, $this->bs->countBookmarks($uid, 'shared'));
|
2009-11-19 20:20:48 +01:00
|
|
|
$this->assertEquals(0, $this->bs->countBookmarks($uid, 'all'));
|
2009-10-31 11:19:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if countBookmarks() works with one public bookmark
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCountBookmarksOnePublic()
|
|
|
|
{
|
|
|
|
$uid = $this->addUser();
|
|
|
|
$this->addBookmark($uid);
|
|
|
|
$this->assertEquals(1, $this->bs->countBookmarks($uid));
|
|
|
|
$this->assertEquals(1, $this->bs->countBookmarks($uid, 'public'));
|
|
|
|
$this->assertEquals(0, $this->bs->countBookmarks($uid, 'private'));
|
|
|
|
$this->assertEquals(0, $this->bs->countBookmarks($uid, 'shared'));
|
2009-11-19 20:20:48 +01:00
|
|
|
$this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));
|
2009-10-31 11:19:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if countBookmarks() works with one private bookmark
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCountBookmarksOnePrivate()
|
|
|
|
{
|
|
|
|
$uid = $this->addUser();
|
|
|
|
$this->bs->addBookmark(
|
|
|
|
'http://test', 'test', 'desc', 'note',
|
|
|
|
2,//private
|
|
|
|
array(), null, false, false, $uid
|
|
|
|
);
|
|
|
|
$this->assertEquals(0, $this->bs->countBookmarks($uid));
|
|
|
|
$this->assertEquals(0, $this->bs->countBookmarks($uid, 'public'));
|
|
|
|
$this->assertEquals(1, $this->bs->countBookmarks($uid, 'private'));
|
|
|
|
$this->assertEquals(0, $this->bs->countBookmarks($uid, 'shared'));
|
2009-11-19 20:20:48 +01:00
|
|
|
$this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));
|
2009-10-31 11:19:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if countBookmarks() works with one shared bookmark
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCountBookmarksOneShared()
|
|
|
|
{
|
|
|
|
$uid = $this->addUser();
|
|
|
|
$this->bs->addBookmark(
|
|
|
|
'http://test', 'test', 'desc', 'note',
|
|
|
|
1,//shared
|
|
|
|
array(), null, false, false, $uid
|
|
|
|
);
|
|
|
|
$this->assertEquals(0, $this->bs->countBookmarks($uid));
|
|
|
|
$this->assertEquals(0, $this->bs->countBookmarks($uid, 'public'));
|
|
|
|
$this->assertEquals(0, $this->bs->countBookmarks($uid, 'private'));
|
|
|
|
$this->assertEquals(1, $this->bs->countBookmarks($uid, 'shared'));
|
2009-11-19 20:20:48 +01:00
|
|
|
$this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));
|
2009-10-31 11:19:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-25 20:32:48 +01:00
|
|
|
/**
|
|
|
|
* Test if deleting a bookmark works.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2009-10-25 16:31:31 +01:00
|
|
|
public function testDeleteBookmark()
|
|
|
|
{
|
2009-10-25 20:32:48 +01:00
|
|
|
$bookmarks = $this->bs->getBookmarks();
|
|
|
|
$this->assertEquals(0, $bookmarks['total']);
|
|
|
|
|
|
|
|
$bid = $this->addBookmark();
|
|
|
|
$bookmarks = $this->bs->getBookmarks();
|
|
|
|
$this->assertEquals(1, $bookmarks['total']);
|
|
|
|
|
|
|
|
$bid2 = $this->addBookmark();
|
|
|
|
$bookmarks = $this->bs->getBookmarks();
|
|
|
|
$this->assertEquals(2, $bookmarks['total']);
|
|
|
|
|
|
|
|
$this->assertTrue($this->bs->deleteBookmark($bid));
|
|
|
|
$bookmarks = $this->bs->getBookmarks();
|
|
|
|
$this->assertEquals(1, $bookmarks['total']);
|
|
|
|
|
|
|
|
$this->assertTrue($this->bs->deleteBookmark($bid2));
|
|
|
|
$bookmarks = $this->bs->getBookmarks();
|
|
|
|
$this->assertEquals(0, $bookmarks['total']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if deleting a bookmark with a vote works.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDeleteBookmarkWithVote()
|
|
|
|
{
|
2009-10-31 11:19:38 +01:00
|
|
|
$GLOBALS['enableVoting'] = true;
|
|
|
|
|
2009-10-25 20:32:48 +01:00
|
|
|
$uid = $this->addUser();
|
|
|
|
$bid = $this->addBookmark();
|
|
|
|
|
|
|
|
$bid = $this->addBookmark();
|
|
|
|
$this->vs->vote($bid, $uid, 1);
|
|
|
|
$this->assertTrue($this->vs->hasVoted($bid, $uid));
|
|
|
|
|
|
|
|
$bid2 = $this->addBookmark();
|
|
|
|
$this->vs->vote($bid2, $uid, 1);
|
|
|
|
$this->assertTrue($this->vs->hasVoted($bid2, $uid));
|
|
|
|
|
|
|
|
$this->assertTrue($this->bs->deleteBookmark($bid));
|
|
|
|
$this->assertFalse($this->vs->hasVoted($bid, $uid));
|
|
|
|
$this->assertTrue($this->vs->hasVoted($bid2, $uid));
|
2009-10-25 16:31:31 +01:00
|
|
|
}
|
|
|
|
|
2009-10-28 23:16:37 +01:00
|
|
|
|
|
|
|
|
2009-11-19 20:20:48 +01:00
|
|
|
/**
|
|
|
|
* Verify that getBookmark() returns false when the
|
|
|
|
* bookmark cannot be found.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetBookmarkNotFound()
|
|
|
|
{
|
|
|
|
$this->assertFalse($this->bs->getBookmark(987654));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify that getBookmark() returns false when the
|
|
|
|
* bookmark ID is not numeric
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetBookmarkInvalidParam()
|
|
|
|
{
|
|
|
|
$this->assertFalse($this->bs->getBookmark('foo'));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check tag loading functionality of getBookmark()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetBookmarkIncludeTags()
|
|
|
|
{
|
|
|
|
$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'));
|
|
|
|
|
|
|
|
$bm = $this->bs->getBookmark($bid, true);
|
|
|
|
$this->assertArrayHasKey('tags', $bm);
|
|
|
|
$this->assertType('array', $bm['tags']);
|
|
|
|
$this->assertContains('foo', $bm['tags']);
|
|
|
|
$this->assertContains('bar', $bm['tags']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-28 23:16:37 +01:00
|
|
|
/**
|
|
|
|
* Verify that getBookmark() does not include user voting
|
|
|
|
* data when no user is logged on.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetBookmarkUserVotingNoUser()
|
|
|
|
{
|
2009-10-31 11:19:38 +01:00
|
|
|
$GLOBALS['enableVoting'] = true;
|
|
|
|
|
2009-10-28 23:16:37 +01:00
|
|
|
$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()
|
|
|
|
{
|
2009-10-31 11:19:38 +01:00
|
|
|
$GLOBALS['enableVoting'] = true;
|
|
|
|
|
2009-10-28 23:16:37 +01:00
|
|
|
$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()
|
|
|
|
{
|
2009-10-31 11:19:38 +01:00
|
|
|
$GLOBALS['enableVoting'] = true;
|
|
|
|
|
2009-10-28 23:16:37 +01:00
|
|
|
$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()
|
|
|
|
{
|
2009-10-31 11:19:38 +01:00
|
|
|
$GLOBALS['enableVoting'] = true;
|
|
|
|
|
2009-10-28 23:16:37 +01:00
|
|
|
$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']);
|
|
|
|
}
|
|
|
|
|
2009-10-25 16:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (PHPUnit_MAIN_METHOD == 'BookmarkTest::main') {
|
|
|
|
BookmarkTest::main();
|
2008-01-23 17:58:00 +01:00
|
|
|
}
|
|
|
|
?>
|