From 65bd4bfab86fc47be3ce125640ebd49163f24f4b Mon Sep 17 00:00:00 2001
From: bretticvs
Date: Tue, 15 Mar 2011 07:53:39 +0100
Subject: Updates for feature request 3164348: Make default privacy
configurable.
---
data/config.default.php | 17 +++++++++++++++++
data/config.php.dist | 22 ++++++++++++++++++++++
data/templates/bookmarks.tpl.php | 2 +-
tests/BookmarkTest.php | 24 ++++++++++++++++++++++++
www/api/posts_add.php | 2 +-
www/bookmarks.php | 4 ++--
www/edit.php | 2 +-
www/import.php | 4 ++--
www/importNetscape.php | 4 ++--
9 files changed, 72 insertions(+), 9 deletions(-)
diff --git a/data/config.default.php b/data/config.default.php
index bd67c7b..cd611f1 100644
--- a/data/config.default.php
+++ b/data/config.default.php
@@ -14,6 +14,13 @@
* @link http://sourceforge.net/projects/semanticscuttle/
*/
+/**
+ * Array for defaults.
+ *
+ * @var array
+ */
+$defaults = array();
+
/***************************************************
* HTML output configuration
@@ -493,6 +500,16 @@ $votingMode = 2;
*/
$hideBelowVoting = null;
+/**
+ * Default privacy setting for bookmarks:
+ * 0 - Public
+ * 1 - Shared with Watchlist
+ * 2 - Private
+ *
+ * @var integer
+ */
+$defaults['privacy'] = 0;
+
/****************************
* Website Thumbnails
diff --git a/data/config.php.dist b/data/config.php.dist
index c135e8e..0f849e2 100644
--- a/data/config.php.dist
+++ b/data/config.php.dist
@@ -7,6 +7,13 @@
* See config.default.inc.php for more options.
*/
+/**
+ * Array for defaults.
+ *
+ * @var array
+ */
+$defaults = array();
+
/**
* The name of this site.
*
@@ -116,6 +123,21 @@ $adminemail = 'admin@example.org';
$admin_users = array();
+/***************************************************
+ * Bookmarks
+ */
+
+/**
+ * Default privacy setting for bookmarks.
+ * 0 - Public
+ * 1 - Shared with Watchlist
+ * 2 - Private
+ *
+ * @var integer
+ */
+$defaults['privacy'] = 0;
+
+
/**
* You have completed the basic configuration!
* More options can be found in config.default.php.
diff --git a/data/templates/bookmarks.tpl.php b/data/templates/bookmarks.tpl.php
index e32d3c9..44dfe90 100644
--- a/data/templates/bookmarks.tpl.php
+++ b/data/templates/bookmarks.tpl.php
@@ -256,7 +256,7 @@ if ($currenttag!= '') {
foreach ($bookmarks as $key => &$row) {
switch ($row['bStatus']) {
case 0:
- $access = '';
+ $access = ' public';
break;
case 1:
$access = ' shared';
diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php
index f54fe9a..aa0b8c3 100644
--- a/tests/BookmarkTest.php
+++ b/tests/BookmarkTest.php
@@ -1343,6 +1343,30 @@ class BookmarkTest extends TestBase
}
+ /**
+ * Test that the default privacy setting in
+ * $GLOBALS['defaults']['privacy'] is used
+ * as expected.
+ *
+ * @return void
+ */
+ public function testDefaultPrivacy()
+ {
+ $GLOBALS['defaults']['privacy'] = 1;
+ $uid = $this->addUser();
+ $this->us->setCurrentUserId($uid);
+ $bid = $this->bs->addBookmark('http://www.somedomain.com', 'mybookmark1', 'descr1', 'privatenote1', $GLOBALS['defaults']['privacy'], array());
+ $bm = $this->bs->getBookmark($bid);
+ $this->assertEquals('1', $bm['bStatus']);
+ $GLOBALS['defaults']['privacy'] = 2;
+ $uid = $this->addUser();
+ $this->us->setCurrentUserId($uid);
+ $bid = $this->bs->addBookmark('http://www.anotherdomain.com', 'mybookmark2', 'descr2', 'privatenote2', $GLOBALS['defaults']['privacy'], array());
+ $bm = $this->bs->getBookmark($bid);
+ $this->assertEquals('2', $bm['bStatus']);
+ }//end function testDefaultPrivacy
+
+
}
diff --git a/www/api/posts_add.php b/www/api/posts_add.php
index 7f9dc59..80d6515 100644
--- a/www/api/posts_add.php
+++ b/www/api/posts_add.php
@@ -81,7 +81,7 @@ if (isset($_REQUEST['dt']) && (trim($_REQUEST['dt']) != '')) {
$replace = isset($_REQUEST['replace']) && ($_REQUEST['replace'] == 'yes');
-$status = 0;
+$status = $GLOBALS['defaults']['privacy'];
if (isset($_REQUEST['status'])) {
$status_str = trim($_REQUEST['status']);
if (is_numeric($status_str)) {
diff --git a/www/bookmarks.php b/www/bookmarks.php
index 5241481..d4fe051 100644
--- a/www/bookmarks.php
+++ b/www/bookmarks.php
@@ -185,7 +185,7 @@ if ($templatename == 'editbookmark.tpl') {
'bDescription' => stripslashes(POST_DESCRIPTION),
'bPrivateNote' => stripslashes(POST_PRIVATENOTE),
'tags' => (POST_TAGS ? explode(',', stripslashes(POST_TAGS)) : array()),
- 'bStatus' => 0,
+ 'bStatus' => $GLOBALS['defaults']['privacy'],
);
$tplVars['tags'] = POST_TAGS;
} else {
@@ -201,7 +201,7 @@ if ($templatename == 'editbookmark.tpl') {
'bDescription' => stripslashes(GET_DESCRIPTION),
'bPrivateNote' => stripslashes(GET_PRIVATENOTE),
'tags' => (GET_TAGS ? explode(',', stripslashes(GET_TAGS)) : array()),
- 'bStatus' => 0
+ 'bStatus' => $GLOBALS['defaults']['privacy']
);
}
diff --git a/www/edit.php b/www/edit.php
index fbea163..cbfa30b 100644
--- a/www/edit.php
+++ b/www/edit.php
@@ -33,7 +33,7 @@ isset($_POST['title']) ? define('POST_TITLE', $_POST['title']): define('POST_TIT
isset($_POST['address']) ? define('POST_ADDRESS', $_POST['address']): define('POST_ADDRESS', '');
isset($_POST['description']) ? define('POST_DESCRIPTION', $_POST['description']): define('POST_DESCRIPTION', '');
isset($_POST['privateNote']) ? define('POST_PRIVATENOTE', $_POST['privateNote']): define('POST_PRIVATENOTE', '');
-isset($_POST['status']) ? define('POST_STATUS', $_POST['status']): define('POST_STATUS', '');
+isset($_POST['status']) ? define('POST_STATUS', $_POST['status']): define('POST_STATUS', $GLOBALS['defaults']['privacy']);
isset($_POST['tags']) ? define('POST_TAGS', $_POST['tags']): define('POST_TAGS', '');
isset($_GET['popup']) ? define('GET_POPUP', $_GET['popup']): define('GET_POPUP', '');
diff --git a/www/import.php b/www/import.php
index 5263aba..3aa2714 100644
--- a/www/import.php
+++ b/www/import.php
@@ -27,7 +27,7 @@ require_once 'www-header.php';
/* Managing all possible inputs */
// First input is $_FILES
// Other inputs
-isset($_POST['status']) ? define('POST_STATUS', $_POST['status']): define('POST_STATUS', '');
+isset($_POST['status']) ? define('POST_STATUS', $_POST['status']): define('POST_STATUS', $GLOBALS['defaults']['privacy']);
if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['size'] > 0) {
@@ -36,7 +36,7 @@ if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['si
if (is_numeric(POST_STATUS)) {
$status = intval(POST_STATUS);
} else {
- $status = 2;
+ $status = $GLOBALS['defaults']['privacy'];
}
$depth = array();
diff --git a/www/importNetscape.php b/www/importNetscape.php
index e23c156..b476c40 100644
--- a/www/importNetscape.php
+++ b/www/importNetscape.php
@@ -28,7 +28,7 @@ $bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark');
/* Managing all possible inputs */
// First input is $_FILES
// Other inputs
-isset($_POST['status']) ? define('POST_STATUS', $_POST['status']): define('POST_STATUS', '');
+isset($_POST['status']) ? define('POST_STATUS', $_POST['status']): define('POST_STATUS', $GLOBALS['defaults']['privacy']);
$countImportedBookmarks = 0;
$tplVars['msg'] = '';
@@ -39,7 +39,7 @@ if ($userservice->isLoggedOn() && sizeof($_FILES) > 0 && $_FILES['userfile']['si
if (is_numeric(POST_STATUS)) {
$status = intval(POST_STATUS);
} else {
- $status = 2;
+ $status = $GLOBALS['defaults']['privacy'];
}
// File handle
--
cgit v1.2.3-54-g00ecf
From eaa62a6c450a05295618e98fc41ae1d4d7f720d0 Mon Sep 17 00:00:00 2001
From: bretticvs
Date: Wed, 30 Mar 2011 22:03:39 -0700
Subject: Adding directory and files for test data.
---
tests/data/BookmarkTest_deliciousbookmarks.xml | 7 +++++++
tests/data/BookmarkTest_netscapebookmarks.html | 27 ++++++++++++++++++++++++++
2 files changed, 34 insertions(+)
create mode 100755 tests/data/BookmarkTest_deliciousbookmarks.xml
create mode 100755 tests/data/BookmarkTest_netscapebookmarks.html
diff --git a/tests/data/BookmarkTest_deliciousbookmarks.xml b/tests/data/BookmarkTest_deliciousbookmarks.xml
new file mode 100755
index 0000000..1c12110
--- /dev/null
+++ b/tests/data/BookmarkTest_deliciousbookmarks.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/tests/data/BookmarkTest_netscapebookmarks.html b/tests/data/BookmarkTest_netscapebookmarks.html
new file mode 100755
index 0000000..3e1bd7d
--- /dev/null
+++ b/tests/data/BookmarkTest_netscapebookmarks.html
@@ -0,0 +1,27 @@
+
+
+
+
+
Bookmarks for dpuser
+
+Bookmarks for dpuser
+
+
+
+
+
- Test bookmark 3 for default privacy.
+
- Test bookmark 4 for default privacy.
+
- Test bookmark 5 for default privacy.
+
- This bookmark will be ignored by importNetscape.php.
+
+
+
+
+
+
+
+
--
cgit v1.2.3-54-g00ecf
From ef88147d453bce7d5b86ec43daad2f54447513c8 Mon Sep 17 00:00:00 2001
From: bretticvs
Date: Wed, 30 Mar 2011 22:30:43 -0700
Subject: Further updates for configurable-privacy2.
---
data/config.php.dist | 283 ++--
data/templates/bookmarks.tpl.php | 878 ++++++------
tests/BookmarkTest.php | 2829 +++++++++++++++++++-------------------
3 files changed, 2029 insertions(+), 1961 deletions(-)
diff --git a/data/config.php.dist b/data/config.php.dist
index 0f849e2..a8d84a6 100644
--- a/data/config.php.dist
+++ b/data/config.php.dist
@@ -1,145 +1,138 @@
-
- * $admin_users = array('adminnickname', 'user1nick', 'user2nick');
- *
- *
- * @var array
- */
-$admin_users = array();
-
-
-/***************************************************
- * Bookmarks
- */
-
-/**
- * Default privacy setting for bookmarks.
- * 0 - Public
- * 1 - Shared with Watchlist
- * 2 - Private
- *
- * @var integer
- */
-$defaults['privacy'] = 0;
-
-
-/**
-* You have completed the basic configuration!
-* More options can be found in config.default.php.
-*/
-?>
+
+ * $admin_users = array('adminnickname', 'user1nick', 'user2nick');
+ *
+ *
+ * @var array
+ */
+$admin_users = array();
+
+
+/***************************************************
+ * Bookmarks
+ */
+
+/**
+ * Default privacy setting for bookmarks.
+ * 0 - Public
+ * 1 - Shared with Watchlist
+ * 2 - Private
+ *
+ * @var integer
+ */
+$defaults['privacy'] = 0;
+
+
+/**
+* You have completed the basic configuration!
+* More options can be found in config.default.php.
+*/
+?>
diff --git a/data/templates/bookmarks.tpl.php b/data/templates/bookmarks.tpl.php
index 44dfe90..b241a71 100644
--- a/data/templates/bookmarks.tpl.php
+++ b/data/templates/bookmarks.tpl.php
@@ -1,439 +1,439 @@
-
- * @author Christian Weiske
- * @author Eric Dane
- * @license GPL http://www.gnu.org/licenses/gpl.html
- * @link http://sourceforge.net/projects/semanticscuttle
- */
-
-/* Service creation: only useful services are created */
-$bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
-$tagservice = SemanticScuttle_Service_Factory::get('Tag');
-$cdservice = SemanticScuttle_Service_Factory::get('CommonDescription');
-
-
-$pageName = isset($pageName) ? $pageName : '';
-$user = isset($user) ? $user : '';
-$currenttag = isset($currenttag) ? $currenttag : '';
-
-
-$this->includeTemplate($GLOBALS['top_include']);
-
-include('search.menu.php');
-?>
-
-
-
-
-
-
-isAdmin($userid) && $pageName != PAGE_WATCHLIST) : ?>
-
-
-
-
-
-
-
-
-
-getLastTagDescription($currenttag)) {
- $cDescription = $cdservice->getLastTagDescription($currenttag);
- echo nl2br(filter($cDescription['cdDescription']));
-} elseif(isset($hash) && $cdservice->getLastBookmarkDescription($hash)) {
- $cDescription = $cdservice->getLastBookmarkDescription($hash);
- echo nl2br(filter($cDescription['cdTitle'])). "
";
- echo nl2br(filter($cDescription['cdDescription'])). "
";
-}
-
-//common tag description edit
-if($userservice->isLoggedOn()) {
- if($currenttag!= '' && ($GLOBALS['enableCommonTagDescriptionEditedByAll'] || $currentUser->isAdmin())) {
- echo ' ';
- echo !is_array($cDescription) || strlen($cDescription['cdDescription'])==0?T_('Edit the common description of this tag'):'';
- echo ' ';
- } elseif(isset($hash)) {
- echo ' (';
- echo T_('Edit the common description of this bookmark').')';
- }
-}
-?>
-
-
-
-getUserByUsername($user);
- if($tagservice->getDescription($currenttag, $userObject['uId'])) { ?>
-
-getDescription($currenttag, $userObject['uId']);
-echo nl2br(filter($pDescription['tDescription']));
-
-//personal tag description edit
-if($userservice->isLoggedOn()) {
- if($currenttag!= '') {
- echo ' ';
- echo strlen($pDescription['tDescription'])==0?T_('Edit your personal description of this tag'):'';
- echo ' ';
- }
-}
-?>
-
-
-
- 0) { ?>
-
-
- -
-
-
- /
-
- /
-
-
- /
-
-
-';
- echo T_('Bookmarks from other users for this tag').'';
- //echo T_(' for these tags');
- } else if ($userservice->isLoggedOn()){
- echo ' - ';
- echo '';
- echo T_('Only your bookmarks for this tag').'';
- //echo T_(' for these tags');
- }
-}
-?>
-
-'. T_('First') .'';
- $bprev = ''. T_('Previous') .'';
- } else {
- $prev = $page - 1;
- $prev = 'page='. $prev;
- $start = ($page - 1) * $perpage;
- $bfirst= ''. T_('First') .'';
- $bprev = ''. T_('Previous') .'';
- }
-
- // Next
- $next = $page + 1;
- $totalpages = ceil($total / $perpage);
- if (count($bookmarks) < $perpage || $perpage * $page == $total) {
- $bnext = ''. T_('Next') .'';
- $blast = ''. T_('Last') ."\n";
- } else {
- $bnext = ''. T_('Next') .'';
- $blast = ''. T_('Last') ."\n";
- }
-
- // RSS
- $brss = '';
- $size = count($rsschannels);
- for ($i = 0; $i < $size; $i++) {
- $brss = ''
- . ''
- . '';
- }
-
- $pagesBanner = ''. $bfirst .' / '. $bprev .' / '. $bnext .' / '. $blast .' / '. sprintf(T_('Page %d of %d'), $page, $totalpages) ." ". $brss ."
\n";
-
- if (getPerPageCount($currentUser) > 10) {
- echo $pagesBanner; // display a page banner if too many bookmarks to manage
- }
-
-
-?>
-
-
-
- 0 ? ' start="'. ++$start .'"' : ''); ?> id="bookmarks">
- &$row) {
- $addresses[$row['bId']] = $row['bAddress'];
- }
- $otherCounts = $bookmarkservice->countOthers($addresses);
- if ($userservice->isLoggedOn()) {
- $existence = $bookmarkservice->bookmarksExist(
- $addresses, $currentUser->getId()
- );
- }
-
- if ($userservice->isLoggedOn()) {
- $watchedNames = $userservice->getWatchNames(
- $currentUser->getId(), true
- );
- } else {
- $watchedNames = null;
- }
-
- foreach ($bookmarks as $key => &$row) {
- switch ($row['bStatus']) {
- case 0:
- $access = ' public';
- break;
- case 1:
- $access = ' shared';
- break;
- case 2:
- $access = ' private';
- break;
- }
-
- $cats = '';
- $tagsForCopy = '';
- $tags = $row['tags'];
- foreach ($tags as $tkey => &$tag) {
- $tagcaturl = sprintf(
- $cat_url,
- filter($row['username'], 'url'),
- filter($tag, 'url')
- );
- $cats .= sprintf(
- '%s, ',
- $tagcaturl, filter($tag)
- );
- $tagsForCopy .= $tag . ',';
- }
- $cats = substr($cats, 0, -2);
- if ($cats != '') {
- $cats = T_('Tags:') . ' ' . $cats;
- }
-
- // Edit and delete links
- $edit = '';
- if ($bookmarkservice->editAllowed($row)) {
- $edit = ' - '
- . T_('Edit')
- . ''
- . '';
- }
-
- // Last update
- $update = ' ('. date($GLOBALS['shortdate'], strtotime($row['bModified'])). ') ';
-
- // User attribution
- $copy = ' ' . T_('by') . ' ';
- if ($userservice->isLoggedOn()
- && $currentUser->getUsername() == $row['username']
- ) {
- $copy .= T_('you');
- } else {
- $copy .= ''
- . $row['username'] . '';
- }
-
- // Udders!
- if (!isset($hash)) {
- $others = $otherCounts[$row['bAddress']];
- $ostart = '';
- $oend = '';
- switch ($others) {
- case 0:
- break;
- case 1:
- $copy .= sprintf(T_(' and %s1 other%s'), $ostart, $oend);
- break;
- default:
- $copy .= sprintf(T_(' and %2$s%1$s others%3$s'), $others, $ostart, $oend);
- }
- }
-
- // Copy link
- if ($userservice->isLoggedOn()
- && ($currentUser->getId() != $row['uId'])
- && !$existence[$row['bAddress']]
- ) {
- $copy .= ' - '
- . T_('Copy')
- . '';
- }
-
- // Nofollow option
- $rel = '';
- if ($GLOBALS['nofollow']) {
- $rel = ' rel="nofollow"';
- }
-
- $address = filter($row['bAddress']);
- $oaddress = $address;
- // Redirection option
- if ($GLOBALS['useredir']) {
- $address = $GLOBALS['url_redir'] . $address;
- }
-
- // Admin specific design
- if ($userservice->isAdmin($row['username']) && $GLOBALS['enableAdminColors']) {
- $adminBgClass = ' class="adminBackground"';
- $adminStar = ' ';
- } else {
- $adminBgClass = '';
- $adminStar = '';
- }
-
- // Private Note (just visible by the owner and his/her contacts)
- if ($watchedNames !== null
- && ($currentUser->getId() == $row['uId']
- || in_array($row['username'], $watchedNames)
- )
- ) {
- $privateNoteField = $row['bPrivateNote'];
- } else {
- $privateNoteField = '';
- }
-
- if ($GLOBALS['enableVoting'] && $GLOBALS['hideBelowVoting'] !== null
- && $row['bVoting'] < $GLOBALS['hideBelowVoting']
- ) {
- $access .= ' below-threshold';
- }
-
- // Output
- echo ' - '."\n";
- include 'bookmarks-thumbnail.inc.tpl.php';
- include 'bookmarks-vote.inc.tpl.php';
-
- echo '
' . "\n";
-
- echo '
\n";
- if ($row['bDescription'] == '') {
- $bkDescription = $GLOBALS['blankDescription'];
- } else {
- // Improve description display (anchors, links, ...)
- $bkDescription = preg_replace('|\[\/.*?\]|', '', filter($row['bDescription'])); // remove final anchor
- $bkDescription = preg_replace('|\[(.*?)\]|', '
$1 » ', $bkDescription); // highlight starting anchor
- $bkDescription = preg_replace('@((http|https|ftp)://.*?)( |\r|$)@', '
$1$3', $bkDescription); // make url clickable
-
- }
- echo '
'. nl2br($bkDescription) ."
\n";
- echo '
' . shortenString($oaddress) . "
\n";
-
- echo '
'
- . $cats . "\n"
- . $copy . "\n"
- . $edit . "\n"
- . $update . "\n"
- . "
\n";
- echo $privateNoteField != ''
- ? '
'.$privateNoteField."
\n"
- : '';
- echo ' ';
- include 'bookmarks-vote-horizontal.inc.tpl.php';
- echo "
\n";
-
- echo " \n";
- }
- ?>
-
-
-
- 7) {
- echo ''.T_('Top of the page').'
';
- }
- echo $pagesBanner; // display previous and next links pages + RSS link
-
-
-} else {
- echo ''.T_('No bookmarks available').'
';
-}
-$this->includeTemplate('sidebar.tpl');
-$this->includeTemplate($GLOBALS['bottom_include']);
-?>
+
+ * @author Christian Weiske
+ * @author Eric Dane
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+
+/* Service creation: only useful services are created */
+$bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
+$tagservice = SemanticScuttle_Service_Factory::get('Tag');
+$cdservice = SemanticScuttle_Service_Factory::get('CommonDescription');
+
+
+$pageName = isset($pageName) ? $pageName : '';
+$user = isset($user) ? $user : '';
+$currenttag = isset($currenttag) ? $currenttag : '';
+
+
+$this->includeTemplate($GLOBALS['top_include']);
+
+include('search.menu.php');
+?>
+
+
+
+
+
+
+isAdmin($userid) && $pageName != PAGE_WATCHLIST) : ?>
+
+
+
+
+
+
+
+
+
+getLastTagDescription($currenttag)) {
+ $cDescription = $cdservice->getLastTagDescription($currenttag);
+ echo nl2br(filter($cDescription['cdDescription']));
+} elseif(isset($hash) && $cdservice->getLastBookmarkDescription($hash)) {
+ $cDescription = $cdservice->getLastBookmarkDescription($hash);
+ echo nl2br(filter($cDescription['cdTitle'])). "
";
+ echo nl2br(filter($cDescription['cdDescription'])). "
";
+}
+
+//common tag description edit
+if($userservice->isLoggedOn()) {
+ if($currenttag!= '' && ($GLOBALS['enableCommonTagDescriptionEditedByAll'] || $currentUser->isAdmin())) {
+ echo ' ';
+ echo !is_array($cDescription) || strlen($cDescription['cdDescription'])==0?T_('Edit the common description of this tag'):'';
+ echo ' ';
+ } elseif(isset($hash)) {
+ echo ' (';
+ echo T_('Edit the common description of this bookmark').')';
+ }
+}
+?>
+
+
+
+getUserByUsername($user);
+ if($tagservice->getDescription($currenttag, $userObject['uId'])) { ?>
+
+getDescription($currenttag, $userObject['uId']);
+echo nl2br(filter($pDescription['tDescription']));
+
+//personal tag description edit
+if($userservice->isLoggedOn()) {
+ if($currenttag!= '') {
+ echo ' ';
+ echo strlen($pDescription['tDescription'])==0?T_('Edit your personal description of this tag'):'';
+ echo ' ';
+ }
+}
+?>
+
+
+
+ 0) { ?>
+
+
+ -
+
+
+ /
+
+ /
+
+
+ /
+
+
+';
+ echo T_('Bookmarks from other users for this tag').'';
+ //echo T_(' for these tags');
+ } else if ($userservice->isLoggedOn()){
+ echo ' - ';
+ echo '';
+ echo T_('Only your bookmarks for this tag').'';
+ //echo T_(' for these tags');
+ }
+}
+?>
+
+'. T_('First') .'';
+ $bprev = ''. T_('Previous') .'';
+ } else {
+ $prev = $page - 1;
+ $prev = 'page='. $prev;
+ $start = ($page - 1) * $perpage;
+ $bfirst= ''. T_('First') .'';
+ $bprev = ''. T_('Previous') .'';
+ }
+
+ // Next
+ $next = $page + 1;
+ $totalpages = ceil($total / $perpage);
+ if (count($bookmarks) < $perpage || $perpage * $page == $total) {
+ $bnext = ''. T_('Next') .'';
+ $blast = ''. T_('Last') ."\n";
+ } else {
+ $bnext = ''. T_('Next') .'';
+ $blast = ''. T_('Last') ."\n";
+ }
+
+ // RSS
+ $brss = '';
+ $size = count($rsschannels);
+ for ($i = 0; $i < $size; $i++) {
+ $brss = ''
+ . ''
+ . '';
+ }
+
+ $pagesBanner = ''. $bfirst .' / '. $bprev .' / '. $bnext .' / '. $blast .' / '. sprintf(T_('Page %d of %d'), $page, $totalpages) ." ". $brss ."
\n";
+
+ if (getPerPageCount($currentUser) > 10) {
+ echo $pagesBanner; // display a page banner if too many bookmarks to manage
+ }
+
+
+?>
+
+
+
+ 0 ? ' start="'. ++$start .'"' : ''); ?> id="bookmarks">
+ &$row) {
+ $addresses[$row['bId']] = $row['bAddress'];
+ }
+ $otherCounts = $bookmarkservice->countOthers($addresses);
+ if ($userservice->isLoggedOn()) {
+ $existence = $bookmarkservice->bookmarksExist(
+ $addresses, $currentUser->getId()
+ );
+ }
+
+ if ($userservice->isLoggedOn()) {
+ $watchedNames = $userservice->getWatchNames(
+ $currentUser->getId(), true
+ );
+ } else {
+ $watchedNames = null;
+ }
+
+ foreach ($bookmarks as $key => &$row) {
+ switch ($row['bStatus']) {
+ case 0:
+ $access = '';
+ break;
+ case 1:
+ $access = ' shared';
+ break;
+ case 2:
+ $access = ' private';
+ break;
+ }
+
+ $cats = '';
+ $tagsForCopy = '';
+ $tags = $row['tags'];
+ foreach ($tags as $tkey => &$tag) {
+ $tagcaturl = sprintf(
+ $cat_url,
+ filter($row['username'], 'url'),
+ filter($tag, 'url')
+ );
+ $cats .= sprintf(
+ '%s, ',
+ $tagcaturl, filter($tag)
+ );
+ $tagsForCopy .= $tag . ',';
+ }
+ $cats = substr($cats, 0, -2);
+ if ($cats != '') {
+ $cats = T_('Tags:') . ' ' . $cats;
+ }
+
+ // Edit and delete links
+ $edit = '';
+ if ($bookmarkservice->editAllowed($row)) {
+ $edit = ' - '
+ . T_('Edit')
+ . ''
+ . '';
+ }
+
+ // Last update
+ $update = ' ('. date($GLOBALS['shortdate'], strtotime($row['bModified'])). ') ';
+
+ // User attribution
+ $copy = ' ' . T_('by') . ' ';
+ if ($userservice->isLoggedOn()
+ && $currentUser->getUsername() == $row['username']
+ ) {
+ $copy .= T_('you');
+ } else {
+ $copy .= ''
+ . $row['username'] . '';
+ }
+
+ // Udders!
+ if (!isset($hash)) {
+ $others = $otherCounts[$row['bAddress']];
+ $ostart = '';
+ $oend = '';
+ switch ($others) {
+ case 0:
+ break;
+ case 1:
+ $copy .= sprintf(T_(' and %s1 other%s'), $ostart, $oend);
+ break;
+ default:
+ $copy .= sprintf(T_(' and %2$s%1$s others%3$s'), $others, $ostart, $oend);
+ }
+ }
+
+ // Copy link
+ if ($userservice->isLoggedOn()
+ && ($currentUser->getId() != $row['uId'])
+ && !$existence[$row['bAddress']]
+ ) {
+ $copy .= ' - '
+ . T_('Copy')
+ . '';
+ }
+
+ // Nofollow option
+ $rel = '';
+ if ($GLOBALS['nofollow']) {
+ $rel = ' rel="nofollow"';
+ }
+
+ $address = filter($row['bAddress']);
+ $oaddress = $address;
+ // Redirection option
+ if ($GLOBALS['useredir']) {
+ $address = $GLOBALS['url_redir'] . $address;
+ }
+
+ // Admin specific design
+ if ($userservice->isAdmin($row['username']) && $GLOBALS['enableAdminColors']) {
+ $adminBgClass = ' class="adminBackground"';
+ $adminStar = ' ';
+ } else {
+ $adminBgClass = '';
+ $adminStar = '';
+ }
+
+ // Private Note (just visible by the owner and his/her contacts)
+ if ($watchedNames !== null
+ && ($currentUser->getId() == $row['uId']
+ || in_array($row['username'], $watchedNames)
+ )
+ ) {
+ $privateNoteField = $row['bPrivateNote'];
+ } else {
+ $privateNoteField = '';
+ }
+
+ if ($GLOBALS['enableVoting'] && $GLOBALS['hideBelowVoting'] !== null
+ && $row['bVoting'] < $GLOBALS['hideBelowVoting']
+ ) {
+ $access .= ' below-threshold';
+ }
+
+ // Output
+ echo ' - '."\n";
+ include 'bookmarks-thumbnail.inc.tpl.php';
+ include 'bookmarks-vote.inc.tpl.php';
+
+ echo '
' . "\n";
+
+ echo '
\n";
+ if ($row['bDescription'] == '') {
+ $bkDescription = $GLOBALS['blankDescription'];
+ } else {
+ // Improve description display (anchors, links, ...)
+ $bkDescription = preg_replace('|\[\/.*?\]|', '', filter($row['bDescription'])); // remove final anchor
+ $bkDescription = preg_replace('|\[(.*?)\]|', '
$1 » ', $bkDescription); // highlight starting anchor
+ $bkDescription = preg_replace('@((http|https|ftp)://.*?)( |\r|$)@', '
$1$3', $bkDescription); // make url clickable
+
+ }
+ echo '
'. nl2br($bkDescription) ."
\n";
+ echo '
' . shortenString($oaddress) . "
\n";
+
+ echo '
'
+ . $cats . "\n"
+ . $copy . "\n"
+ . $edit . "\n"
+ . $update . "\n"
+ . "
\n";
+ echo $privateNoteField != ''
+ ? '
'.$privateNoteField."
\n"
+ : '';
+ echo ' ';
+ include 'bookmarks-vote-horizontal.inc.tpl.php';
+ echo "
\n";
+
+ echo " \n";
+ }
+ ?>
+
+
+
+ 7) {
+ echo ''.T_('Top of the page').'
';
+ }
+ echo $pagesBanner; // display previous and next links pages + RSS link
+
+
+} else {
+ echo ''.T_('No bookmarks available').'
';
+}
+$this->includeTemplate('sidebar.tpl');
+$this->includeTemplate($GLOBALS['bottom_include']);
+?>
diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php
index aa0b8c3..0912d55 100644
--- a/tests/BookmarkTest.php
+++ b/tests/BookmarkTest.php
@@ -1,1377 +1,1452 @@
-
- * @author Christian Weiske
- * @author Eric Dane
- * @license GPL http://www.gnu.org/licenses/gpl.html
- * @link http://sourceforge.net/projects/semanticscuttle
- */
-if (!defined('PHPUnit_MAIN_METHOD')) {
- define('PHPUnit_MAIN_METHOD', 'BookmarkTest::main');
-}
-
-require_once 'prepare.php';
-
-/**
- * Unit tests for the SemanticScuttle bookmark service.
- *
- * @category Bookmarking
- * @package SemanticScuttle
- * @author Benjamin Huynh-Kim-Bang
- * @author Christian Weiske
- * @author Eric Dane
- * @license GPL http://www.gnu.org/licenses/gpl.html
- * @link http://sourceforge.net/projects/semanticscuttle
- */
-class BookmarkTest extends TestBase
-{
- protected $us;
- protected $bs;
- protected $ts;
- protected $tts;
-
-
-
- /**
- * 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__)
- );
- }
-
-
-
- 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();
- }
-
- /**
- * Tests if adding a bookmark with short url name
- * saves it in the database.
- *
- * @return void
- */
- public function testAddBookmarkShort()
- {
- $bid = $this->bs->addBookmark(
- 'http://example.org', 'title', 'desc', 'priv',
- 0, array(), 'myShortName'
- );
- $bm = $this->bs->getBookmark($bid);
- $this->assertEquals('http://example.org', $bm['bAddress']);
- $this->assertArrayHasKey('bShort', $bm);
- $this->assertEquals('myShortName', $bm['bShort']);
- }
-
- public function testHardCharactersInBookmarks()
- {
- $bs = $this->bs;
- $title = "title&é\"'(-è_çà)=";
- $desc = "description#{[|`\^@]}³<> ¹¡÷׿&é\"'(-è\\_çà)=";
- $tag1 = "#{|`^@]³¹¡¿<&é\"'(-è\\_çà)";
- $tag2 = "&é\"'(-è.[?./§!_çà)";
-
- $uid = $this->addUser();
- $bid = $bs->addBookmark(
- 'http://site1.com', $title, $desc, 'note',
- 0, array($tag1, $tag2),
- null, null, false, false, $uid
- );
-
- $bookmarks = $bs->getBookmarks(0, 1);
-
- $b0 = $bookmarks['bookmarks'][0];
- $this->assertEquals($title, $b0['bTitle']);
- $this->assertEquals($desc, $b0['bDescription']);
- $this->assertEquals(
- str_replace(array('"', '\'', '/'), "_", $tag1),
- $b0['tags'][0]
- );
- $this->assertEquals(
- str_replace(array('"', '\'', '/'), "_", $tag2),
- $b0['tags'][1]
- );
- }
-
- public function testUnificationOfBookmarks()
- {
- $bs = $this->bs;
-
- $uid = $this->addUser();
- $uid2 = $this->addUser();
-
- $bs->addBookmark(
- 'http://site1.com', "title", "description", 'note',
- 0, array('tag1'), null, null, false, false,
- $uid
- );
- $bs->addBookmark(
- "http://site1.com", "title2", "description2", 'note',
- 0, array('tag2'), null, null, false, false,
- $uid2
- );
-
- $bookmarks = $bs->getBookmarks();
- $this->assertEquals(1, $bookmarks['total']);
- }
-
- /*public function testSearchingBookmarksAccentsInsensible()
- {
- $bs = $this->bs;
-
- $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']);
- }*/
-
-
-
- /**
- * Tests if bookmarkExists() returns false when the given
- * parameter is invalid.
- *
- * @return void
- */
- public function testBookmarkExistsInvalidParam()
- {
- $this->assertFalse($this->bs->bookmarkExists(false));
- $this->assertFalse($this->bs->bookmarkExists(null));
- }
-
-
-
- /**
- * Tests if bookmarkExists() returns true when a bookmark
- * exists
- *
- * @return void
- */
- public function testBookmarkExistsTrue()
- {
- $bid = $this->addBookmark();
- $bookmark = $this->bs->getBookmark($bid);
-
- $this->assertTrue($this->bs->bookmarkExists($bookmark['bAddress']));
- }
-
-
-
- /**
- * Tests if bookmarkExists() returns false when a bookmark
- * does not exist
- *
- * @return void
- */
- public function testBookmarkExistsFalse()
- {
- $this->assertFalse($this->bs->bookmarkExists('does-not-exist'));
- }
-
-
-
- /**
- * Tests if bookmarkExists() returns true when a bookmark
- * exists for a user
- *
- * @return void
- */
- public function testBookmarkExistsUserTrue()
- {
- $bid = $this->addBookmark();
- $bookmark = $this->bs->getBookmark($bid);
-
- $this->assertTrue(
- $this->bs->bookmarkExists(
- $bookmark['bAddress'],
- $bookmark['uId']
- )
- );
- }
-
-
-
- /**
- * Tests if bookmarkExists() returns false when a bookmark
- * does not exist for a user
- *
- * @return void
- */
- public function testBookmarkExistsUserFalse()
- {
- $this->assertFalse(
- $this->bs->bookmarkExists('does-not-exist', 1234)
- );
- }
-
-
-
- /**
- * Tests if bookmarkExists() returns false when a bookmark
- * does not exist for a user but for another user
- *
- * @return void
- */
- public function testBookmarkExistsOtherUser()
- {
- $bid = $this->addBookmark();
- $bookmark = $this->bs->getBookmark($bid);
-
- $this->assertFalse(
- $this->bs->bookmarkExists(
- $bookmark['bAddress'],
- $bookmark['uId'] + 1
- )
- );
- }
-
-
-
- /**
- * 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->assertInternalType('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->assertInternalType('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->assertInternalType('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->assertInternalType('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);
-
- //do not search for this one
- $bid3 = $this->addBookmark();
- $bookmark3 = $this->bs->getBookmark($bid3);
-
-
- $ret = $this->bs->bookmarksExist(
- array(
- $bookmark['bAddress'],
- 'does-not-exist',
- $bookmark2['bAddress'],
- 'does-not-exist-2',
- 'does-not-exist-3'
- )
- );
- $this->assertInternalType('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
- *
- * @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'));
- $this->assertEquals(0, $this->bs->countBookmarks($uid, 'all'));
- }
-
-
-
- /**
- * 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'));
- $this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));
- }
-
-
-
- /**
- * 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, 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'));
- $this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));
- }
-
-
-
- /**
- * 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, 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'));
- $this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));
- }
-
-
-
- /**
- * 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->assertInternalType('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.
- *
- * @return void
- */
- public function testDeleteBookmark()
- {
- $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 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
- */
- public function testDeleteBookmarkWithVote()
- {
- $GLOBALS['enableVoting'] = true;
-
- $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));
- }
-
-
-
- /**
- * Test if editAllowed() returns false when the bookmark
- * id is invalid.
- *
- * @return void
- */
- public function testEditAllowedInvalidBookmarkId()
- {
- $this->assertFalse($this->bs->editAllowed('invalid'));
- $this->assertFalse($this->bs->editAllowed(array()));
- $this->assertFalse($this->bs->editAllowed(array('some', 'where')));
- $this->assertFalse($this->bs->editAllowed(array('bId' => false)));
- $this->assertFalse($this->bs->editAllowed(array('bId' => 'foo')));
- }
-
-
-
- /**
- * Test if editAllowed() works when passing the ID of
- * an existing bookmark.
- *
- * @return void
- */
- public function testEditAllowedBookmarkId()
- {
- $uid = $this->addUser();
- $bid = $this->addBookmark($uid);
- $this->us->setCurrentUserId($uid);
- $this->assertTrue($this->bs->editAllowed($bid));
- }
-
-
-
- /**
- * Test if editAllowed() works when passing the ID of
- * an existing bookmark that does not belong to the current
- * user.
- *
- * @return void
- */
- public function testEditAllowedBookmarkIdNotOwn()
- {
- $uid = $this->addUser();
- $bid = $this->addBookmark();
- $this->us->setCurrentUserId($uid);
- $this->assertFalse($this->bs->editAllowed($bid));
- }
-
-
-
- /**
- * Test if editAllowed() works when passing the ID of
- * an existing bookmark that does not belong to the current
- * user.
- *
- * @return void
- */
- public function testEditAllowedBookmarkIdNoUser()
- {
- $bid = $this->addBookmark();
- $this->us->setCurrentUserId(null);
- $this->assertFalse($this->bs->editAllowed($bid));
- }
-
-
-
- /**
- * Test if editAllowed() works when passing a bookmark
- * row.
- *
- * @return void
- */
- public function testEditAllowedBookmarkRow()
- {
- $uid = $this->addUser();
- $this->us->setCurrentUserId($uid);
-
- $bid = $this->addBookmark($uid);
- $bookmark = $this->bs->getBookmark($bid);
- $this->assertTrue($this->bs->editAllowed($bookmark));
- }
-
-
-
- /**
- * Test if editAllowed() returns false when the bookmark
- * specified by the ID does not exist.
- *
- * @return void
- */
- public function testEditAllowedIdNotFound()
- {
- $this->assertFalse($this->bs->editAllowed(98765));
- }
-
-
-
- /**
- * Test if editAllowed() works when the user is an administrator.
- *
- * @return void
- */
- public function testEditAllowedBookmarkAdmin()
- {
- //make the user admin
- $uid = $this->addUser();
- $user = $this->us->getUser($uid);
- $GLOBALS['admin_users'][] = $user['username'];
-
- $bid = $this->addBookmark($uid);
- $this->us->setCurrentUserId($uid);
- $this->assertTrue($this->bs->editAllowed($bid));
- }
-
-
-
- /**
- * 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->assertInternalType('array', $bm['tags']);
- $this->assertContains('foo', $bm['tags']);
- $this->assertContains('bar', $bm['tags']);
- }
-
-
-
- /**
- * Verify that getBookmark() does not include user voting
- * data when no user is logged on.
- *
- * @return void
- */
- public function testGetBookmarkUserVotingNoUser()
- {
- $GLOBALS['enableVoting'] = true;
-
- $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()
- {
- $GLOBALS['enableVoting'] = true;
-
- $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()
- {
- $GLOBALS['enableVoting'] = true;
-
- $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()
- {
- $GLOBALS['enableVoting'] = true;
-
- $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']);
- }
-
-
-
- /**
- * 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->assertInternalType('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->assertInternalType('array', $bm);
- $this->assertEquals($url, $bm['bAddress']);
- }
-
-
-
- public function testNormalize()
- {
- $this->assertEquals(
- 'http://example.org', $this->bs->normalize('http://example.org')
- );
- $this->assertEquals(
- 'ftp://example.org', $this->bs->normalize('ftp://example.org')
- );
- $this->assertEquals(
- 'http://example.org', $this->bs->normalize('http://example.org/')
- );
- $this->assertEquals(
- 'http://example.org', $this->bs->normalize('example.org')
- );
- $this->assertEquals(
- 'mailto:foo@example.org',
- $this->bs->normalize('mailto:foo@example.org')
- );
- }
-
-
-
- /**
- * test if updating an existing bookmark works
- */
- public function testUpdateBookmark()
- {
- $bid = $this->addBookmark();
- $this->assertTrue(
- $this->bs->updateBookmark(
- $bid,
- 'http://example.org/foo',
- 'my new title',
- 'new description',
- 'new private note',
- 1,
- array('new')
- )
- );
- $bm = $this->bs->getBookmark($bid, true);
- $this->assertEquals('http://example.org/foo', $bm['bAddress']);
- $this->assertEquals('my new title', $bm['bTitle']);
- $this->assertEquals('new description', $bm['bDescription']);
- $this->assertEquals('new private note', $bm['bPrivateNote']);
- $this->assertEquals(1, $bm['bStatus']);
- $this->assertInternalType('array', $bm['tags']);
- $this->assertEquals(1, count($bm['tags']));
- $this->assertContains('new', $bm['tags']);
- }
-
- /**
- * Tests if updating a bookmark's short url name
- * saves it in the database.
- *
- * @return void
- */
- public function testUpdateBookmarkShort()
- {
- $bid = $this->bs->addBookmark(
- 'http://example.org', 'title', 'desc', 'priv',
- 0, array(), 'myShortName'
- );
- $bm = $this->bs->getBookmark($bid);
- $this->assertEquals('myShortName', $bm['bShort']);
-
- $this->assertTrue(
- $this->bs->updateBookmark(
- $bid, 'http://example2.org', 'my title', 'desc',
- 'priv', 0, array(), 'newShortNambb'
- )
- );
- $bm = $this->bs->getBookmark($bid);
- $this->assertEquals('newShortNambb', $bm['bShort']);
- }
-
- /**
- * Tests if updating a bookmark's date works.
- * This once was a bug, see bug #3073215.
- *
- * @return void
- *
- * @link https://sourceforge.net/tracker/?func=detail&atid=1017430&aid=3073215&group_id=211356
- */
- public function testUpdateBookmarkDate()
- {
- $bid = $this->bs->addBookmark(
- 'http://example.org', 'title', 'desc', 'priv',
- 0, array(), 'myShortName'
- );
- $bm = $this->bs->getBookmark($bid);
- $this->assertEquals('myShortName', $bm['bShort']);
-
- $this->assertTrue(
- $this->bs->updateBookmark(
- $bid, 'http://example2.org', 'my title', 'desc',
- 'priv', 0, array(), 'newShortNambb',
- //we need to use zulu (GMT) time zone here
- // since the dates/times are stored as that
- // in the database
- '2002-03-04T05:06:07Z'
- )
- );
- $bm = $this->bs->getBookmark($bid);
- $this->assertEquals('newShortNambb', $bm['bShort']);
- $this->assertEquals('2002-03-04 05:06:07', $bm['bDatetime']);
- }
-
-
-
- /**
- * 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 a friend (people on the watchlist) has bookmarked
- * and the same address with public status.
- *
- * @return void
- */
- public function testCountOthersWatchlistPublic()
- {
- $uid = $this->addUser();
- $address = 'http://example.org';
-
- //create other user and add main user to his watchlist
- $friendPublic1 = $this->addUser();
- $this->us->setCurrentUserId($friendPublic1);
- $this->us->setWatchStatus($uid);
-
- //create bookmarks for main user and other one
- $this->addBookmark($uid, $address, 0);
- $this->addBookmark($friendPublic1, $address, 0);//0 is public
-
- //log main user in
- $this->us->setCurrentUserId($uid);
-
- $this->assertEquals(1, $this->bs->countOthers($address));
- }
-
-
-
- /**
- * Test what countOther() returns when the user is logged in
- * and a friend (people on the watchlist) has bookmarked
- * and shared the same address for the watchlist.
- *
- * @return void
- */
- public function testCountOthersWatchlistShared()
- {
- $uid = $this->addUser();
- $address = 'http://example.org';
-
- //create other user and add main user to his watchlist
- $friendPublic1 = $this->addUser();
- $this->us->setCurrentUserId($friendPublic1);
- $this->us->setWatchStatus($uid);
-
- //create bookmarks for main user and other one
- $this->addBookmark($uid, $address, 0);
- $this->addBookmark($friendPublic1, $address, 1);//1 is shared
-
- //log main user in
- $this->us->setCurrentUserId($uid);
-
- $this->assertEquals(1, $this->bs->countOthers($address));
- }
-
-
-
- /**
- * Test what countOther() returns when the user is logged in
- * and one friends (people on the watchlist) has bookmarked
- * the same address but made it private.
- *
- * @return void
- */
- public function testCountOthersWatchlistPrivate()
- {
- $uid = $this->addUser();
- $address = 'http://example.org';
-
- //create other user and add main user to his watchlist
- $friendPublic1 = $this->addUser();
- $this->us->setCurrentUserId($friendPublic1);
- $this->us->setWatchStatus($uid);
-
- //create bookmarks for main user and other one
- $this->addBookmark($uid, $address, 0);
- $this->addBookmark($friendPublic1, $address, 2);//2 is private
-
- //log main user in
- $this->us->setCurrentUserId($uid);
-
- $this->assertEquals(0, $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 testCountOthersWatchlistComplex()
- {
- $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));
- }
-
-
-
- /**
- * 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)
- )
- );
- }
-
-
- /**
- * Test that the default privacy setting in
- * $GLOBALS['defaults']['privacy'] is used
- * as expected.
- *
- * @return void
- */
- public function testDefaultPrivacy()
- {
- $GLOBALS['defaults']['privacy'] = 1;
- $uid = $this->addUser();
- $this->us->setCurrentUserId($uid);
- $bid = $this->bs->addBookmark('http://www.somedomain.com', 'mybookmark1', 'descr1', 'privatenote1', $GLOBALS['defaults']['privacy'], array());
- $bm = $this->bs->getBookmark($bid);
- $this->assertEquals('1', $bm['bStatus']);
- $GLOBALS['defaults']['privacy'] = 2;
- $uid = $this->addUser();
- $this->us->setCurrentUserId($uid);
- $bid = $this->bs->addBookmark('http://www.anotherdomain.com', 'mybookmark2', 'descr2', 'privatenote2', $GLOBALS['defaults']['privacy'], array());
- $bm = $this->bs->getBookmark($bid);
- $this->assertEquals('2', $bm['bStatus']);
- }//end function testDefaultPrivacy
-
-
-
-}
-
-
-if (PHPUnit_MAIN_METHOD == 'BookmarkTest::main') {
- BookmarkTest::main();
-}
-?>
+
+ * @author Christian Weiske
+ * @author Eric Dane
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+if (!defined('PHPUnit_MAIN_METHOD')) {
+ define('PHPUnit_MAIN_METHOD', 'BookmarkTest::main');
+}
+
+require_once 'prepare.php';
+
+/**
+ * Unit tests for the SemanticScuttle bookmark service.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Benjamin Huynh-Kim-Bang
+ * @author Christian Weiske
+ * @author Eric Dane
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+class BookmarkTest extends TestBase
+{
+ protected $us;
+ protected $bs;
+ protected $ts;
+ protected $tts;
+
+
+
+ /**
+ * 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__)
+ );
+ }
+
+
+
+ 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();
+ }
+
+ /**
+ * Tests if adding a bookmark with short url name
+ * saves it in the database.
+ *
+ * @return void
+ */
+ public function testAddBookmarkShort()
+ {
+ $bid = $this->bs->addBookmark(
+ 'http://example.org', 'title', 'desc', 'priv',
+ 0, array(), 'myShortName'
+ );
+ $bm = $this->bs->getBookmark($bid);
+ $this->assertEquals('http://example.org', $bm['bAddress']);
+ $this->assertArrayHasKey('bShort', $bm);
+ $this->assertEquals('myShortName', $bm['bShort']);
+ }
+
+ public function testHardCharactersInBookmarks()
+ {
+ $bs = $this->bs;
+ $title = "title&é\"'(-è_çà)=";
+ $desc = "description#{[|`\^@]}³<> ¹¡÷׿&é\"'(-è\\_çà)=";
+ $tag1 = "#{|`^@]³¹¡¿<&é\"'(-è\\_çà)";
+ $tag2 = "&é\"'(-è.[?./§!_çà)";
+
+ $uid = $this->addUser();
+ $bid = $bs->addBookmark(
+ 'http://site1.com', $title, $desc, 'note',
+ 0, array($tag1, $tag2),
+ null, null, false, false, $uid
+ );
+
+ $bookmarks = $bs->getBookmarks(0, 1);
+
+ $b0 = $bookmarks['bookmarks'][0];
+ $this->assertEquals($title, $b0['bTitle']);
+ $this->assertEquals($desc, $b0['bDescription']);
+ $this->assertEquals(
+ str_replace(array('"', '\'', '/'), "_", $tag1),
+ $b0['tags'][0]
+ );
+ $this->assertEquals(
+ str_replace(array('"', '\'', '/'), "_", $tag2),
+ $b0['tags'][1]
+ );
+ }
+
+ public function testUnificationOfBookmarks()
+ {
+ $bs = $this->bs;
+
+ $uid = $this->addUser();
+ $uid2 = $this->addUser();
+
+ $bs->addBookmark(
+ 'http://site1.com', "title", "description", 'note',
+ 0, array('tag1'), null, null, false, false,
+ $uid
+ );
+ $bs->addBookmark(
+ "http://site1.com", "title2", "description2", 'note',
+ 0, array('tag2'), null, null, false, false,
+ $uid2
+ );
+
+ $bookmarks = $bs->getBookmarks();
+ $this->assertEquals(1, $bookmarks['total']);
+ }
+
+ /*public function testSearchingBookmarksAccentsInsensible()
+ {
+ $bs = $this->bs;
+
+ $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']);
+ }*/
+
+
+
+ /**
+ * Tests if bookmarkExists() returns false when the given
+ * parameter is invalid.
+ *
+ * @return void
+ */
+ public function testBookmarkExistsInvalidParam()
+ {
+ $this->assertFalse($this->bs->bookmarkExists(false));
+ $this->assertFalse($this->bs->bookmarkExists(null));
+ }
+
+
+
+ /**
+ * Tests if bookmarkExists() returns true when a bookmark
+ * exists
+ *
+ * @return void
+ */
+ public function testBookmarkExistsTrue()
+ {
+ $bid = $this->addBookmark();
+ $bookmark = $this->bs->getBookmark($bid);
+
+ $this->assertTrue($this->bs->bookmarkExists($bookmark['bAddress']));
+ }
+
+
+
+ /**
+ * Tests if bookmarkExists() returns false when a bookmark
+ * does not exist
+ *
+ * @return void
+ */
+ public function testBookmarkExistsFalse()
+ {
+ $this->assertFalse($this->bs->bookmarkExists('does-not-exist'));
+ }
+
+
+
+ /**
+ * Tests if bookmarkExists() returns true when a bookmark
+ * exists for a user
+ *
+ * @return void
+ */
+ public function testBookmarkExistsUserTrue()
+ {
+ $bid = $this->addBookmark();
+ $bookmark = $this->bs->getBookmark($bid);
+
+ $this->assertTrue(
+ $this->bs->bookmarkExists(
+ $bookmark['bAddress'],
+ $bookmark['uId']
+ )
+ );
+ }
+
+
+
+ /**
+ * Tests if bookmarkExists() returns false when a bookmark
+ * does not exist for a user
+ *
+ * @return void
+ */
+ public function testBookmarkExistsUserFalse()
+ {
+ $this->assertFalse(
+ $this->bs->bookmarkExists('does-not-exist', 1234)
+ );
+ }
+
+
+
+ /**
+ * Tests if bookmarkExists() returns false when a bookmark
+ * does not exist for a user but for another user
+ *
+ * @return void
+ */
+ public function testBookmarkExistsOtherUser()
+ {
+ $bid = $this->addBookmark();
+ $bookmark = $this->bs->getBookmark($bid);
+
+ $this->assertFalse(
+ $this->bs->bookmarkExists(
+ $bookmark['bAddress'],
+ $bookmark['uId'] + 1
+ )
+ );
+ }
+
+
+
+ /**
+ * 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->assertInternalType('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->assertInternalType('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->assertInternalType('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->assertInternalType('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);
+
+ //do not search for this one
+ $bid3 = $this->addBookmark();
+ $bookmark3 = $this->bs->getBookmark($bid3);
+
+
+ $ret = $this->bs->bookmarksExist(
+ array(
+ $bookmark['bAddress'],
+ 'does-not-exist',
+ $bookmark2['bAddress'],
+ 'does-not-exist-2',
+ 'does-not-exist-3'
+ )
+ );
+ $this->assertInternalType('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
+ *
+ * @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'));
+ $this->assertEquals(0, $this->bs->countBookmarks($uid, 'all'));
+ }
+
+
+
+ /**
+ * 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'));
+ $this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));
+ }
+
+
+
+ /**
+ * 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, 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'));
+ $this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));
+ }
+
+
+
+ /**
+ * 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, 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'));
+ $this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));
+ }
+
+
+
+ /**
+ * 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->assertInternalType('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.
+ *
+ * @return void
+ */
+ public function testDeleteBookmark()
+ {
+ $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 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
+ */
+ public function testDeleteBookmarkWithVote()
+ {
+ $GLOBALS['enableVoting'] = true;
+
+ $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));
+ }
+
+
+
+ /**
+ * Test if editAllowed() returns false when the bookmark
+ * id is invalid.
+ *
+ * @return void
+ */
+ public function testEditAllowedInvalidBookmarkId()
+ {
+ $this->assertFalse($this->bs->editAllowed('invalid'));
+ $this->assertFalse($this->bs->editAllowed(array()));
+ $this->assertFalse($this->bs->editAllowed(array('some', 'where')));
+ $this->assertFalse($this->bs->editAllowed(array('bId' => false)));
+ $this->assertFalse($this->bs->editAllowed(array('bId' => 'foo')));
+ }
+
+
+
+ /**
+ * Test if editAllowed() works when passing the ID of
+ * an existing bookmark.
+ *
+ * @return void
+ */
+ public function testEditAllowedBookmarkId()
+ {
+ $uid = $this->addUser();
+ $bid = $this->addBookmark($uid);
+ $this->us->setCurrentUserId($uid);
+ $this->assertTrue($this->bs->editAllowed($bid));
+ }
+
+
+
+ /**
+ * Test if editAllowed() works when passing the ID of
+ * an existing bookmark that does not belong to the current
+ * user.
+ *
+ * @return void
+ */
+ public function testEditAllowedBookmarkIdNotOwn()
+ {
+ $uid = $this->addUser();
+ $bid = $this->addBookmark();
+ $this->us->setCurrentUserId($uid);
+ $this->assertFalse($this->bs->editAllowed($bid));
+ }
+
+
+
+ /**
+ * Test if editAllowed() works when passing the ID of
+ * an existing bookmark that does not belong to the current
+ * user.
+ *
+ * @return void
+ */
+ public function testEditAllowedBookmarkIdNoUser()
+ {
+ $bid = $this->addBookmark();
+ $this->us->setCurrentUserId(null);
+ $this->assertFalse($this->bs->editAllowed($bid));
+ }
+
+
+
+ /**
+ * Test if editAllowed() works when passing a bookmark
+ * row.
+ *
+ * @return void
+ */
+ public function testEditAllowedBookmarkRow()
+ {
+ $uid = $this->addUser();
+ $this->us->setCurrentUserId($uid);
+
+ $bid = $this->addBookmark($uid);
+ $bookmark = $this->bs->getBookmark($bid);
+ $this->assertTrue($this->bs->editAllowed($bookmark));
+ }
+
+
+
+ /**
+ * Test if editAllowed() returns false when the bookmark
+ * specified by the ID does not exist.
+ *
+ * @return void
+ */
+ public function testEditAllowedIdNotFound()
+ {
+ $this->assertFalse($this->bs->editAllowed(98765));
+ }
+
+
+
+ /**
+ * Test if editAllowed() works when the user is an administrator.
+ *
+ * @return void
+ */
+ public function testEditAllowedBookmarkAdmin()
+ {
+ //make the user admin
+ $uid = $this->addUser();
+ $user = $this->us->getUser($uid);
+ $GLOBALS['admin_users'][] = $user['username'];
+
+ $bid = $this->addBookmark($uid);
+ $this->us->setCurrentUserId($uid);
+ $this->assertTrue($this->bs->editAllowed($bid));
+ }
+
+
+
+ /**
+ * 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->assertInternalType('array', $bm['tags']);
+ $this->assertContains('foo', $bm['tags']);
+ $this->assertContains('bar', $bm['tags']);
+ }
+
+
+
+ /**
+ * Verify that getBookmark() does not include user voting
+ * data when no user is logged on.
+ *
+ * @return void
+ */
+ public function testGetBookmarkUserVotingNoUser()
+ {
+ $GLOBALS['enableVoting'] = true;
+
+ $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()
+ {
+ $GLOBALS['enableVoting'] = true;
+
+ $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()
+ {
+ $GLOBALS['enableVoting'] = true;
+
+ $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()
+ {
+ $GLOBALS['enableVoting'] = true;
+
+ $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']);
+ }
+
+
+
+ /**
+ * 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->assertInternalType('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->assertInternalType('array', $bm);
+ $this->assertEquals($url, $bm['bAddress']);
+ }
+
+
+
+ public function testNormalize()
+ {
+ $this->assertEquals(
+ 'http://example.org', $this->bs->normalize('http://example.org')
+ );
+ $this->assertEquals(
+ 'ftp://example.org', $this->bs->normalize('ftp://example.org')
+ );
+ $this->assertEquals(
+ 'http://example.org', $this->bs->normalize('http://example.org/')
+ );
+ $this->assertEquals(
+ 'http://example.org', $this->bs->normalize('example.org')
+ );
+ $this->assertEquals(
+ 'mailto:foo@example.org',
+ $this->bs->normalize('mailto:foo@example.org')
+ );
+ }
+
+
+
+ /**
+ * test if updating an existing bookmark works
+ */
+ public function testUpdateBookmark()
+ {
+ $bid = $this->addBookmark();
+ $this->assertTrue(
+ $this->bs->updateBookmark(
+ $bid,
+ 'http://example.org/foo',
+ 'my new title',
+ 'new description',
+ 'new private note',
+ 1,
+ array('new')
+ )
+ );
+ $bm = $this->bs->getBookmark($bid, true);
+ $this->assertEquals('http://example.org/foo', $bm['bAddress']);
+ $this->assertEquals('my new title', $bm['bTitle']);
+ $this->assertEquals('new description', $bm['bDescription']);
+ $this->assertEquals('new private note', $bm['bPrivateNote']);
+ $this->assertEquals(1, $bm['bStatus']);
+ $this->assertInternalType('array', $bm['tags']);
+ $this->assertEquals(1, count($bm['tags']));
+ $this->assertContains('new', $bm['tags']);
+ }
+
+ /**
+ * Tests if updating a bookmark's short url name
+ * saves it in the database.
+ *
+ * @return void
+ */
+ public function testUpdateBookmarkShort()
+ {
+ $bid = $this->bs->addBookmark(
+ 'http://example.org', 'title', 'desc', 'priv',
+ 0, array(), 'myShortName'
+ );
+ $bm = $this->bs->getBookmark($bid);
+ $this->assertEquals('myShortName', $bm['bShort']);
+
+ $this->assertTrue(
+ $this->bs->updateBookmark(
+ $bid, 'http://example2.org', 'my title', 'desc',
+ 'priv', 0, array(), 'newShortNambb'
+ )
+ );
+ $bm = $this->bs->getBookmark($bid);
+ $this->assertEquals('newShortNambb', $bm['bShort']);
+ }
+
+ /**
+ * Tests if updating a bookmark's date works.
+ * This once was a bug, see bug #3073215.
+ *
+ * @return void
+ *
+ * @link https://sourceforge.net/tracker/?func=detail&atid=1017430&aid=3073215&group_id=211356
+ */
+ public function testUpdateBookmarkDate()
+ {
+ $bid = $this->bs->addBookmark(
+ 'http://example.org', 'title', 'desc', 'priv',
+ 0, array(), 'myShortName'
+ );
+ $bm = $this->bs->getBookmark($bid);
+ $this->assertEquals('myShortName', $bm['bShort']);
+
+ $this->assertTrue(
+ $this->bs->updateBookmark(
+ $bid, 'http://example2.org', 'my title', 'desc',
+ 'priv', 0, array(), 'newShortNambb',
+ //we need to use zulu (GMT) time zone here
+ // since the dates/times are stored as that
+ // in the database
+ '2002-03-04T05:06:07Z'
+ )
+ );
+ $bm = $this->bs->getBookmark($bid);
+ $this->assertEquals('newShortNambb', $bm['bShort']);
+ $this->assertEquals('2002-03-04 05:06:07', $bm['bDatetime']);
+ }
+
+
+
+ /**
+ * 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 a friend (people on the watchlist) has bookmarked
+ * and the same address with public status.
+ *
+ * @return void
+ */
+ public function testCountOthersWatchlistPublic()
+ {
+ $uid = $this->addUser();
+ $address = 'http://example.org';
+
+ //create other user and add main user to his watchlist
+ $friendPublic1 = $this->addUser();
+ $this->us->setCurrentUserId($friendPublic1);
+ $this->us->setWatchStatus($uid);
+
+ //create bookmarks for main user and other one
+ $this->addBookmark($uid, $address, 0);
+ $this->addBookmark($friendPublic1, $address, 0);//0 is public
+
+ //log main user in
+ $this->us->setCurrentUserId($uid);
+
+ $this->assertEquals(1, $this->bs->countOthers($address));
+ }
+
+
+
+ /**
+ * Test what countOther() returns when the user is logged in
+ * and a friend (people on the watchlist) has bookmarked
+ * and shared the same address for the watchlist.
+ *
+ * @return void
+ */
+ public function testCountOthersWatchlistShared()
+ {
+ $uid = $this->addUser();
+ $address = 'http://example.org';
+
+ //create other user and add main user to his watchlist
+ $friendPublic1 = $this->addUser();
+ $this->us->setCurrentUserId($friendPublic1);
+ $this->us->setWatchStatus($uid);
+
+ //create bookmarks for main user and other one
+ $this->addBookmark($uid, $address, 0);
+ $this->addBookmark($friendPublic1, $address, 1);//1 is shared
+
+ //log main user in
+ $this->us->setCurrentUserId($uid);
+
+ $this->assertEquals(1, $this->bs->countOthers($address));
+ }
+
+
+
+ /**
+ * Test what countOther() returns when the user is logged in
+ * and one friends (people on the watchlist) has bookmarked
+ * the same address but made it private.
+ *
+ * @return void
+ */
+ public function testCountOthersWatchlistPrivate()
+ {
+ $uid = $this->addUser();
+ $address = 'http://example.org';
+
+ //create other user and add main user to his watchlist
+ $friendPublic1 = $this->addUser();
+ $this->us->setCurrentUserId($friendPublic1);
+ $this->us->setWatchStatus($uid);
+
+ //create bookmarks for main user and other one
+ $this->addBookmark($uid, $address, 0);
+ $this->addBookmark($friendPublic1, $address, 2);//2 is private
+
+ //log main user in
+ $this->us->setCurrentUserId($uid);
+
+ $this->assertEquals(0, $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 testCountOthersWatchlistComplex()
+ {
+ $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));
+ }
+
+
+
+ /**
+ * 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)
+ )
+ );
+ }
+
+
+ /**
+ * Test that the default privacy setting in
+ * $GLOBALS['defaults']['privacy'] is used
+ * as expected.
+ *
+ * @return void
+ */
+ public function testDefaultPrivacy()
+ {
+ //For this test, the default privacy has been set to 2 (private) in the configuration file.
+ require_once 'HTTP/Request2.php';
+ require_once dirname(__FILE__) . '/../data/config.php';
+ $this->bs->deleteAll();
+ $this->us->deleteAll();
+ $request = new HTTP_Request2('http://localhost/api/posts_add.php', HTTP_Request2::METHOD_POST);
+ $dpuid = $this->addUser('dpuser', 'dpuserpassword');
+ $request->setAuth('dpuser', 'dpuserpassword');
+ $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com');
+ $request->addPostParameter('description', 'Test bookmark 1 for default privacy.');
+ $request->send();
+ $bm = $this->bs->getBookmark('1');
+ $this->assertEquals('2', $bm['bStatus']);
+
+ $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add2.com');
+ $request->addPostParameter('description', 'Test bookmark 2 for default privacy.');
+ $request->addPostParameter('status', '0');
+ $request->send();
+
+ $request = new HTTP_Request2('http://localhost/edit.php/2', HTTP_Request2::METHOD_POST);
+ $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
+ $userinfo = $this->us->getUser('1');
+ $testcookiepassword = $userinfo['password'];
+ $testcookievalue = '1:'.md5('dpuser'.$testcookiepassword);
+ $request->setCookieJar(true);
+ $request->addCookie($testcookiekey, $testcookievalue);
+ $request->addPostParameter('title', 'Test bookmark 2 for default privacy.');
+ $request->addPostParameter('address', 'http://www.testdefaultprivacyposts_add2.com');
+ $request->addPostParameter('submitted', '1');
+ $request->send();
+ $bm = $this->bs->getBookmark('2');
+ $this->assertEquals('2', $bm['bStatus']);
+
+ $request = new HTTP_Request2('http://localhost/importNetscape.php', HTTP_Request2::METHOD_POST);
+ $request->setCookieJar(true);
+ $request->addCookie($testcookiekey, $testcookievalue);
+ $request->addUpload('userfile', './data/BookmarkTest_netscapebookmarks.html');
+ $request->send();
+ $bm = $this->bs->getBookmark('3');
+ $this->assertEquals('2', $bm['bStatus']);
+ $bm = $this->bs->getBookmark('4');
+ $this->assertEquals('2', $bm['bStatus']);
+ $bm = $this->bs->getBookmark('5');
+ $this->assertEquals('2', $bm['bStatus']);
+
+ $request = new HTTP_Request2('http://localhost/import.php', HTTP_Request2::METHOD_POST);
+ $request->setCookieJar(true);
+ $request->addCookie($testcookiekey, $testcookievalue);
+ $request->addUpload('userfile', './data/BookmarkTest_deliciousbookmarks.xml');
+ $request->send();
+ $bm = $this->bs->getBookmark('6');
+ $this->assertEquals('2', $bm['bStatus']);
+ $bm = $this->bs->getBookmark('7');
+ $this->assertEquals('2', $bm['bStatus']);
+ $bm = $this->bs->getBookmark('8');
+ $this->assertEquals('2', $bm['bStatus']);
+
+ $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=get', HTTP_Request2::METHOD_POST);
+ $request->setCookieJar(true);
+ $request->addCookie($testcookiekey, $testcookievalue);
+ $request->addPostParameter('submitted', '1');
+ $response = $request->send();
+ $response_body = $response->getBody();
+ $start = strpos($response_body, 'Privacy');
+ $end = strpos($response_body, 'referrer');
+ $length = $end - $start;
+ $response_body = substr($response_body, $start, $length);
+ $start = strpos($response_body, 'selected');
+ $start = $start - 3;
+ $length = 1;
+ $selected_privacy = substr($response_body, $start, $length);
+ $this->assertEquals('2', $selected_privacy);
+
+ $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=add', HTTP_Request2::METHOD_POST);
+ $request->setCookieJar(true);
+ $request->addCookie($testcookiekey, $testcookievalue);
+ $response = $request->send();
+ $response_body = $response->getBody();
+ $start = strpos($response_body, 'Privacy');
+ $end = strpos($response_body, 'referrer');
+ $length = $end - $start;
+ $response_body = substr($response_body, $start, $length);
+ $start = strpos($response_body, 'selected');
+ $start = $start - 3;
+ $length = 1;
+ $selected_privacy = substr($response_body, $start, $length);
+ $this->assertEquals('2', $selected_privacy);
+ }//end function testDefaultPrivacy
+
+
+
+}
+
+
+if (PHPUnit_MAIN_METHOD == 'BookmarkTest::main') {
+ BookmarkTest::main();
+}
+?>
--
cgit v1.2.3-54-g00ecf
From 8cbfef8115f3f219bcb5bd71b6e6566782d31c70 Mon Sep 17 00:00:00 2001
From: U-SYBASE\bdee
Date: Thu, 31 Mar 2011 13:25:37 -0700
Subject: Revert "Further updates for configurable-privacy2."
This reverts commit ef88147d453bce7d5b86ec43daad2f54447513c8.
---
data/config.php.dist | 283 ++--
data/templates/bookmarks.tpl.php | 878 ++++++------
tests/BookmarkTest.php | 2829 +++++++++++++++++++-------------------
3 files changed, 1961 insertions(+), 2029 deletions(-)
diff --git a/data/config.php.dist b/data/config.php.dist
index a8d84a6..0f849e2 100644
--- a/data/config.php.dist
+++ b/data/config.php.dist
@@ -1,138 +1,145 @@
-
- * $admin_users = array('adminnickname', 'user1nick', 'user2nick');
- *
- *
- * @var array
- */
-$admin_users = array();
-
-
-/***************************************************
- * Bookmarks
- */
-
-/**
- * Default privacy setting for bookmarks.
- * 0 - Public
- * 1 - Shared with Watchlist
- * 2 - Private
- *
- * @var integer
- */
-$defaults['privacy'] = 0;
-
-
-/**
-* You have completed the basic configuration!
-* More options can be found in config.default.php.
-*/
-?>
+
+ * $admin_users = array('adminnickname', 'user1nick', 'user2nick');
+ *
+ *
+ * @var array
+ */
+$admin_users = array();
+
+
+/***************************************************
+ * Bookmarks
+ */
+
+/**
+ * Default privacy setting for bookmarks.
+ * 0 - Public
+ * 1 - Shared with Watchlist
+ * 2 - Private
+ *
+ * @var integer
+ */
+$defaults['privacy'] = 0;
+
+
+/**
+* You have completed the basic configuration!
+* More options can be found in config.default.php.
+*/
+?>
diff --git a/data/templates/bookmarks.tpl.php b/data/templates/bookmarks.tpl.php
index b241a71..44dfe90 100644
--- a/data/templates/bookmarks.tpl.php
+++ b/data/templates/bookmarks.tpl.php
@@ -1,439 +1,439 @@
-
- * @author Christian Weiske
- * @author Eric Dane
- * @license GPL http://www.gnu.org/licenses/gpl.html
- * @link http://sourceforge.net/projects/semanticscuttle
- */
-
-/* Service creation: only useful services are created */
-$bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
-$tagservice = SemanticScuttle_Service_Factory::get('Tag');
-$cdservice = SemanticScuttle_Service_Factory::get('CommonDescription');
-
-
-$pageName = isset($pageName) ? $pageName : '';
-$user = isset($user) ? $user : '';
-$currenttag = isset($currenttag) ? $currenttag : '';
-
-
-$this->includeTemplate($GLOBALS['top_include']);
-
-include('search.menu.php');
-?>
-
-
-
-
-
-
-isAdmin($userid) && $pageName != PAGE_WATCHLIST) : ?>
-
-
-
-
-
-
-
-
-
-getLastTagDescription($currenttag)) {
- $cDescription = $cdservice->getLastTagDescription($currenttag);
- echo nl2br(filter($cDescription['cdDescription']));
-} elseif(isset($hash) && $cdservice->getLastBookmarkDescription($hash)) {
- $cDescription = $cdservice->getLastBookmarkDescription($hash);
- echo nl2br(filter($cDescription['cdTitle'])). "
";
- echo nl2br(filter($cDescription['cdDescription'])). "
";
-}
-
-//common tag description edit
-if($userservice->isLoggedOn()) {
- if($currenttag!= '' && ($GLOBALS['enableCommonTagDescriptionEditedByAll'] || $currentUser->isAdmin())) {
- echo ' ';
- echo !is_array($cDescription) || strlen($cDescription['cdDescription'])==0?T_('Edit the common description of this tag'):'';
- echo ' ';
- } elseif(isset($hash)) {
- echo ' (';
- echo T_('Edit the common description of this bookmark').')';
- }
-}
-?>
-
-
-
-getUserByUsername($user);
- if($tagservice->getDescription($currenttag, $userObject['uId'])) { ?>
-
-getDescription($currenttag, $userObject['uId']);
-echo nl2br(filter($pDescription['tDescription']));
-
-//personal tag description edit
-if($userservice->isLoggedOn()) {
- if($currenttag!= '') {
- echo ' ';
- echo strlen($pDescription['tDescription'])==0?T_('Edit your personal description of this tag'):'';
- echo ' ';
- }
-}
-?>
-
-
-
- 0) { ?>
-
-
- -
-
-
- /
-
- /
-
-
- /
-
-
-';
- echo T_('Bookmarks from other users for this tag').'';
- //echo T_(' for these tags');
- } else if ($userservice->isLoggedOn()){
- echo ' - ';
- echo '';
- echo T_('Only your bookmarks for this tag').'';
- //echo T_(' for these tags');
- }
-}
-?>
-
-'. T_('First') .'';
- $bprev = ''. T_('Previous') .'';
- } else {
- $prev = $page - 1;
- $prev = 'page='. $prev;
- $start = ($page - 1) * $perpage;
- $bfirst= ''. T_('First') .'';
- $bprev = ''. T_('Previous') .'';
- }
-
- // Next
- $next = $page + 1;
- $totalpages = ceil($total / $perpage);
- if (count($bookmarks) < $perpage || $perpage * $page == $total) {
- $bnext = ''. T_('Next') .'';
- $blast = ''. T_('Last') ."\n";
- } else {
- $bnext = ''. T_('Next') .'';
- $blast = ''. T_('Last') ."\n";
- }
-
- // RSS
- $brss = '';
- $size = count($rsschannels);
- for ($i = 0; $i < $size; $i++) {
- $brss = ''
- . ''
- . '';
- }
-
- $pagesBanner = ''. $bfirst .' / '. $bprev .' / '. $bnext .' / '. $blast .' / '. sprintf(T_('Page %d of %d'), $page, $totalpages) ." ". $brss ."
\n";
-
- if (getPerPageCount($currentUser) > 10) {
- echo $pagesBanner; // display a page banner if too many bookmarks to manage
- }
-
-
-?>
-
-
-
- 0 ? ' start="'. ++$start .'"' : ''); ?> id="bookmarks">
- &$row) {
- $addresses[$row['bId']] = $row['bAddress'];
- }
- $otherCounts = $bookmarkservice->countOthers($addresses);
- if ($userservice->isLoggedOn()) {
- $existence = $bookmarkservice->bookmarksExist(
- $addresses, $currentUser->getId()
- );
- }
-
- if ($userservice->isLoggedOn()) {
- $watchedNames = $userservice->getWatchNames(
- $currentUser->getId(), true
- );
- } else {
- $watchedNames = null;
- }
-
- foreach ($bookmarks as $key => &$row) {
- switch ($row['bStatus']) {
- case 0:
- $access = '';
- break;
- case 1:
- $access = ' shared';
- break;
- case 2:
- $access = ' private';
- break;
- }
-
- $cats = '';
- $tagsForCopy = '';
- $tags = $row['tags'];
- foreach ($tags as $tkey => &$tag) {
- $tagcaturl = sprintf(
- $cat_url,
- filter($row['username'], 'url'),
- filter($tag, 'url')
- );
- $cats .= sprintf(
- '%s, ',
- $tagcaturl, filter($tag)
- );
- $tagsForCopy .= $tag . ',';
- }
- $cats = substr($cats, 0, -2);
- if ($cats != '') {
- $cats = T_('Tags:') . ' ' . $cats;
- }
-
- // Edit and delete links
- $edit = '';
- if ($bookmarkservice->editAllowed($row)) {
- $edit = ' - '
- . T_('Edit')
- . ''
- . '';
- }
-
- // Last update
- $update = ' ('. date($GLOBALS['shortdate'], strtotime($row['bModified'])). ') ';
-
- // User attribution
- $copy = ' ' . T_('by') . ' ';
- if ($userservice->isLoggedOn()
- && $currentUser->getUsername() == $row['username']
- ) {
- $copy .= T_('you');
- } else {
- $copy .= ''
- . $row['username'] . '';
- }
-
- // Udders!
- if (!isset($hash)) {
- $others = $otherCounts[$row['bAddress']];
- $ostart = '';
- $oend = '';
- switch ($others) {
- case 0:
- break;
- case 1:
- $copy .= sprintf(T_(' and %s1 other%s'), $ostart, $oend);
- break;
- default:
- $copy .= sprintf(T_(' and %2$s%1$s others%3$s'), $others, $ostart, $oend);
- }
- }
-
- // Copy link
- if ($userservice->isLoggedOn()
- && ($currentUser->getId() != $row['uId'])
- && !$existence[$row['bAddress']]
- ) {
- $copy .= ' - '
- . T_('Copy')
- . '';
- }
-
- // Nofollow option
- $rel = '';
- if ($GLOBALS['nofollow']) {
- $rel = ' rel="nofollow"';
- }
-
- $address = filter($row['bAddress']);
- $oaddress = $address;
- // Redirection option
- if ($GLOBALS['useredir']) {
- $address = $GLOBALS['url_redir'] . $address;
- }
-
- // Admin specific design
- if ($userservice->isAdmin($row['username']) && $GLOBALS['enableAdminColors']) {
- $adminBgClass = ' class="adminBackground"';
- $adminStar = ' ';
- } else {
- $adminBgClass = '';
- $adminStar = '';
- }
-
- // Private Note (just visible by the owner and his/her contacts)
- if ($watchedNames !== null
- && ($currentUser->getId() == $row['uId']
- || in_array($row['username'], $watchedNames)
- )
- ) {
- $privateNoteField = $row['bPrivateNote'];
- } else {
- $privateNoteField = '';
- }
-
- if ($GLOBALS['enableVoting'] && $GLOBALS['hideBelowVoting'] !== null
- && $row['bVoting'] < $GLOBALS['hideBelowVoting']
- ) {
- $access .= ' below-threshold';
- }
-
- // Output
- echo ' - '."\n";
- include 'bookmarks-thumbnail.inc.tpl.php';
- include 'bookmarks-vote.inc.tpl.php';
-
- echo '
' . "\n";
-
- echo '
\n";
- if ($row['bDescription'] == '') {
- $bkDescription = $GLOBALS['blankDescription'];
- } else {
- // Improve description display (anchors, links, ...)
- $bkDescription = preg_replace('|\[\/.*?\]|', '', filter($row['bDescription'])); // remove final anchor
- $bkDescription = preg_replace('|\[(.*?)\]|', '
$1 » ', $bkDescription); // highlight starting anchor
- $bkDescription = preg_replace('@((http|https|ftp)://.*?)( |\r|$)@', '
$1$3', $bkDescription); // make url clickable
-
- }
- echo '
'. nl2br($bkDescription) ."
\n";
- echo '
' . shortenString($oaddress) . "
\n";
-
- echo '
'
- . $cats . "\n"
- . $copy . "\n"
- . $edit . "\n"
- . $update . "\n"
- . "
\n";
- echo $privateNoteField != ''
- ? '
'.$privateNoteField."
\n"
- : '';
- echo ' ';
- include 'bookmarks-vote-horizontal.inc.tpl.php';
- echo "
\n";
-
- echo " \n";
- }
- ?>
-
-
-
- 7) {
- echo ''.T_('Top of the page').'
';
- }
- echo $pagesBanner; // display previous and next links pages + RSS link
-
-
-} else {
- echo ''.T_('No bookmarks available').'
';
-}
-$this->includeTemplate('sidebar.tpl');
-$this->includeTemplate($GLOBALS['bottom_include']);
-?>
+
+ * @author Christian Weiske
+ * @author Eric Dane
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+
+/* Service creation: only useful services are created */
+$bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
+$tagservice = SemanticScuttle_Service_Factory::get('Tag');
+$cdservice = SemanticScuttle_Service_Factory::get('CommonDescription');
+
+
+$pageName = isset($pageName) ? $pageName : '';
+$user = isset($user) ? $user : '';
+$currenttag = isset($currenttag) ? $currenttag : '';
+
+
+$this->includeTemplate($GLOBALS['top_include']);
+
+include('search.menu.php');
+?>
+
+
+
+
+
+
+isAdmin($userid) && $pageName != PAGE_WATCHLIST) : ?>
+
+
+
+
+
+
+
+
+
+getLastTagDescription($currenttag)) {
+ $cDescription = $cdservice->getLastTagDescription($currenttag);
+ echo nl2br(filter($cDescription['cdDescription']));
+} elseif(isset($hash) && $cdservice->getLastBookmarkDescription($hash)) {
+ $cDescription = $cdservice->getLastBookmarkDescription($hash);
+ echo nl2br(filter($cDescription['cdTitle'])). "
";
+ echo nl2br(filter($cDescription['cdDescription'])). "
";
+}
+
+//common tag description edit
+if($userservice->isLoggedOn()) {
+ if($currenttag!= '' && ($GLOBALS['enableCommonTagDescriptionEditedByAll'] || $currentUser->isAdmin())) {
+ echo ' ';
+ echo !is_array($cDescription) || strlen($cDescription['cdDescription'])==0?T_('Edit the common description of this tag'):'';
+ echo ' ';
+ } elseif(isset($hash)) {
+ echo ' (';
+ echo T_('Edit the common description of this bookmark').')';
+ }
+}
+?>
+
+
+
+getUserByUsername($user);
+ if($tagservice->getDescription($currenttag, $userObject['uId'])) { ?>
+
+getDescription($currenttag, $userObject['uId']);
+echo nl2br(filter($pDescription['tDescription']));
+
+//personal tag description edit
+if($userservice->isLoggedOn()) {
+ if($currenttag!= '') {
+ echo ' ';
+ echo strlen($pDescription['tDescription'])==0?T_('Edit your personal description of this tag'):'';
+ echo ' ';
+ }
+}
+?>
+
+
+
+ 0) { ?>
+
+
+ -
+
+
+ /
+
+ /
+
+
+ /
+
+
+';
+ echo T_('Bookmarks from other users for this tag').'';
+ //echo T_(' for these tags');
+ } else if ($userservice->isLoggedOn()){
+ echo ' - ';
+ echo '';
+ echo T_('Only your bookmarks for this tag').'';
+ //echo T_(' for these tags');
+ }
+}
+?>
+
+'. T_('First') .'';
+ $bprev = ''. T_('Previous') .'';
+ } else {
+ $prev = $page - 1;
+ $prev = 'page='. $prev;
+ $start = ($page - 1) * $perpage;
+ $bfirst= ''. T_('First') .'';
+ $bprev = ''. T_('Previous') .'';
+ }
+
+ // Next
+ $next = $page + 1;
+ $totalpages = ceil($total / $perpage);
+ if (count($bookmarks) < $perpage || $perpage * $page == $total) {
+ $bnext = ''. T_('Next') .'';
+ $blast = ''. T_('Last') ."\n";
+ } else {
+ $bnext = ''. T_('Next') .'';
+ $blast = ''. T_('Last') ."\n";
+ }
+
+ // RSS
+ $brss = '';
+ $size = count($rsschannels);
+ for ($i = 0; $i < $size; $i++) {
+ $brss = ''
+ . ''
+ . '';
+ }
+
+ $pagesBanner = ''. $bfirst .' / '. $bprev .' / '. $bnext .' / '. $blast .' / '. sprintf(T_('Page %d of %d'), $page, $totalpages) ." ". $brss ."
\n";
+
+ if (getPerPageCount($currentUser) > 10) {
+ echo $pagesBanner; // display a page banner if too many bookmarks to manage
+ }
+
+
+?>
+
+
+
+ 0 ? ' start="'. ++$start .'"' : ''); ?> id="bookmarks">
+ &$row) {
+ $addresses[$row['bId']] = $row['bAddress'];
+ }
+ $otherCounts = $bookmarkservice->countOthers($addresses);
+ if ($userservice->isLoggedOn()) {
+ $existence = $bookmarkservice->bookmarksExist(
+ $addresses, $currentUser->getId()
+ );
+ }
+
+ if ($userservice->isLoggedOn()) {
+ $watchedNames = $userservice->getWatchNames(
+ $currentUser->getId(), true
+ );
+ } else {
+ $watchedNames = null;
+ }
+
+ foreach ($bookmarks as $key => &$row) {
+ switch ($row['bStatus']) {
+ case 0:
+ $access = ' public';
+ break;
+ case 1:
+ $access = ' shared';
+ break;
+ case 2:
+ $access = ' private';
+ break;
+ }
+
+ $cats = '';
+ $tagsForCopy = '';
+ $tags = $row['tags'];
+ foreach ($tags as $tkey => &$tag) {
+ $tagcaturl = sprintf(
+ $cat_url,
+ filter($row['username'], 'url'),
+ filter($tag, 'url')
+ );
+ $cats .= sprintf(
+ '%s, ',
+ $tagcaturl, filter($tag)
+ );
+ $tagsForCopy .= $tag . ',';
+ }
+ $cats = substr($cats, 0, -2);
+ if ($cats != '') {
+ $cats = T_('Tags:') . ' ' . $cats;
+ }
+
+ // Edit and delete links
+ $edit = '';
+ if ($bookmarkservice->editAllowed($row)) {
+ $edit = ' - '
+ . T_('Edit')
+ . ''
+ . '';
+ }
+
+ // Last update
+ $update = ' ('. date($GLOBALS['shortdate'], strtotime($row['bModified'])). ') ';
+
+ // User attribution
+ $copy = ' ' . T_('by') . ' ';
+ if ($userservice->isLoggedOn()
+ && $currentUser->getUsername() == $row['username']
+ ) {
+ $copy .= T_('you');
+ } else {
+ $copy .= ''
+ . $row['username'] . '';
+ }
+
+ // Udders!
+ if (!isset($hash)) {
+ $others = $otherCounts[$row['bAddress']];
+ $ostart = '';
+ $oend = '';
+ switch ($others) {
+ case 0:
+ break;
+ case 1:
+ $copy .= sprintf(T_(' and %s1 other%s'), $ostart, $oend);
+ break;
+ default:
+ $copy .= sprintf(T_(' and %2$s%1$s others%3$s'), $others, $ostart, $oend);
+ }
+ }
+
+ // Copy link
+ if ($userservice->isLoggedOn()
+ && ($currentUser->getId() != $row['uId'])
+ && !$existence[$row['bAddress']]
+ ) {
+ $copy .= ' - '
+ . T_('Copy')
+ . '';
+ }
+
+ // Nofollow option
+ $rel = '';
+ if ($GLOBALS['nofollow']) {
+ $rel = ' rel="nofollow"';
+ }
+
+ $address = filter($row['bAddress']);
+ $oaddress = $address;
+ // Redirection option
+ if ($GLOBALS['useredir']) {
+ $address = $GLOBALS['url_redir'] . $address;
+ }
+
+ // Admin specific design
+ if ($userservice->isAdmin($row['username']) && $GLOBALS['enableAdminColors']) {
+ $adminBgClass = ' class="adminBackground"';
+ $adminStar = ' ';
+ } else {
+ $adminBgClass = '';
+ $adminStar = '';
+ }
+
+ // Private Note (just visible by the owner and his/her contacts)
+ if ($watchedNames !== null
+ && ($currentUser->getId() == $row['uId']
+ || in_array($row['username'], $watchedNames)
+ )
+ ) {
+ $privateNoteField = $row['bPrivateNote'];
+ } else {
+ $privateNoteField = '';
+ }
+
+ if ($GLOBALS['enableVoting'] && $GLOBALS['hideBelowVoting'] !== null
+ && $row['bVoting'] < $GLOBALS['hideBelowVoting']
+ ) {
+ $access .= ' below-threshold';
+ }
+
+ // Output
+ echo ' - '."\n";
+ include 'bookmarks-thumbnail.inc.tpl.php';
+ include 'bookmarks-vote.inc.tpl.php';
+
+ echo '
' . "\n";
+
+ echo '
\n";
+ if ($row['bDescription'] == '') {
+ $bkDescription = $GLOBALS['blankDescription'];
+ } else {
+ // Improve description display (anchors, links, ...)
+ $bkDescription = preg_replace('|\[\/.*?\]|', '', filter($row['bDescription'])); // remove final anchor
+ $bkDescription = preg_replace('|\[(.*?)\]|', '
$1 » ', $bkDescription); // highlight starting anchor
+ $bkDescription = preg_replace('@((http|https|ftp)://.*?)( |\r|$)@', '
$1$3', $bkDescription); // make url clickable
+
+ }
+ echo '
'. nl2br($bkDescription) ."
\n";
+ echo '
' . shortenString($oaddress) . "
\n";
+
+ echo '
'
+ . $cats . "\n"
+ . $copy . "\n"
+ . $edit . "\n"
+ . $update . "\n"
+ . "
\n";
+ echo $privateNoteField != ''
+ ? '
'.$privateNoteField."
\n"
+ : '';
+ echo ' ';
+ include 'bookmarks-vote-horizontal.inc.tpl.php';
+ echo "
\n";
+
+ echo " \n";
+ }
+ ?>
+
+
+
+ 7) {
+ echo ''.T_('Top of the page').'
';
+ }
+ echo $pagesBanner; // display previous and next links pages + RSS link
+
+
+} else {
+ echo ''.T_('No bookmarks available').'
';
+}
+$this->includeTemplate('sidebar.tpl');
+$this->includeTemplate($GLOBALS['bottom_include']);
+?>
diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php
index 0912d55..aa0b8c3 100644
--- a/tests/BookmarkTest.php
+++ b/tests/BookmarkTest.php
@@ -1,1452 +1,1377 @@
-
- * @author Christian Weiske
- * @author Eric Dane
- * @license GPL http://www.gnu.org/licenses/gpl.html
- * @link http://sourceforge.net/projects/semanticscuttle
- */
-if (!defined('PHPUnit_MAIN_METHOD')) {
- define('PHPUnit_MAIN_METHOD', 'BookmarkTest::main');
-}
-
-require_once 'prepare.php';
-
-/**
- * Unit tests for the SemanticScuttle bookmark service.
- *
- * @category Bookmarking
- * @package SemanticScuttle
- * @author Benjamin Huynh-Kim-Bang
- * @author Christian Weiske
- * @author Eric Dane
- * @license GPL http://www.gnu.org/licenses/gpl.html
- * @link http://sourceforge.net/projects/semanticscuttle
- */
-class BookmarkTest extends TestBase
-{
- protected $us;
- protected $bs;
- protected $ts;
- protected $tts;
-
-
-
- /**
- * 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__)
- );
- }
-
-
-
- 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();
- }
-
- /**
- * Tests if adding a bookmark with short url name
- * saves it in the database.
- *
- * @return void
- */
- public function testAddBookmarkShort()
- {
- $bid = $this->bs->addBookmark(
- 'http://example.org', 'title', 'desc', 'priv',
- 0, array(), 'myShortName'
- );
- $bm = $this->bs->getBookmark($bid);
- $this->assertEquals('http://example.org', $bm['bAddress']);
- $this->assertArrayHasKey('bShort', $bm);
- $this->assertEquals('myShortName', $bm['bShort']);
- }
-
- public function testHardCharactersInBookmarks()
- {
- $bs = $this->bs;
- $title = "title&é\"'(-è_çà)=";
- $desc = "description#{[|`\^@]}³<> ¹¡÷׿&é\"'(-è\\_çà)=";
- $tag1 = "#{|`^@]³¹¡¿<&é\"'(-è\\_çà)";
- $tag2 = "&é\"'(-è.[?./§!_çà)";
-
- $uid = $this->addUser();
- $bid = $bs->addBookmark(
- 'http://site1.com', $title, $desc, 'note',
- 0, array($tag1, $tag2),
- null, null, false, false, $uid
- );
-
- $bookmarks = $bs->getBookmarks(0, 1);
-
- $b0 = $bookmarks['bookmarks'][0];
- $this->assertEquals($title, $b0['bTitle']);
- $this->assertEquals($desc, $b0['bDescription']);
- $this->assertEquals(
- str_replace(array('"', '\'', '/'), "_", $tag1),
- $b0['tags'][0]
- );
- $this->assertEquals(
- str_replace(array('"', '\'', '/'), "_", $tag2),
- $b0['tags'][1]
- );
- }
-
- public function testUnificationOfBookmarks()
- {
- $bs = $this->bs;
-
- $uid = $this->addUser();
- $uid2 = $this->addUser();
-
- $bs->addBookmark(
- 'http://site1.com', "title", "description", 'note',
- 0, array('tag1'), null, null, false, false,
- $uid
- );
- $bs->addBookmark(
- "http://site1.com", "title2", "description2", 'note',
- 0, array('tag2'), null, null, false, false,
- $uid2
- );
-
- $bookmarks = $bs->getBookmarks();
- $this->assertEquals(1, $bookmarks['total']);
- }
-
- /*public function testSearchingBookmarksAccentsInsensible()
- {
- $bs = $this->bs;
-
- $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']);
- }*/
-
-
-
- /**
- * Tests if bookmarkExists() returns false when the given
- * parameter is invalid.
- *
- * @return void
- */
- public function testBookmarkExistsInvalidParam()
- {
- $this->assertFalse($this->bs->bookmarkExists(false));
- $this->assertFalse($this->bs->bookmarkExists(null));
- }
-
-
-
- /**
- * Tests if bookmarkExists() returns true when a bookmark
- * exists
- *
- * @return void
- */
- public function testBookmarkExistsTrue()
- {
- $bid = $this->addBookmark();
- $bookmark = $this->bs->getBookmark($bid);
-
- $this->assertTrue($this->bs->bookmarkExists($bookmark['bAddress']));
- }
-
-
-
- /**
- * Tests if bookmarkExists() returns false when a bookmark
- * does not exist
- *
- * @return void
- */
- public function testBookmarkExistsFalse()
- {
- $this->assertFalse($this->bs->bookmarkExists('does-not-exist'));
- }
-
-
-
- /**
- * Tests if bookmarkExists() returns true when a bookmark
- * exists for a user
- *
- * @return void
- */
- public function testBookmarkExistsUserTrue()
- {
- $bid = $this->addBookmark();
- $bookmark = $this->bs->getBookmark($bid);
-
- $this->assertTrue(
- $this->bs->bookmarkExists(
- $bookmark['bAddress'],
- $bookmark['uId']
- )
- );
- }
-
-
-
- /**
- * Tests if bookmarkExists() returns false when a bookmark
- * does not exist for a user
- *
- * @return void
- */
- public function testBookmarkExistsUserFalse()
- {
- $this->assertFalse(
- $this->bs->bookmarkExists('does-not-exist', 1234)
- );
- }
-
-
-
- /**
- * Tests if bookmarkExists() returns false when a bookmark
- * does not exist for a user but for another user
- *
- * @return void
- */
- public function testBookmarkExistsOtherUser()
- {
- $bid = $this->addBookmark();
- $bookmark = $this->bs->getBookmark($bid);
-
- $this->assertFalse(
- $this->bs->bookmarkExists(
- $bookmark['bAddress'],
- $bookmark['uId'] + 1
- )
- );
- }
-
-
-
- /**
- * 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->assertInternalType('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->assertInternalType('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->assertInternalType('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->assertInternalType('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);
-
- //do not search for this one
- $bid3 = $this->addBookmark();
- $bookmark3 = $this->bs->getBookmark($bid3);
-
-
- $ret = $this->bs->bookmarksExist(
- array(
- $bookmark['bAddress'],
- 'does-not-exist',
- $bookmark2['bAddress'],
- 'does-not-exist-2',
- 'does-not-exist-3'
- )
- );
- $this->assertInternalType('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
- *
- * @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'));
- $this->assertEquals(0, $this->bs->countBookmarks($uid, 'all'));
- }
-
-
-
- /**
- * 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'));
- $this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));
- }
-
-
-
- /**
- * 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, 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'));
- $this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));
- }
-
-
-
- /**
- * 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, 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'));
- $this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));
- }
-
-
-
- /**
- * 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->assertInternalType('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.
- *
- * @return void
- */
- public function testDeleteBookmark()
- {
- $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 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
- */
- public function testDeleteBookmarkWithVote()
- {
- $GLOBALS['enableVoting'] = true;
-
- $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));
- }
-
-
-
- /**
- * Test if editAllowed() returns false when the bookmark
- * id is invalid.
- *
- * @return void
- */
- public function testEditAllowedInvalidBookmarkId()
- {
- $this->assertFalse($this->bs->editAllowed('invalid'));
- $this->assertFalse($this->bs->editAllowed(array()));
- $this->assertFalse($this->bs->editAllowed(array('some', 'where')));
- $this->assertFalse($this->bs->editAllowed(array('bId' => false)));
- $this->assertFalse($this->bs->editAllowed(array('bId' => 'foo')));
- }
-
-
-
- /**
- * Test if editAllowed() works when passing the ID of
- * an existing bookmark.
- *
- * @return void
- */
- public function testEditAllowedBookmarkId()
- {
- $uid = $this->addUser();
- $bid = $this->addBookmark($uid);
- $this->us->setCurrentUserId($uid);
- $this->assertTrue($this->bs->editAllowed($bid));
- }
-
-
-
- /**
- * Test if editAllowed() works when passing the ID of
- * an existing bookmark that does not belong to the current
- * user.
- *
- * @return void
- */
- public function testEditAllowedBookmarkIdNotOwn()
- {
- $uid = $this->addUser();
- $bid = $this->addBookmark();
- $this->us->setCurrentUserId($uid);
- $this->assertFalse($this->bs->editAllowed($bid));
- }
-
-
-
- /**
- * Test if editAllowed() works when passing the ID of
- * an existing bookmark that does not belong to the current
- * user.
- *
- * @return void
- */
- public function testEditAllowedBookmarkIdNoUser()
- {
- $bid = $this->addBookmark();
- $this->us->setCurrentUserId(null);
- $this->assertFalse($this->bs->editAllowed($bid));
- }
-
-
-
- /**
- * Test if editAllowed() works when passing a bookmark
- * row.
- *
- * @return void
- */
- public function testEditAllowedBookmarkRow()
- {
- $uid = $this->addUser();
- $this->us->setCurrentUserId($uid);
-
- $bid = $this->addBookmark($uid);
- $bookmark = $this->bs->getBookmark($bid);
- $this->assertTrue($this->bs->editAllowed($bookmark));
- }
-
-
-
- /**
- * Test if editAllowed() returns false when the bookmark
- * specified by the ID does not exist.
- *
- * @return void
- */
- public function testEditAllowedIdNotFound()
- {
- $this->assertFalse($this->bs->editAllowed(98765));
- }
-
-
-
- /**
- * Test if editAllowed() works when the user is an administrator.
- *
- * @return void
- */
- public function testEditAllowedBookmarkAdmin()
- {
- //make the user admin
- $uid = $this->addUser();
- $user = $this->us->getUser($uid);
- $GLOBALS['admin_users'][] = $user['username'];
-
- $bid = $this->addBookmark($uid);
- $this->us->setCurrentUserId($uid);
- $this->assertTrue($this->bs->editAllowed($bid));
- }
-
-
-
- /**
- * 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->assertInternalType('array', $bm['tags']);
- $this->assertContains('foo', $bm['tags']);
- $this->assertContains('bar', $bm['tags']);
- }
-
-
-
- /**
- * Verify that getBookmark() does not include user voting
- * data when no user is logged on.
- *
- * @return void
- */
- public function testGetBookmarkUserVotingNoUser()
- {
- $GLOBALS['enableVoting'] = true;
-
- $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()
- {
- $GLOBALS['enableVoting'] = true;
-
- $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()
- {
- $GLOBALS['enableVoting'] = true;
-
- $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()
- {
- $GLOBALS['enableVoting'] = true;
-
- $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']);
- }
-
-
-
- /**
- * 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->assertInternalType('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->assertInternalType('array', $bm);
- $this->assertEquals($url, $bm['bAddress']);
- }
-
-
-
- public function testNormalize()
- {
- $this->assertEquals(
- 'http://example.org', $this->bs->normalize('http://example.org')
- );
- $this->assertEquals(
- 'ftp://example.org', $this->bs->normalize('ftp://example.org')
- );
- $this->assertEquals(
- 'http://example.org', $this->bs->normalize('http://example.org/')
- );
- $this->assertEquals(
- 'http://example.org', $this->bs->normalize('example.org')
- );
- $this->assertEquals(
- 'mailto:foo@example.org',
- $this->bs->normalize('mailto:foo@example.org')
- );
- }
-
-
-
- /**
- * test if updating an existing bookmark works
- */
- public function testUpdateBookmark()
- {
- $bid = $this->addBookmark();
- $this->assertTrue(
- $this->bs->updateBookmark(
- $bid,
- 'http://example.org/foo',
- 'my new title',
- 'new description',
- 'new private note',
- 1,
- array('new')
- )
- );
- $bm = $this->bs->getBookmark($bid, true);
- $this->assertEquals('http://example.org/foo', $bm['bAddress']);
- $this->assertEquals('my new title', $bm['bTitle']);
- $this->assertEquals('new description', $bm['bDescription']);
- $this->assertEquals('new private note', $bm['bPrivateNote']);
- $this->assertEquals(1, $bm['bStatus']);
- $this->assertInternalType('array', $bm['tags']);
- $this->assertEquals(1, count($bm['tags']));
- $this->assertContains('new', $bm['tags']);
- }
-
- /**
- * Tests if updating a bookmark's short url name
- * saves it in the database.
- *
- * @return void
- */
- public function testUpdateBookmarkShort()
- {
- $bid = $this->bs->addBookmark(
- 'http://example.org', 'title', 'desc', 'priv',
- 0, array(), 'myShortName'
- );
- $bm = $this->bs->getBookmark($bid);
- $this->assertEquals('myShortName', $bm['bShort']);
-
- $this->assertTrue(
- $this->bs->updateBookmark(
- $bid, 'http://example2.org', 'my title', 'desc',
- 'priv', 0, array(), 'newShortNambb'
- )
- );
- $bm = $this->bs->getBookmark($bid);
- $this->assertEquals('newShortNambb', $bm['bShort']);
- }
-
- /**
- * Tests if updating a bookmark's date works.
- * This once was a bug, see bug #3073215.
- *
- * @return void
- *
- * @link https://sourceforge.net/tracker/?func=detail&atid=1017430&aid=3073215&group_id=211356
- */
- public function testUpdateBookmarkDate()
- {
- $bid = $this->bs->addBookmark(
- 'http://example.org', 'title', 'desc', 'priv',
- 0, array(), 'myShortName'
- );
- $bm = $this->bs->getBookmark($bid);
- $this->assertEquals('myShortName', $bm['bShort']);
-
- $this->assertTrue(
- $this->bs->updateBookmark(
- $bid, 'http://example2.org', 'my title', 'desc',
- 'priv', 0, array(), 'newShortNambb',
- //we need to use zulu (GMT) time zone here
- // since the dates/times are stored as that
- // in the database
- '2002-03-04T05:06:07Z'
- )
- );
- $bm = $this->bs->getBookmark($bid);
- $this->assertEquals('newShortNambb', $bm['bShort']);
- $this->assertEquals('2002-03-04 05:06:07', $bm['bDatetime']);
- }
-
-
-
- /**
- * 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 a friend (people on the watchlist) has bookmarked
- * and the same address with public status.
- *
- * @return void
- */
- public function testCountOthersWatchlistPublic()
- {
- $uid = $this->addUser();
- $address = 'http://example.org';
-
- //create other user and add main user to his watchlist
- $friendPublic1 = $this->addUser();
- $this->us->setCurrentUserId($friendPublic1);
- $this->us->setWatchStatus($uid);
-
- //create bookmarks for main user and other one
- $this->addBookmark($uid, $address, 0);
- $this->addBookmark($friendPublic1, $address, 0);//0 is public
-
- //log main user in
- $this->us->setCurrentUserId($uid);
-
- $this->assertEquals(1, $this->bs->countOthers($address));
- }
-
-
-
- /**
- * Test what countOther() returns when the user is logged in
- * and a friend (people on the watchlist) has bookmarked
- * and shared the same address for the watchlist.
- *
- * @return void
- */
- public function testCountOthersWatchlistShared()
- {
- $uid = $this->addUser();
- $address = 'http://example.org';
-
- //create other user and add main user to his watchlist
- $friendPublic1 = $this->addUser();
- $this->us->setCurrentUserId($friendPublic1);
- $this->us->setWatchStatus($uid);
-
- //create bookmarks for main user and other one
- $this->addBookmark($uid, $address, 0);
- $this->addBookmark($friendPublic1, $address, 1);//1 is shared
-
- //log main user in
- $this->us->setCurrentUserId($uid);
-
- $this->assertEquals(1, $this->bs->countOthers($address));
- }
-
-
-
- /**
- * Test what countOther() returns when the user is logged in
- * and one friends (people on the watchlist) has bookmarked
- * the same address but made it private.
- *
- * @return void
- */
- public function testCountOthersWatchlistPrivate()
- {
- $uid = $this->addUser();
- $address = 'http://example.org';
-
- //create other user and add main user to his watchlist
- $friendPublic1 = $this->addUser();
- $this->us->setCurrentUserId($friendPublic1);
- $this->us->setWatchStatus($uid);
-
- //create bookmarks for main user and other one
- $this->addBookmark($uid, $address, 0);
- $this->addBookmark($friendPublic1, $address, 2);//2 is private
-
- //log main user in
- $this->us->setCurrentUserId($uid);
-
- $this->assertEquals(0, $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 testCountOthersWatchlistComplex()
- {
- $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));
- }
-
-
-
- /**
- * 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)
- )
- );
- }
-
-
- /**
- * Test that the default privacy setting in
- * $GLOBALS['defaults']['privacy'] is used
- * as expected.
- *
- * @return void
- */
- public function testDefaultPrivacy()
- {
- //For this test, the default privacy has been set to 2 (private) in the configuration file.
- require_once 'HTTP/Request2.php';
- require_once dirname(__FILE__) . '/../data/config.php';
- $this->bs->deleteAll();
- $this->us->deleteAll();
- $request = new HTTP_Request2('http://localhost/api/posts_add.php', HTTP_Request2::METHOD_POST);
- $dpuid = $this->addUser('dpuser', 'dpuserpassword');
- $request->setAuth('dpuser', 'dpuserpassword');
- $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com');
- $request->addPostParameter('description', 'Test bookmark 1 for default privacy.');
- $request->send();
- $bm = $this->bs->getBookmark('1');
- $this->assertEquals('2', $bm['bStatus']);
-
- $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add2.com');
- $request->addPostParameter('description', 'Test bookmark 2 for default privacy.');
- $request->addPostParameter('status', '0');
- $request->send();
-
- $request = new HTTP_Request2('http://localhost/edit.php/2', HTTP_Request2::METHOD_POST);
- $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
- $userinfo = $this->us->getUser('1');
- $testcookiepassword = $userinfo['password'];
- $testcookievalue = '1:'.md5('dpuser'.$testcookiepassword);
- $request->setCookieJar(true);
- $request->addCookie($testcookiekey, $testcookievalue);
- $request->addPostParameter('title', 'Test bookmark 2 for default privacy.');
- $request->addPostParameter('address', 'http://www.testdefaultprivacyposts_add2.com');
- $request->addPostParameter('submitted', '1');
- $request->send();
- $bm = $this->bs->getBookmark('2');
- $this->assertEquals('2', $bm['bStatus']);
-
- $request = new HTTP_Request2('http://localhost/importNetscape.php', HTTP_Request2::METHOD_POST);
- $request->setCookieJar(true);
- $request->addCookie($testcookiekey, $testcookievalue);
- $request->addUpload('userfile', './data/BookmarkTest_netscapebookmarks.html');
- $request->send();
- $bm = $this->bs->getBookmark('3');
- $this->assertEquals('2', $bm['bStatus']);
- $bm = $this->bs->getBookmark('4');
- $this->assertEquals('2', $bm['bStatus']);
- $bm = $this->bs->getBookmark('5');
- $this->assertEquals('2', $bm['bStatus']);
-
- $request = new HTTP_Request2('http://localhost/import.php', HTTP_Request2::METHOD_POST);
- $request->setCookieJar(true);
- $request->addCookie($testcookiekey, $testcookievalue);
- $request->addUpload('userfile', './data/BookmarkTest_deliciousbookmarks.xml');
- $request->send();
- $bm = $this->bs->getBookmark('6');
- $this->assertEquals('2', $bm['bStatus']);
- $bm = $this->bs->getBookmark('7');
- $this->assertEquals('2', $bm['bStatus']);
- $bm = $this->bs->getBookmark('8');
- $this->assertEquals('2', $bm['bStatus']);
-
- $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=get', HTTP_Request2::METHOD_POST);
- $request->setCookieJar(true);
- $request->addCookie($testcookiekey, $testcookievalue);
- $request->addPostParameter('submitted', '1');
- $response = $request->send();
- $response_body = $response->getBody();
- $start = strpos($response_body, 'Privacy');
- $end = strpos($response_body, 'referrer');
- $length = $end - $start;
- $response_body = substr($response_body, $start, $length);
- $start = strpos($response_body, 'selected');
- $start = $start - 3;
- $length = 1;
- $selected_privacy = substr($response_body, $start, $length);
- $this->assertEquals('2', $selected_privacy);
-
- $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=add', HTTP_Request2::METHOD_POST);
- $request->setCookieJar(true);
- $request->addCookie($testcookiekey, $testcookievalue);
- $response = $request->send();
- $response_body = $response->getBody();
- $start = strpos($response_body, 'Privacy');
- $end = strpos($response_body, 'referrer');
- $length = $end - $start;
- $response_body = substr($response_body, $start, $length);
- $start = strpos($response_body, 'selected');
- $start = $start - 3;
- $length = 1;
- $selected_privacy = substr($response_body, $start, $length);
- $this->assertEquals('2', $selected_privacy);
- }//end function testDefaultPrivacy
-
-
-
-}
-
-
-if (PHPUnit_MAIN_METHOD == 'BookmarkTest::main') {
- BookmarkTest::main();
-}
-?>
+
+ * @author Christian Weiske
+ * @author Eric Dane
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+if (!defined('PHPUnit_MAIN_METHOD')) {
+ define('PHPUnit_MAIN_METHOD', 'BookmarkTest::main');
+}
+
+require_once 'prepare.php';
+
+/**
+ * Unit tests for the SemanticScuttle bookmark service.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Benjamin Huynh-Kim-Bang
+ * @author Christian Weiske
+ * @author Eric Dane
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+class BookmarkTest extends TestBase
+{
+ protected $us;
+ protected $bs;
+ protected $ts;
+ protected $tts;
+
+
+
+ /**
+ * 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__)
+ );
+ }
+
+
+
+ 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();
+ }
+
+ /**
+ * Tests if adding a bookmark with short url name
+ * saves it in the database.
+ *
+ * @return void
+ */
+ public function testAddBookmarkShort()
+ {
+ $bid = $this->bs->addBookmark(
+ 'http://example.org', 'title', 'desc', 'priv',
+ 0, array(), 'myShortName'
+ );
+ $bm = $this->bs->getBookmark($bid);
+ $this->assertEquals('http://example.org', $bm['bAddress']);
+ $this->assertArrayHasKey('bShort', $bm);
+ $this->assertEquals('myShortName', $bm['bShort']);
+ }
+
+ public function testHardCharactersInBookmarks()
+ {
+ $bs = $this->bs;
+ $title = "title&é\"'(-è_çà)=";
+ $desc = "description#{[|`\^@]}³<> ¹¡÷׿&é\"'(-è\\_çà)=";
+ $tag1 = "#{|`^@]³¹¡¿<&é\"'(-è\\_çà)";
+ $tag2 = "&é\"'(-è.[?./§!_çà)";
+
+ $uid = $this->addUser();
+ $bid = $bs->addBookmark(
+ 'http://site1.com', $title, $desc, 'note',
+ 0, array($tag1, $tag2),
+ null, null, false, false, $uid
+ );
+
+ $bookmarks = $bs->getBookmarks(0, 1);
+
+ $b0 = $bookmarks['bookmarks'][0];
+ $this->assertEquals($title, $b0['bTitle']);
+ $this->assertEquals($desc, $b0['bDescription']);
+ $this->assertEquals(
+ str_replace(array('"', '\'', '/'), "_", $tag1),
+ $b0['tags'][0]
+ );
+ $this->assertEquals(
+ str_replace(array('"', '\'', '/'), "_", $tag2),
+ $b0['tags'][1]
+ );
+ }
+
+ public function testUnificationOfBookmarks()
+ {
+ $bs = $this->bs;
+
+ $uid = $this->addUser();
+ $uid2 = $this->addUser();
+
+ $bs->addBookmark(
+ 'http://site1.com', "title", "description", 'note',
+ 0, array('tag1'), null, null, false, false,
+ $uid
+ );
+ $bs->addBookmark(
+ "http://site1.com", "title2", "description2", 'note',
+ 0, array('tag2'), null, null, false, false,
+ $uid2
+ );
+
+ $bookmarks = $bs->getBookmarks();
+ $this->assertEquals(1, $bookmarks['total']);
+ }
+
+ /*public function testSearchingBookmarksAccentsInsensible()
+ {
+ $bs = $this->bs;
+
+ $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']);
+ }*/
+
+
+
+ /**
+ * Tests if bookmarkExists() returns false when the given
+ * parameter is invalid.
+ *
+ * @return void
+ */
+ public function testBookmarkExistsInvalidParam()
+ {
+ $this->assertFalse($this->bs->bookmarkExists(false));
+ $this->assertFalse($this->bs->bookmarkExists(null));
+ }
+
+
+
+ /**
+ * Tests if bookmarkExists() returns true when a bookmark
+ * exists
+ *
+ * @return void
+ */
+ public function testBookmarkExistsTrue()
+ {
+ $bid = $this->addBookmark();
+ $bookmark = $this->bs->getBookmark($bid);
+
+ $this->assertTrue($this->bs->bookmarkExists($bookmark['bAddress']));
+ }
+
+
+
+ /**
+ * Tests if bookmarkExists() returns false when a bookmark
+ * does not exist
+ *
+ * @return void
+ */
+ public function testBookmarkExistsFalse()
+ {
+ $this->assertFalse($this->bs->bookmarkExists('does-not-exist'));
+ }
+
+
+
+ /**
+ * Tests if bookmarkExists() returns true when a bookmark
+ * exists for a user
+ *
+ * @return void
+ */
+ public function testBookmarkExistsUserTrue()
+ {
+ $bid = $this->addBookmark();
+ $bookmark = $this->bs->getBookmark($bid);
+
+ $this->assertTrue(
+ $this->bs->bookmarkExists(
+ $bookmark['bAddress'],
+ $bookmark['uId']
+ )
+ );
+ }
+
+
+
+ /**
+ * Tests if bookmarkExists() returns false when a bookmark
+ * does not exist for a user
+ *
+ * @return void
+ */
+ public function testBookmarkExistsUserFalse()
+ {
+ $this->assertFalse(
+ $this->bs->bookmarkExists('does-not-exist', 1234)
+ );
+ }
+
+
+
+ /**
+ * Tests if bookmarkExists() returns false when a bookmark
+ * does not exist for a user but for another user
+ *
+ * @return void
+ */
+ public function testBookmarkExistsOtherUser()
+ {
+ $bid = $this->addBookmark();
+ $bookmark = $this->bs->getBookmark($bid);
+
+ $this->assertFalse(
+ $this->bs->bookmarkExists(
+ $bookmark['bAddress'],
+ $bookmark['uId'] + 1
+ )
+ );
+ }
+
+
+
+ /**
+ * 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->assertInternalType('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->assertInternalType('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->assertInternalType('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->assertInternalType('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);
+
+ //do not search for this one
+ $bid3 = $this->addBookmark();
+ $bookmark3 = $this->bs->getBookmark($bid3);
+
+
+ $ret = $this->bs->bookmarksExist(
+ array(
+ $bookmark['bAddress'],
+ 'does-not-exist',
+ $bookmark2['bAddress'],
+ 'does-not-exist-2',
+ 'does-not-exist-3'
+ )
+ );
+ $this->assertInternalType('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
+ *
+ * @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'));
+ $this->assertEquals(0, $this->bs->countBookmarks($uid, 'all'));
+ }
+
+
+
+ /**
+ * 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'));
+ $this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));
+ }
+
+
+
+ /**
+ * 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, 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'));
+ $this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));
+ }
+
+
+
+ /**
+ * 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, 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'));
+ $this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));
+ }
+
+
+
+ /**
+ * 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->assertInternalType('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.
+ *
+ * @return void
+ */
+ public function testDeleteBookmark()
+ {
+ $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 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
+ */
+ public function testDeleteBookmarkWithVote()
+ {
+ $GLOBALS['enableVoting'] = true;
+
+ $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));
+ }
+
+
+
+ /**
+ * Test if editAllowed() returns false when the bookmark
+ * id is invalid.
+ *
+ * @return void
+ */
+ public function testEditAllowedInvalidBookmarkId()
+ {
+ $this->assertFalse($this->bs->editAllowed('invalid'));
+ $this->assertFalse($this->bs->editAllowed(array()));
+ $this->assertFalse($this->bs->editAllowed(array('some', 'where')));
+ $this->assertFalse($this->bs->editAllowed(array('bId' => false)));
+ $this->assertFalse($this->bs->editAllowed(array('bId' => 'foo')));
+ }
+
+
+
+ /**
+ * Test if editAllowed() works when passing the ID of
+ * an existing bookmark.
+ *
+ * @return void
+ */
+ public function testEditAllowedBookmarkId()
+ {
+ $uid = $this->addUser();
+ $bid = $this->addBookmark($uid);
+ $this->us->setCurrentUserId($uid);
+ $this->assertTrue($this->bs->editAllowed($bid));
+ }
+
+
+
+ /**
+ * Test if editAllowed() works when passing the ID of
+ * an existing bookmark that does not belong to the current
+ * user.
+ *
+ * @return void
+ */
+ public function testEditAllowedBookmarkIdNotOwn()
+ {
+ $uid = $this->addUser();
+ $bid = $this->addBookmark();
+ $this->us->setCurrentUserId($uid);
+ $this->assertFalse($this->bs->editAllowed($bid));
+ }
+
+
+
+ /**
+ * Test if editAllowed() works when passing the ID of
+ * an existing bookmark that does not belong to the current
+ * user.
+ *
+ * @return void
+ */
+ public function testEditAllowedBookmarkIdNoUser()
+ {
+ $bid = $this->addBookmark();
+ $this->us->setCurrentUserId(null);
+ $this->assertFalse($this->bs->editAllowed($bid));
+ }
+
+
+
+ /**
+ * Test if editAllowed() works when passing a bookmark
+ * row.
+ *
+ * @return void
+ */
+ public function testEditAllowedBookmarkRow()
+ {
+ $uid = $this->addUser();
+ $this->us->setCurrentUserId($uid);
+
+ $bid = $this->addBookmark($uid);
+ $bookmark = $this->bs->getBookmark($bid);
+ $this->assertTrue($this->bs->editAllowed($bookmark));
+ }
+
+
+
+ /**
+ * Test if editAllowed() returns false when the bookmark
+ * specified by the ID does not exist.
+ *
+ * @return void
+ */
+ public function testEditAllowedIdNotFound()
+ {
+ $this->assertFalse($this->bs->editAllowed(98765));
+ }
+
+
+
+ /**
+ * Test if editAllowed() works when the user is an administrator.
+ *
+ * @return void
+ */
+ public function testEditAllowedBookmarkAdmin()
+ {
+ //make the user admin
+ $uid = $this->addUser();
+ $user = $this->us->getUser($uid);
+ $GLOBALS['admin_users'][] = $user['username'];
+
+ $bid = $this->addBookmark($uid);
+ $this->us->setCurrentUserId($uid);
+ $this->assertTrue($this->bs->editAllowed($bid));
+ }
+
+
+
+ /**
+ * 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->assertInternalType('array', $bm['tags']);
+ $this->assertContains('foo', $bm['tags']);
+ $this->assertContains('bar', $bm['tags']);
+ }
+
+
+
+ /**
+ * Verify that getBookmark() does not include user voting
+ * data when no user is logged on.
+ *
+ * @return void
+ */
+ public function testGetBookmarkUserVotingNoUser()
+ {
+ $GLOBALS['enableVoting'] = true;
+
+ $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()
+ {
+ $GLOBALS['enableVoting'] = true;
+
+ $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()
+ {
+ $GLOBALS['enableVoting'] = true;
+
+ $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()
+ {
+ $GLOBALS['enableVoting'] = true;
+
+ $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']);
+ }
+
+
+
+ /**
+ * 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->assertInternalType('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->assertInternalType('array', $bm);
+ $this->assertEquals($url, $bm['bAddress']);
+ }
+
+
+
+ public function testNormalize()
+ {
+ $this->assertEquals(
+ 'http://example.org', $this->bs->normalize('http://example.org')
+ );
+ $this->assertEquals(
+ 'ftp://example.org', $this->bs->normalize('ftp://example.org')
+ );
+ $this->assertEquals(
+ 'http://example.org', $this->bs->normalize('http://example.org/')
+ );
+ $this->assertEquals(
+ 'http://example.org', $this->bs->normalize('example.org')
+ );
+ $this->assertEquals(
+ 'mailto:foo@example.org',
+ $this->bs->normalize('mailto:foo@example.org')
+ );
+ }
+
+
+
+ /**
+ * test if updating an existing bookmark works
+ */
+ public function testUpdateBookmark()
+ {
+ $bid = $this->addBookmark();
+ $this->assertTrue(
+ $this->bs->updateBookmark(
+ $bid,
+ 'http://example.org/foo',
+ 'my new title',
+ 'new description',
+ 'new private note',
+ 1,
+ array('new')
+ )
+ );
+ $bm = $this->bs->getBookmark($bid, true);
+ $this->assertEquals('http://example.org/foo', $bm['bAddress']);
+ $this->assertEquals('my new title', $bm['bTitle']);
+ $this->assertEquals('new description', $bm['bDescription']);
+ $this->assertEquals('new private note', $bm['bPrivateNote']);
+ $this->assertEquals(1, $bm['bStatus']);
+ $this->assertInternalType('array', $bm['tags']);
+ $this->assertEquals(1, count($bm['tags']));
+ $this->assertContains('new', $bm['tags']);
+ }
+
+ /**
+ * Tests if updating a bookmark's short url name
+ * saves it in the database.
+ *
+ * @return void
+ */
+ public function testUpdateBookmarkShort()
+ {
+ $bid = $this->bs->addBookmark(
+ 'http://example.org', 'title', 'desc', 'priv',
+ 0, array(), 'myShortName'
+ );
+ $bm = $this->bs->getBookmark($bid);
+ $this->assertEquals('myShortName', $bm['bShort']);
+
+ $this->assertTrue(
+ $this->bs->updateBookmark(
+ $bid, 'http://example2.org', 'my title', 'desc',
+ 'priv', 0, array(), 'newShortNambb'
+ )
+ );
+ $bm = $this->bs->getBookmark($bid);
+ $this->assertEquals('newShortNambb', $bm['bShort']);
+ }
+
+ /**
+ * Tests if updating a bookmark's date works.
+ * This once was a bug, see bug #3073215.
+ *
+ * @return void
+ *
+ * @link https://sourceforge.net/tracker/?func=detail&atid=1017430&aid=3073215&group_id=211356
+ */
+ public function testUpdateBookmarkDate()
+ {
+ $bid = $this->bs->addBookmark(
+ 'http://example.org', 'title', 'desc', 'priv',
+ 0, array(), 'myShortName'
+ );
+ $bm = $this->bs->getBookmark($bid);
+ $this->assertEquals('myShortName', $bm['bShort']);
+
+ $this->assertTrue(
+ $this->bs->updateBookmark(
+ $bid, 'http://example2.org', 'my title', 'desc',
+ 'priv', 0, array(), 'newShortNambb',
+ //we need to use zulu (GMT) time zone here
+ // since the dates/times are stored as that
+ // in the database
+ '2002-03-04T05:06:07Z'
+ )
+ );
+ $bm = $this->bs->getBookmark($bid);
+ $this->assertEquals('newShortNambb', $bm['bShort']);
+ $this->assertEquals('2002-03-04 05:06:07', $bm['bDatetime']);
+ }
+
+
+
+ /**
+ * 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 a friend (people on the watchlist) has bookmarked
+ * and the same address with public status.
+ *
+ * @return void
+ */
+ public function testCountOthersWatchlistPublic()
+ {
+ $uid = $this->addUser();
+ $address = 'http://example.org';
+
+ //create other user and add main user to his watchlist
+ $friendPublic1 = $this->addUser();
+ $this->us->setCurrentUserId($friendPublic1);
+ $this->us->setWatchStatus($uid);
+
+ //create bookmarks for main user and other one
+ $this->addBookmark($uid, $address, 0);
+ $this->addBookmark($friendPublic1, $address, 0);//0 is public
+
+ //log main user in
+ $this->us->setCurrentUserId($uid);
+
+ $this->assertEquals(1, $this->bs->countOthers($address));
+ }
+
+
+
+ /**
+ * Test what countOther() returns when the user is logged in
+ * and a friend (people on the watchlist) has bookmarked
+ * and shared the same address for the watchlist.
+ *
+ * @return void
+ */
+ public function testCountOthersWatchlistShared()
+ {
+ $uid = $this->addUser();
+ $address = 'http://example.org';
+
+ //create other user and add main user to his watchlist
+ $friendPublic1 = $this->addUser();
+ $this->us->setCurrentUserId($friendPublic1);
+ $this->us->setWatchStatus($uid);
+
+ //create bookmarks for main user and other one
+ $this->addBookmark($uid, $address, 0);
+ $this->addBookmark($friendPublic1, $address, 1);//1 is shared
+
+ //log main user in
+ $this->us->setCurrentUserId($uid);
+
+ $this->assertEquals(1, $this->bs->countOthers($address));
+ }
+
+
+
+ /**
+ * Test what countOther() returns when the user is logged in
+ * and one friends (people on the watchlist) has bookmarked
+ * the same address but made it private.
+ *
+ * @return void
+ */
+ public function testCountOthersWatchlistPrivate()
+ {
+ $uid = $this->addUser();
+ $address = 'http://example.org';
+
+ //create other user and add main user to his watchlist
+ $friendPublic1 = $this->addUser();
+ $this->us->setCurrentUserId($friendPublic1);
+ $this->us->setWatchStatus($uid);
+
+ //create bookmarks for main user and other one
+ $this->addBookmark($uid, $address, 0);
+ $this->addBookmark($friendPublic1, $address, 2);//2 is private
+
+ //log main user in
+ $this->us->setCurrentUserId($uid);
+
+ $this->assertEquals(0, $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 testCountOthersWatchlistComplex()
+ {
+ $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));
+ }
+
+
+
+ /**
+ * 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)
+ )
+ );
+ }
+
+
+ /**
+ * Test that the default privacy setting in
+ * $GLOBALS['defaults']['privacy'] is used
+ * as expected.
+ *
+ * @return void
+ */
+ public function testDefaultPrivacy()
+ {
+ $GLOBALS['defaults']['privacy'] = 1;
+ $uid = $this->addUser();
+ $this->us->setCurrentUserId($uid);
+ $bid = $this->bs->addBookmark('http://www.somedomain.com', 'mybookmark1', 'descr1', 'privatenote1', $GLOBALS['defaults']['privacy'], array());
+ $bm = $this->bs->getBookmark($bid);
+ $this->assertEquals('1', $bm['bStatus']);
+ $GLOBALS['defaults']['privacy'] = 2;
+ $uid = $this->addUser();
+ $this->us->setCurrentUserId($uid);
+ $bid = $this->bs->addBookmark('http://www.anotherdomain.com', 'mybookmark2', 'descr2', 'privatenote2', $GLOBALS['defaults']['privacy'], array());
+ $bm = $this->bs->getBookmark($bid);
+ $this->assertEquals('2', $bm['bStatus']);
+ }//end function testDefaultPrivacy
+
+
+
+}
+
+
+if (PHPUnit_MAIN_METHOD == 'BookmarkTest::main') {
+ BookmarkTest::main();
+}
+?>
--
cgit v1.2.3-54-g00ecf
From 675eadd584e264ba92091579bbc1166dcf3a5715 Mon Sep 17 00:00:00 2001
From: bretticvs
Date: Thu, 31 Mar 2011 15:59:44 -0700
Subject: Updates for configurable-privacy2, hopefully without carriage
returns.
---
data/config.php.dist | 6 --
data/templates/bookmarks.tpl.php | 2 +-
tests/BookmarkTest.php | 97 +++++++++++++++++++++++---
tests/data/BookmarkTest_deliciousbookmarks.xml | 2 +-
tests/data/BookmarkTest_netscapebookmarks.html | 2 +-
5 files changed, 89 insertions(+), 20 deletions(-)
diff --git a/data/config.php.dist b/data/config.php.dist
index 0f849e2..302d55f 100644
--- a/data/config.php.dist
+++ b/data/config.php.dist
@@ -7,12 +7,6 @@
* See config.default.inc.php for more options.
*/
-/**
- * Array for defaults.
- *
- * @var array
- */
-$defaults = array();
/**
* The name of this site.
diff --git a/data/templates/bookmarks.tpl.php b/data/templates/bookmarks.tpl.php
index 44dfe90..e32d3c9 100644
--- a/data/templates/bookmarks.tpl.php
+++ b/data/templates/bookmarks.tpl.php
@@ -256,7 +256,7 @@ if ($currenttag!= '') {
foreach ($bookmarks as $key => &$row) {
switch ($row['bStatus']) {
case 0:
- $access = ' public';
+ $access = '';
break;
case 1:
$access = ' shared';
diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php
index aa0b8c3..e6f2b26 100644
--- a/tests/BookmarkTest.php
+++ b/tests/BookmarkTest.php
@@ -1352,18 +1352,93 @@ class BookmarkTest extends TestBase
*/
public function testDefaultPrivacy()
{
- $GLOBALS['defaults']['privacy'] = 1;
- $uid = $this->addUser();
- $this->us->setCurrentUserId($uid);
- $bid = $this->bs->addBookmark('http://www.somedomain.com', 'mybookmark1', 'descr1', 'privatenote1', $GLOBALS['defaults']['privacy'], array());
- $bm = $this->bs->getBookmark($bid);
- $this->assertEquals('1', $bm['bStatus']);
- $GLOBALS['defaults']['privacy'] = 2;
- $uid = $this->addUser();
- $this->us->setCurrentUserId($uid);
- $bid = $this->bs->addBookmark('http://www.anotherdomain.com', 'mybookmark2', 'descr2', 'privatenote2', $GLOBALS['defaults']['privacy'], array());
- $bm = $this->bs->getBookmark($bid);
+ //For this test, the default privacy has been set to 2 (private) in the configuration file.
+ require_once 'HTTP/Request2.php';
+ require_once dirname(__FILE__) . '/../data/config.php';
+ $this->bs->deleteAll();
+ $this->us->deleteAll();
+ $request = new HTTP_Request2('http://localhost/api/posts_add.php', HTTP_Request2::METHOD_POST);
+ $dpuid = $this->addUser('dpuser', 'dpuserpassword');
+ $request->setAuth('dpuser', 'dpuserpassword');
+ $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com');
+ $request->addPostParameter('description', 'Test bookmark 1 for default privacy.');
+ $request->send();
+ $bm = $this->bs->getBookmark('1');
+ $this->assertEquals('2', $bm['bStatus']);
+
+ $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add2.com');
+ $request->addPostParameter('description', 'Test bookmark 2 for default privacy.');
+ $request->addPostParameter('status', '0');
+ $request->send();
+
+ $request = new HTTP_Request2('http://localhost/edit.php/2', HTTP_Request2::METHOD_POST);
+ $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
+ $userinfo = $this->us->getUser('1');
+ $testcookiepassword = $userinfo['password'];
+ $testcookievalue = '1:'.md5('dpuser'.$testcookiepassword);
+ $request->setCookieJar(true);
+ $request->addCookie($testcookiekey, $testcookievalue);
+ $request->addPostParameter('title', 'Test bookmark 2 for default privacy.');
+ $request->addPostParameter('address', 'http://www.testdefaultprivacyposts_add2.com');
+ $request->addPostParameter('submitted', '1');
+ $request->send();
+ $bm = $this->bs->getBookmark('2');
$this->assertEquals('2', $bm['bStatus']);
+
+ $request = new HTTP_Request2('http://localhost/importNetscape.php', HTTP_Request2::METHOD_POST);
+ $request->setCookieJar(true);
+ $request->addCookie($testcookiekey, $testcookievalue);
+ $request->addUpload('userfile', './data/BookmarkTest_netscapebookmarks.html');
+ $request->send();
+ $bm = $this->bs->getBookmark('3');
+ $this->assertEquals('2', $bm['bStatus']);
+ $bm = $this->bs->getBookmark('4');
+ $this->assertEquals('2', $bm['bStatus']);
+ $bm = $this->bs->getBookmark('5');
+ $this->assertEquals('2', $bm['bStatus']);
+
+ $request = new HTTP_Request2('http://localhost/import.php', HTTP_Request2::METHOD_POST);
+ $request->setCookieJar(true);
+ $request->addCookie($testcookiekey, $testcookievalue);
+ $request->addUpload('userfile', './data/BookmarkTest_deliciousbookmarks.xml');
+ $request->send();
+ $bm = $this->bs->getBookmark('6');
+ $this->assertEquals('2', $bm['bStatus']);
+ $bm = $this->bs->getBookmark('7');
+ $this->assertEquals('2', $bm['bStatus']);
+ $bm = $this->bs->getBookmark('8');
+ $this->assertEquals('2', $bm['bStatus']);
+
+ $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=get', HTTP_Request2::METHOD_POST);
+ $request->setCookieJar(true);
+ $request->addCookie($testcookiekey, $testcookievalue);
+ $request->addPostParameter('submitted', '1');
+ $response = $request->send();
+ $response_body = $response->getBody();
+ $start = strpos($response_body, 'Privacy');
+ $end = strpos($response_body, 'referrer');
+ $length = $end - $start;
+ $response_body = substr($response_body, $start, $length);
+ $start = strpos($response_body, 'selected');
+ $start = $start - 3;
+ $length = 1;
+ $selected_privacy = substr($response_body, $start, $length);
+ $this->assertEquals('2', $selected_privacy);
+
+ $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=add', HTTP_Request2::METHOD_POST);
+ $request->setCookieJar(true);
+ $request->addCookie($testcookiekey, $testcookievalue);
+ $response = $request->send();
+ $response_body = $response->getBody();
+ $start = strpos($response_body, 'Privacy');
+ $end = strpos($response_body, 'referrer');
+ $length = $end - $start;
+ $response_body = substr($response_body, $start, $length);
+ $start = strpos($response_body, 'selected');
+ $start = $start - 3;
+ $length = 1;
+ $selected_privacy = substr($response_body, $start, $length);
+ $this->assertEquals('2', $selected_privacy);
}//end function testDefaultPrivacy
diff --git a/tests/data/BookmarkTest_deliciousbookmarks.xml b/tests/data/BookmarkTest_deliciousbookmarks.xml
index 1c12110..1c3fd8d 100755
--- a/tests/data/BookmarkTest_deliciousbookmarks.xml
+++ b/tests/data/BookmarkTest_deliciousbookmarks.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/tests/data/BookmarkTest_netscapebookmarks.html b/tests/data/BookmarkTest_netscapebookmarks.html
index 3e1bd7d..c91d20a 100755
--- a/tests/data/BookmarkTest_netscapebookmarks.html
+++ b/tests/data/BookmarkTest_netscapebookmarks.html
@@ -1,7 +1,7 @@
--
cgit v1.2.3-54-g00ecf
From f072059f2de515c0125a9f63ab8476e52c4d4353 Mon Sep 17 00:00:00 2001
From: bretticvs
Date: Thu, 31 Mar 2011 16:17:53 -0700
Subject: Revert "Updates for configurable-privacy2, hopefully without carriage
returns."
This reverts commit 675eadd584e264ba92091579bbc1166dcf3a5715.
---
data/config.php.dist | 6 ++
data/templates/bookmarks.tpl.php | 2 +-
tests/BookmarkTest.php | 97 +++-----------------------
tests/data/BookmarkTest_deliciousbookmarks.xml | 2 +-
tests/data/BookmarkTest_netscapebookmarks.html | 2 +-
5 files changed, 20 insertions(+), 89 deletions(-)
diff --git a/data/config.php.dist b/data/config.php.dist
index 302d55f..0f849e2 100644
--- a/data/config.php.dist
+++ b/data/config.php.dist
@@ -7,6 +7,12 @@
* See config.default.inc.php for more options.
*/
+/**
+ * Array for defaults.
+ *
+ * @var array
+ */
+$defaults = array();
/**
* The name of this site.
diff --git a/data/templates/bookmarks.tpl.php b/data/templates/bookmarks.tpl.php
index e32d3c9..44dfe90 100644
--- a/data/templates/bookmarks.tpl.php
+++ b/data/templates/bookmarks.tpl.php
@@ -256,7 +256,7 @@ if ($currenttag!= '') {
foreach ($bookmarks as $key => &$row) {
switch ($row['bStatus']) {
case 0:
- $access = '';
+ $access = ' public';
break;
case 1:
$access = ' shared';
diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php
index e6f2b26..aa0b8c3 100644
--- a/tests/BookmarkTest.php
+++ b/tests/BookmarkTest.php
@@ -1352,93 +1352,18 @@ class BookmarkTest extends TestBase
*/
public function testDefaultPrivacy()
{
- //For this test, the default privacy has been set to 2 (private) in the configuration file.
- require_once 'HTTP/Request2.php';
- require_once dirname(__FILE__) . '/../data/config.php';
- $this->bs->deleteAll();
- $this->us->deleteAll();
- $request = new HTTP_Request2('http://localhost/api/posts_add.php', HTTP_Request2::METHOD_POST);
- $dpuid = $this->addUser('dpuser', 'dpuserpassword');
- $request->setAuth('dpuser', 'dpuserpassword');
- $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com');
- $request->addPostParameter('description', 'Test bookmark 1 for default privacy.');
- $request->send();
- $bm = $this->bs->getBookmark('1');
- $this->assertEquals('2', $bm['bStatus']);
-
- $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add2.com');
- $request->addPostParameter('description', 'Test bookmark 2 for default privacy.');
- $request->addPostParameter('status', '0');
- $request->send();
-
- $request = new HTTP_Request2('http://localhost/edit.php/2', HTTP_Request2::METHOD_POST);
- $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
- $userinfo = $this->us->getUser('1');
- $testcookiepassword = $userinfo['password'];
- $testcookievalue = '1:'.md5('dpuser'.$testcookiepassword);
- $request->setCookieJar(true);
- $request->addCookie($testcookiekey, $testcookievalue);
- $request->addPostParameter('title', 'Test bookmark 2 for default privacy.');
- $request->addPostParameter('address', 'http://www.testdefaultprivacyposts_add2.com');
- $request->addPostParameter('submitted', '1');
- $request->send();
- $bm = $this->bs->getBookmark('2');
- $this->assertEquals('2', $bm['bStatus']);
-
- $request = new HTTP_Request2('http://localhost/importNetscape.php', HTTP_Request2::METHOD_POST);
- $request->setCookieJar(true);
- $request->addCookie($testcookiekey, $testcookievalue);
- $request->addUpload('userfile', './data/BookmarkTest_netscapebookmarks.html');
- $request->send();
- $bm = $this->bs->getBookmark('3');
- $this->assertEquals('2', $bm['bStatus']);
- $bm = $this->bs->getBookmark('4');
- $this->assertEquals('2', $bm['bStatus']);
- $bm = $this->bs->getBookmark('5');
- $this->assertEquals('2', $bm['bStatus']);
-
- $request = new HTTP_Request2('http://localhost/import.php', HTTP_Request2::METHOD_POST);
- $request->setCookieJar(true);
- $request->addCookie($testcookiekey, $testcookievalue);
- $request->addUpload('userfile', './data/BookmarkTest_deliciousbookmarks.xml');
- $request->send();
- $bm = $this->bs->getBookmark('6');
- $this->assertEquals('2', $bm['bStatus']);
- $bm = $this->bs->getBookmark('7');
- $this->assertEquals('2', $bm['bStatus']);
- $bm = $this->bs->getBookmark('8');
+ $GLOBALS['defaults']['privacy'] = 1;
+ $uid = $this->addUser();
+ $this->us->setCurrentUserId($uid);
+ $bid = $this->bs->addBookmark('http://www.somedomain.com', 'mybookmark1', 'descr1', 'privatenote1', $GLOBALS['defaults']['privacy'], array());
+ $bm = $this->bs->getBookmark($bid);
+ $this->assertEquals('1', $bm['bStatus']);
+ $GLOBALS['defaults']['privacy'] = 2;
+ $uid = $this->addUser();
+ $this->us->setCurrentUserId($uid);
+ $bid = $this->bs->addBookmark('http://www.anotherdomain.com', 'mybookmark2', 'descr2', 'privatenote2', $GLOBALS['defaults']['privacy'], array());
+ $bm = $this->bs->getBookmark($bid);
$this->assertEquals('2', $bm['bStatus']);
-
- $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=get', HTTP_Request2::METHOD_POST);
- $request->setCookieJar(true);
- $request->addCookie($testcookiekey, $testcookievalue);
- $request->addPostParameter('submitted', '1');
- $response = $request->send();
- $response_body = $response->getBody();
- $start = strpos($response_body, 'Privacy');
- $end = strpos($response_body, 'referrer');
- $length = $end - $start;
- $response_body = substr($response_body, $start, $length);
- $start = strpos($response_body, 'selected');
- $start = $start - 3;
- $length = 1;
- $selected_privacy = substr($response_body, $start, $length);
- $this->assertEquals('2', $selected_privacy);
-
- $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=add', HTTP_Request2::METHOD_POST);
- $request->setCookieJar(true);
- $request->addCookie($testcookiekey, $testcookievalue);
- $response = $request->send();
- $response_body = $response->getBody();
- $start = strpos($response_body, 'Privacy');
- $end = strpos($response_body, 'referrer');
- $length = $end - $start;
- $response_body = substr($response_body, $start, $length);
- $start = strpos($response_body, 'selected');
- $start = $start - 3;
- $length = 1;
- $selected_privacy = substr($response_body, $start, $length);
- $this->assertEquals('2', $selected_privacy);
}//end function testDefaultPrivacy
diff --git a/tests/data/BookmarkTest_deliciousbookmarks.xml b/tests/data/BookmarkTest_deliciousbookmarks.xml
index 1c3fd8d..1c12110 100755
--- a/tests/data/BookmarkTest_deliciousbookmarks.xml
+++ b/tests/data/BookmarkTest_deliciousbookmarks.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/tests/data/BookmarkTest_netscapebookmarks.html b/tests/data/BookmarkTest_netscapebookmarks.html
index c91d20a..3e1bd7d 100755
--- a/tests/data/BookmarkTest_netscapebookmarks.html
+++ b/tests/data/BookmarkTest_netscapebookmarks.html
@@ -1,7 +1,7 @@
--
cgit v1.2.3-54-g00ecf
From 42942507c416b6a4b5042631f18e6596fdac4dd7 Mon Sep 17 00:00:00 2001
From: bretticvs
Date: Thu, 31 Mar 2011 16:18:36 -0700
Subject: Revert "Revert "Updates for configurable-privacy2, hopefully without
carriage returns.""
This reverts commit f072059f2de515c0125a9f63ab8476e52c4d4353.
---
data/config.php.dist | 6 --
data/templates/bookmarks.tpl.php | 2 +-
tests/BookmarkTest.php | 97 +++++++++++++++++++++++---
tests/data/BookmarkTest_deliciousbookmarks.xml | 2 +-
tests/data/BookmarkTest_netscapebookmarks.html | 2 +-
5 files changed, 89 insertions(+), 20 deletions(-)
diff --git a/data/config.php.dist b/data/config.php.dist
index 0f849e2..302d55f 100644
--- a/data/config.php.dist
+++ b/data/config.php.dist
@@ -7,12 +7,6 @@
* See config.default.inc.php for more options.
*/
-/**
- * Array for defaults.
- *
- * @var array
- */
-$defaults = array();
/**
* The name of this site.
diff --git a/data/templates/bookmarks.tpl.php b/data/templates/bookmarks.tpl.php
index 44dfe90..e32d3c9 100644
--- a/data/templates/bookmarks.tpl.php
+++ b/data/templates/bookmarks.tpl.php
@@ -256,7 +256,7 @@ if ($currenttag!= '') {
foreach ($bookmarks as $key => &$row) {
switch ($row['bStatus']) {
case 0:
- $access = ' public';
+ $access = '';
break;
case 1:
$access = ' shared';
diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php
index aa0b8c3..e6f2b26 100644
--- a/tests/BookmarkTest.php
+++ b/tests/BookmarkTest.php
@@ -1352,18 +1352,93 @@ class BookmarkTest extends TestBase
*/
public function testDefaultPrivacy()
{
- $GLOBALS['defaults']['privacy'] = 1;
- $uid = $this->addUser();
- $this->us->setCurrentUserId($uid);
- $bid = $this->bs->addBookmark('http://www.somedomain.com', 'mybookmark1', 'descr1', 'privatenote1', $GLOBALS['defaults']['privacy'], array());
- $bm = $this->bs->getBookmark($bid);
- $this->assertEquals('1', $bm['bStatus']);
- $GLOBALS['defaults']['privacy'] = 2;
- $uid = $this->addUser();
- $this->us->setCurrentUserId($uid);
- $bid = $this->bs->addBookmark('http://www.anotherdomain.com', 'mybookmark2', 'descr2', 'privatenote2', $GLOBALS['defaults']['privacy'], array());
- $bm = $this->bs->getBookmark($bid);
+ //For this test, the default privacy has been set to 2 (private) in the configuration file.
+ require_once 'HTTP/Request2.php';
+ require_once dirname(__FILE__) . '/../data/config.php';
+ $this->bs->deleteAll();
+ $this->us->deleteAll();
+ $request = new HTTP_Request2('http://localhost/api/posts_add.php', HTTP_Request2::METHOD_POST);
+ $dpuid = $this->addUser('dpuser', 'dpuserpassword');
+ $request->setAuth('dpuser', 'dpuserpassword');
+ $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com');
+ $request->addPostParameter('description', 'Test bookmark 1 for default privacy.');
+ $request->send();
+ $bm = $this->bs->getBookmark('1');
+ $this->assertEquals('2', $bm['bStatus']);
+
+ $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add2.com');
+ $request->addPostParameter('description', 'Test bookmark 2 for default privacy.');
+ $request->addPostParameter('status', '0');
+ $request->send();
+
+ $request = new HTTP_Request2('http://localhost/edit.php/2', HTTP_Request2::METHOD_POST);
+ $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
+ $userinfo = $this->us->getUser('1');
+ $testcookiepassword = $userinfo['password'];
+ $testcookievalue = '1:'.md5('dpuser'.$testcookiepassword);
+ $request->setCookieJar(true);
+ $request->addCookie($testcookiekey, $testcookievalue);
+ $request->addPostParameter('title', 'Test bookmark 2 for default privacy.');
+ $request->addPostParameter('address', 'http://www.testdefaultprivacyposts_add2.com');
+ $request->addPostParameter('submitted', '1');
+ $request->send();
+ $bm = $this->bs->getBookmark('2');
$this->assertEquals('2', $bm['bStatus']);
+
+ $request = new HTTP_Request2('http://localhost/importNetscape.php', HTTP_Request2::METHOD_POST);
+ $request->setCookieJar(true);
+ $request->addCookie($testcookiekey, $testcookievalue);
+ $request->addUpload('userfile', './data/BookmarkTest_netscapebookmarks.html');
+ $request->send();
+ $bm = $this->bs->getBookmark('3');
+ $this->assertEquals('2', $bm['bStatus']);
+ $bm = $this->bs->getBookmark('4');
+ $this->assertEquals('2', $bm['bStatus']);
+ $bm = $this->bs->getBookmark('5');
+ $this->assertEquals('2', $bm['bStatus']);
+
+ $request = new HTTP_Request2('http://localhost/import.php', HTTP_Request2::METHOD_POST);
+ $request->setCookieJar(true);
+ $request->addCookie($testcookiekey, $testcookievalue);
+ $request->addUpload('userfile', './data/BookmarkTest_deliciousbookmarks.xml');
+ $request->send();
+ $bm = $this->bs->getBookmark('6');
+ $this->assertEquals('2', $bm['bStatus']);
+ $bm = $this->bs->getBookmark('7');
+ $this->assertEquals('2', $bm['bStatus']);
+ $bm = $this->bs->getBookmark('8');
+ $this->assertEquals('2', $bm['bStatus']);
+
+ $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=get', HTTP_Request2::METHOD_POST);
+ $request->setCookieJar(true);
+ $request->addCookie($testcookiekey, $testcookievalue);
+ $request->addPostParameter('submitted', '1');
+ $response = $request->send();
+ $response_body = $response->getBody();
+ $start = strpos($response_body, 'Privacy');
+ $end = strpos($response_body, 'referrer');
+ $length = $end - $start;
+ $response_body = substr($response_body, $start, $length);
+ $start = strpos($response_body, 'selected');
+ $start = $start - 3;
+ $length = 1;
+ $selected_privacy = substr($response_body, $start, $length);
+ $this->assertEquals('2', $selected_privacy);
+
+ $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=add', HTTP_Request2::METHOD_POST);
+ $request->setCookieJar(true);
+ $request->addCookie($testcookiekey, $testcookievalue);
+ $response = $request->send();
+ $response_body = $response->getBody();
+ $start = strpos($response_body, 'Privacy');
+ $end = strpos($response_body, 'referrer');
+ $length = $end - $start;
+ $response_body = substr($response_body, $start, $length);
+ $start = strpos($response_body, 'selected');
+ $start = $start - 3;
+ $length = 1;
+ $selected_privacy = substr($response_body, $start, $length);
+ $this->assertEquals('2', $selected_privacy);
}//end function testDefaultPrivacy
diff --git a/tests/data/BookmarkTest_deliciousbookmarks.xml b/tests/data/BookmarkTest_deliciousbookmarks.xml
index 1c12110..1c3fd8d 100755
--- a/tests/data/BookmarkTest_deliciousbookmarks.xml
+++ b/tests/data/BookmarkTest_deliciousbookmarks.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/tests/data/BookmarkTest_netscapebookmarks.html b/tests/data/BookmarkTest_netscapebookmarks.html
index 3e1bd7d..c91d20a 100755
--- a/tests/data/BookmarkTest_netscapebookmarks.html
+++ b/tests/data/BookmarkTest_netscapebookmarks.html
@@ -1,7 +1,7 @@
--
cgit v1.2.3-54-g00ecf
From a0ca39837263bf0ca112c964e8c4d62e0378a399 Mon Sep 17 00:00:00 2001
From: bretticvs
Date: Thu, 31 Mar 2011 16:42:44 -0700
Subject: Trying to remove carriage returns from test data.
---
tests/data/BookmarkTest_deliciousbookmarks.xml | 7 -------
tests/data/BookmarkTest_netscapebookmarks.html | 27 --------------------------
2 files changed, 34 deletions(-)
diff --git a/tests/data/BookmarkTest_deliciousbookmarks.xml b/tests/data/BookmarkTest_deliciousbookmarks.xml
index 1c3fd8d..e69de29 100755
--- a/tests/data/BookmarkTest_deliciousbookmarks.xml
+++ b/tests/data/BookmarkTest_deliciousbookmarks.xml
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
diff --git a/tests/data/BookmarkTest_netscapebookmarks.html b/tests/data/BookmarkTest_netscapebookmarks.html
index c91d20a..e69de29 100755
--- a/tests/data/BookmarkTest_netscapebookmarks.html
+++ b/tests/data/BookmarkTest_netscapebookmarks.html
@@ -1,27 +0,0 @@
-
-
-
-
-Bookmarks for dpuser
-
-Bookmarks for dpuser
-
-
-
-
-
- Test bookmark 3 for default privacy.
-
- Test bookmark 4 for default privacy.
-
- Test bookmark 5 for default privacy.
-
- This bookmark will be ignored by importNetscape.php.
-
-
-
-
-
-
-
-
--
cgit v1.2.3-54-g00ecf
From 1aa20d38ca2833287ae3cd46b78dc000aea93732 Mon Sep 17 00:00:00 2001
From: bretticvs
Date: Thu, 31 Mar 2011 16:49:21 -0700
Subject: Re-adding test data without carriage returns.
---
tests/data/BookmarkTest_deliciousbookmarks.xml | 7 +++++++
tests/data/BookmarkTest_netscapebookmarks.html | 27 ++++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/tests/data/BookmarkTest_deliciousbookmarks.xml b/tests/data/BookmarkTest_deliciousbookmarks.xml
index e69de29..d2bcfc5 100755
--- a/tests/data/BookmarkTest_deliciousbookmarks.xml
+++ b/tests/data/BookmarkTest_deliciousbookmarks.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/tests/data/BookmarkTest_netscapebookmarks.html b/tests/data/BookmarkTest_netscapebookmarks.html
index e69de29..07c7448 100755
--- a/tests/data/BookmarkTest_netscapebookmarks.html
+++ b/tests/data/BookmarkTest_netscapebookmarks.html
@@ -0,0 +1,27 @@
+
+
+
+
+
Bookmarks for dpuser
+
+Bookmarks for dpuser
+
+
+
+
+
- Test bookmark 3 for default privacy.
+
- Test bookmark 4 for default privacy.
+
- Test bookmark 5 for default privacy.
+
- This bookmark will be ignored by importNetscape.php.
+
+
+
+
+
+
+
+
--
cgit v1.2.3-54-g00ecf
From 988e564ec3af4191cc9a7a8a04ae1cb582271518 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Wed, 6 Apr 2011 07:46:55 +0200
Subject: always delete all bookmarks in setUp since almost all methods do it
anyway
---
tests/Api/PostsAddTest.php | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index 1f21d04..226a7c9 100644
--- a/tests/Api/PostsAddTest.php
+++ b/tests/Api/PostsAddTest.php
@@ -51,6 +51,13 @@ class Api_PostsAddTest extends TestBaseApi
}
+ public function setUp()
+ {
+ parent::setUp();
+ $this->bs->deleteAll();
+ }
+
+
/**
* Test if authentication is required when sending no auth data
@@ -82,8 +89,6 @@ class Api_PostsAddTest extends TestBaseApi
*/
public function testAddBookmarkPost()
{
- $this->bs->deleteAll();
-
$bmUrl = 'http://example.org/tag-1';
$bmTags = array('foo', 'bar', 'baz');
$bmDatetime = '2010-09-08T03:02:01Z';
@@ -144,8 +149,6 @@ TXT;
*/
public function testAddBookmarkGet()
{
- $this->bs->deleteAll();
-
$bmUrl = 'http://example.org/tag-1';
$bmTags = array('foo', 'bar', 'baz');
$bmDatetime = '2010-09-08T03:02:01Z';
@@ -205,8 +208,6 @@ TXT;
*/
public function testUrlDescEnough()
{
- $this->bs->deleteAll();
-
list($req, $uId) = $this->getAuthRequest();
$req->setMethod(HTTP_Request2::METHOD_POST);
$req->addPostParameter('url', 'http://example.org/tag2');
@@ -241,8 +242,6 @@ TXT;
*/
public function testUrlRequired()
{
- $this->bs->deleteAll();
-
list($req, $uId) = $this->getAuthRequest();
$req->setMethod(HTTP_Request2::METHOD_POST);
//$req->addPostParameter('url', 'http://example.org/tag2');
@@ -277,8 +276,6 @@ TXT;
*/
public function testDescriptionRequired()
{
- $this->bs->deleteAll();
-
list($req, $uId) = $this->getAuthRequest();
$req->setMethod(HTTP_Request2::METHOD_POST);
$req->addPostParameter('url', 'http://example.org/tag2');
@@ -313,8 +310,6 @@ TXT;
*/
public function testReplaceNo()
{
- $this->bs->deleteAll();
-
$url = 'http://example.org/tag2';
$title1 = 'foo bar 1';
$title2 = 'bar 2 foo';
@@ -381,8 +376,6 @@ TXT;
*/
public function testReplaceYes()
{
- $this->bs->deleteAll();
-
$url = 'http://example.org/tag2';
$title1 = 'foo bar 1';
$title2 = 'bar 2 foo';
--
cgit v1.2.3-54-g00ecf
From 1a2b37cc3421ba24931c1ef5edb0f06e61db6d5c Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Wed, 6 Apr 2011 07:58:01 +0200
Subject: tell people why we need that variable
---
tests/prepare.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tests/prepare.php b/tests/prepare.php
index 6afc284..c80306e 100644
--- a/tests/prepare.php
+++ b/tests/prepare.php
@@ -16,7 +16,9 @@
/**
* Prepare the application for unit testing
*/
+//that's needed in constants.php
$_SERVER['HTTP_HOST'] = 'http://localhost/';
+
define('UNIT_TEST_MODE', true);
if ('@data_dir@' == '@' . 'data_dir@') {
--
cgit v1.2.3-54-g00ecf
From c81566f5d8c6149e87432b158331fd724e7e35e5 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Wed, 6 Apr 2011 08:42:26 +0200
Subject: cherry-pick: add new feature: allow unit test mode enabling via HTTP
GET parameter
---
data/config.default.php | 8 ++++
src/SemanticScuttle/header.php | 16 +++++++-
tests/TestBase.php | 89 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 112 insertions(+), 1 deletion(-)
diff --git a/data/config.default.php b/data/config.default.php
index cd611f1..85b9ccb 100644
--- a/data/config.default.php
+++ b/data/config.default.php
@@ -752,4 +752,12 @@ $authEmailSuffix = null;
*/
$unittestUrl = null;
+/**
+ * Allow "unittestMode=1" in URLs.
+ * Should only be enabled on development systems
+ *
+ * @var boolean
+ */
+$allowUnittestMode = false;
+
?>
diff --git a/src/SemanticScuttle/header.php b/src/SemanticScuttle/header.php
index d1a5c29..5d1ec80 100644
--- a/src/SemanticScuttle/header.php
+++ b/src/SemanticScuttle/header.php
@@ -39,6 +39,20 @@ set_include_path(
require_once $datadir . '/config.default.php';
require_once $datadir . '/config.php';
+if (isset($_GET['unittestMode']) && $_GET['unittestMode'] == 1
+) {
+ if ($allowUnittestMode !== true) {
+ header('HTTP/1.0 400 Bad Request');
+ die("Unittestmode is not allowed\n");
+ }
+
+ $unittestConfigFile = $datadir . '/config.unittest.php';
+ if (file_exists($unittestConfigFile)) {
+ require_once $unittestConfigFile;
+ }
+ define('HTTP_UNIT_TEST_MODE', true);
+ define('UNIT_TEST_MODE', true);
+}
if (defined('UNIT_TEST_MODE')) {
//make local config vars global - needed for unit tests
//run with phpunit
@@ -117,7 +131,7 @@ $tplVars['currentUser'] = $currentUser;
$tplVars['userservice'] = $userservice;
// 6 // Force UTF-8 behaviour for server (cannot be moved into top.inc.php which is not included into every file)
-if (!defined('UNIT_TEST_MODE')) {
+if (!defined('UNIT_TEST_MODE') || defined('HTTP_UNIT_TEST_MODE')) {
//API files define that, so we need a way to support both of them
if (!isset($httpContentType)) {
$httpContentType = 'text/html';
diff --git a/tests/TestBase.php b/tests/TestBase.php
index 8c1a934..edafd3d 100644
--- a/tests/TestBase.php
+++ b/tests/TestBase.php
@@ -22,6 +22,18 @@
*/
class TestBase extends PHPUnit_Framework_TestCase
{
+ /**
+ * Clean up after test
+ */
+ public function tearDown()
+ {
+ if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) {
+ unlink($GLOBALS['datadir'] . '/config.unittest.php');
+ }
+ }
+
+
+
/**
* Create a new bookmark.
*
@@ -79,8 +91,25 @@ class TestBase extends PHPUnit_Framework_TestCase
* @param string $password Password
*
* @return integer ID of user
+ *
+ * @uses addUserData()
*/
protected function addUser($username = null, $password = null)
+ {
+ return reset($this->addUserData($username, $password));
+ }
+
+
+
+ /**
+ * Creates a new user in the database and returns id, username and password.
+ *
+ * @param string $username Username
+ * @param string $password Password
+ *
+ * @return array ID of user, Name of user, password of user
+ */
+ protected function addUserData($username = null, $password = null)
{
$us = SemanticScuttle_Service_Factory::get('User');
$rand = rand();
@@ -97,9 +126,69 @@ class TestBase extends PHPUnit_Framework_TestCase
$password,
'unittest-' . $rand . '@example.org'
);
+ return array($uid, $username, $password);
+ }
+
+
+
+ /**
+ * Retrieves the UID of an admin user.
+ * If that user does not exist in the database, it is created.
+ *
+ * @return integer UID of admin user
+ */
+ protected function getAdminUser()
+ {
+ if (count($GLOBALS['admin_users']) == 0) {
+ $this->fail('No admin users configured');
+ }
+ $adminUserName = reset($GLOBALS['admin_users']);
+
+ $us = SemanticScuttle_Service_Factory::get('User');
+ $uid = $us->getIdFromUser($adminUserName);
+ if ($uid === null) {
+ //that user does not exist in the database; create it
+ $uid = $us->addUser(
+ $adminUserName,
+ rand(),
+ 'unittest-admin-' . $adminUserName . '@example.org'
+ );
+ }
+
return $uid;
}
+
+ /**
+ * Writes a special unittest configuration file.
+ * The unittest config file is read when a GET request with unittestMode=1
+ * is sent, and the user allowed unittestmode in config.php.
+ *
+ * @param array $arConfig Array with config names as key and their value as
+ * value
+ *
+ * @return void
+ */
+ protected function setUnittestConfig($arConfig)
+ {
+ $str = '<' . "?php\r\n";
+ foreach ($arConfig as $name => $value) {
+ $str .= '$' . $name . ' = '
+ . var_export($value, true) . ";\n";
+ }
+
+ if (!is_dir($GLOBALS['datadir'])) {
+ $this->fail(
+ 'datadir not set or not a directory: ' . $GLOBALS['datadir']
+ );
+ }
+
+ $this->assertInternalType(
+ 'integer',
+ file_put_contents($GLOBALS['datadir'] . '/config.unittest.php', $str),
+ 'Writing config.unittest.php failed'
+ );
+ }
}
?>
\ No newline at end of file
--
cgit v1.2.3-54-g00ecf
From cba0776325ac82bc255feb9a44b3bf312b02f6dc Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Wed, 6 Apr 2011 08:43:42 +0200
Subject: cherry-pick: move setUnittestConfig to TestBaseApi since it makes
only sense to use it there
Conflicts:
tests/TestBaseApi.php
---
tests/TestBase.php | 44 --------------------
tests/TestBaseApi.php | 90 +++++++++++++++++++++++++++++++++++++++++
tests/ajax/GetAdminTagsTest.php | 63 +++++++++++++++++++++++++++++
3 files changed, 153 insertions(+), 44 deletions(-)
create mode 100644 tests/ajax/GetAdminTagsTest.php
diff --git a/tests/TestBase.php b/tests/TestBase.php
index edafd3d..5a61b7b 100644
--- a/tests/TestBase.php
+++ b/tests/TestBase.php
@@ -22,18 +22,6 @@
*/
class TestBase extends PHPUnit_Framework_TestCase
{
- /**
- * Clean up after test
- */
- public function tearDown()
- {
- if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) {
- unlink($GLOBALS['datadir'] . '/config.unittest.php');
- }
- }
-
-
-
/**
* Create a new bookmark.
*
@@ -157,38 +145,6 @@ class TestBase extends PHPUnit_Framework_TestCase
return $uid;
}
-
-
- /**
- * Writes a special unittest configuration file.
- * The unittest config file is read when a GET request with unittestMode=1
- * is sent, and the user allowed unittestmode in config.php.
- *
- * @param array $arConfig Array with config names as key and their value as
- * value
- *
- * @return void
- */
- protected function setUnittestConfig($arConfig)
- {
- $str = '<' . "?php\r\n";
- foreach ($arConfig as $name => $value) {
- $str .= '$' . $name . ' = '
- . var_export($value, true) . ";\n";
- }
-
- if (!is_dir($GLOBALS['datadir'])) {
- $this->fail(
- 'datadir not set or not a directory: ' . $GLOBALS['datadir']
- );
- }
-
- $this->assertInternalType(
- 'integer',
- file_put_contents($GLOBALS['datadir'] . '/config.unittest.php', $str),
- 'Writing config.unittest.php failed'
- );
- }
}
?>
\ No newline at end of file
diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php
index dacdecd..73135fb 100644
--- a/tests/TestBaseApi.php
+++ b/tests/TestBaseApi.php
@@ -57,6 +57,18 @@ class TestBaseApi extends TestBase
+ /**
+ * Clean up after test
+ */
+ public function tearDown()
+ {
+ if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) {
+ unlink($GLOBALS['datadir'] . '/config.unittest.php');
+ }
+ }
+
+
+
/**
* Gets a HTTP request object.
* Uses $this->url plus $urlSuffix as request URL.
@@ -109,5 +121,83 @@ class TestBaseApi extends TestBase
return array($req, $uid);
}
+
+
+ /**
+ * Creates a user and a HTTP_Request2 object, does a normal login
+ * and prepares the cookies for the HTTP request object so that
+ * the user is seen as logged in when requesting any HTML page.
+ *
+ * Useful for testing HTML pages or ajax URLs.
+ *
+ * @param string $urlSuffix Suffix for the URL
+ * @param mixed $auth If user authentication is needed (true/false)
+ * or array with username and password
+ *
+ * @return array(HTTP_Request2, integer) HTTP request object and user id
+ *
+ * @uses getRequest()
+ */
+ protected function getLoggedInRequest($urlSuffix = null, $auth = true)
+ {
+ if (is_array($auth)) {
+ list($username, $password) = $auth;
+ } else {
+ $username = 'testuser';
+ $password = 'testpassword';
+ }
+ $uid = $this->addUser($username, $password);
+
+ $req = new HTTP_Request2(
+ $GLOBALS['unittestUrl'] . '/login.php',
+ HTTP_Request2::METHOD_POST
+ );
+ $cookies = $req->setCookieJar()->getCookieJar();
+ $req->addPostParameter('username', $username);
+ $req->addPostParameter('password', $password);
+ $req->addPostParameter('submitted', 'Log In');
+ $res = $req->send();
+
+ //after login, we normally get redirected
+ $this->assertEquals(302, $res->getStatus(), 'Login failure');
+
+ $req = $this->getRequest($urlSuffix);
+ $req->setCookieJar($cookies);
+
+ return array($req, $uid);
+ }
+
+
+
+ /**
+ * Writes a special unittest configuration file.
+ * The unittest config file is read when a GET request with unittestMode=1
+ * is sent, and the user allowed unittestmode in config.php.
+ *
+ * @param array $arConfig Array with config names as key and their value as
+ * value
+ *
+ * @return void
+ */
+ protected function setUnittestConfig($arConfig)
+ {
+ $str = '<' . "?php\r\n";
+ foreach ($arConfig as $name => $value) {
+ $str .= '$' . $name . ' = '
+ . var_export($value, true) . ";\n";
+ }
+
+ if (!is_dir($GLOBALS['datadir'])) {
+ $this->fail(
+ 'datadir not set or not a directory: ' . $GLOBALS['datadir']
+ );
+ }
+
+ $this->assertInternalType(
+ 'integer',
+ file_put_contents($GLOBALS['datadir'] . '/config.unittest.php', $str),
+ 'Writing config.unittest.php failed'
+ );
+ }
}
?>
\ No newline at end of file
diff --git a/tests/ajax/GetAdminTagsTest.php b/tests/ajax/GetAdminTagsTest.php
new file mode 100644
index 0000000..5c941e8
--- /dev/null
+++ b/tests/ajax/GetAdminTagsTest.php
@@ -0,0 +1,63 @@
+
+ * @author Christian Weiske
+ * @author Eric Dane
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+
+require_once dirname(__FILE__) . '/../prepare.php';
+require_once 'HTTP/Request2.php';
+
+/**
+ * Unit tests for the ajax getadmintags.php script
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Christian Weiske
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+class ajax_GetAdminTagsTest extends TestBaseApi
+{
+ protected $urlPart = 'ajax/getadmintags.php';
+
+
+ public function testTags()
+ {
+ list($user1, $uname1) = $this->addUserData();
+ $user2 = $this->addUser();
+ $this->addBookmark($user1, null, 0, array('admintag', 'admintag2'));
+ $this->addBookmark($user2, null, 0, array('lusertag', 'lusertag2'));
+
+ $this->setUnittestConfig(
+ array(
+ 'admin_users' => array($uname1)
+ )
+ );
+
+ $req = $this->getRequest('?unittestMode=1');
+ $res = $req->send();
+ $this->assertEquals(200, $res->getStatus());
+ $this->assertEquals(
+ 'application/json; charset=utf-8',
+ $res->getHeader('content-type')
+ );
+ $data = json_decode($res->getBody());
+ $this->assertInternalType('array', $data);
+ $this->assertEquals(2, count($data));
+ $this->assertContains('admintag', $data);
+ $this->assertContains('admintag2', $data);
+ }
+
+}
+
+
+?>
\ No newline at end of file
--
cgit v1.2.3-54-g00ecf
From 366987a97d41f1a276dfd43921a2fcf1f6e70f00 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Wed, 6 Apr 2011 09:50:42 +0200
Subject: move unittest config deletion to setup since that makes it easier to
debug, and does not break config when the test fatal errored
---
tests/TestBaseApi.php | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php
index 73135fb..9081a4a 100644
--- a/tests/TestBaseApi.php
+++ b/tests/TestBaseApi.php
@@ -47,6 +47,11 @@ class TestBaseApi extends TestBase
}
$this->url = $GLOBALS['unittestUrl'] . $this->urlPart;
+ //clean up before test
+ if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) {
+ unlink($GLOBALS['datadir'] . '/config.unittest.php');
+ }
+
$this->us = SemanticScuttle_Service_Factory::get('User');
$this->us->deleteAll();
$this->bs = SemanticScuttle_Service_Factory::get('Bookmark');
@@ -57,18 +62,6 @@ class TestBaseApi extends TestBase
- /**
- * Clean up after test
- */
- public function tearDown()
- {
- if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) {
- unlink($GLOBALS['datadir'] . '/config.unittest.php');
- }
- }
-
-
-
/**
* Gets a HTTP request object.
* Uses $this->url plus $urlSuffix as request URL.
--
cgit v1.2.3-54-g00ecf
From 3306261b3ee6ee3df2d67f2f87b4d8afafd55a53 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Wed, 6 Apr 2011 09:50:58 +0200
Subject: ignore unittest config file
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore
index 888ac2e..6f6d812 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
dist/
build.properties
package.xml
+data/config.unittest.php
--
cgit v1.2.3-54-g00ecf
From 200cb1d3c54dfaae54d26c0d51f6086435bcee8e Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Wed, 6 Apr 2011 09:52:02 +0200
Subject: move privacy tests for api/post_add to the correct location
---
tests/Api/PostsAddTest.php | 36 ++++++++++++++++++++++++++++++++++++
tests/BookmarkTest.php | 13 -------------
2 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index 226a7c9..f3bb31e 100644
--- a/tests/Api/PostsAddTest.php
+++ b/tests/Api/PostsAddTest.php
@@ -420,6 +420,42 @@ TXT;
$this->assertEquals(1, $data['total']);
$this->assertEquals($title2, $data['bookmarks'][0]['bTitle']);
}
+
+ public function testDefaultPrivacyPrivate()
+ {
+ $this->setUnittestConfig(
+ array('defaults' => array('privacy' => 2))
+ );
+ list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com');
+ $req->addPostParameter('description', 'Test bookmark 1 for default privacy.');
+ $req->send();
+
+ $this->us->setCurrentUserId($uId);
+ $bms = $this->bs->getBookmarks(0, null, $uId);
+ $this->assertEquals(1, count($bms['bookmarks']));
+ $bm = reset($bms['bookmarks']);
+ $this->assertEquals('2', $bm['bStatus']);
+ }
+
+ public function testDefaultPrivacyPublic()
+ {
+ $this->setUnittestConfig(
+ array('defaults' => array('privacy' => 0))
+ );
+ list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com');
+ $req->addPostParameter('description', 'Test bookmark 1 for default privacy.');
+ $req->send();
+
+ $this->us->setCurrentUserId($uId);
+ $bms = $this->bs->getBookmarks(0, null, $uId);
+ $this->assertEquals(1, count($bms['bookmarks']));
+ $bm = reset($bms['bookmarks']);
+ $this->assertEquals('0', $bm['bStatus']);
+ }
}
if (PHPUnit_MAIN_METHOD == 'Api_PostsAddTest::main') {
diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php
index e6f2b26..ad1cb48 100644
--- a/tests/BookmarkTest.php
+++ b/tests/BookmarkTest.php
@@ -1357,19 +1357,6 @@ class BookmarkTest extends TestBase
require_once dirname(__FILE__) . '/../data/config.php';
$this->bs->deleteAll();
$this->us->deleteAll();
- $request = new HTTP_Request2('http://localhost/api/posts_add.php', HTTP_Request2::METHOD_POST);
- $dpuid = $this->addUser('dpuser', 'dpuserpassword');
- $request->setAuth('dpuser', 'dpuserpassword');
- $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com');
- $request->addPostParameter('description', 'Test bookmark 1 for default privacy.');
- $request->send();
- $bm = $this->bs->getBookmark('1');
- $this->assertEquals('2', $bm['bStatus']);
-
- $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add2.com');
- $request->addPostParameter('description', 'Test bookmark 2 for default privacy.');
- $request->addPostParameter('status', '0');
- $request->send();
$request = new HTTP_Request2('http://localhost/edit.php/2', HTTP_Request2::METHOD_POST);
$testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
--
cgit v1.2.3-54-g00ecf
From 3b582fd875de425d91bc143a33dc07e554246a80 Mon Sep 17 00:00:00 2001
From: bretticvs
Date: Sun, 17 Apr 2011 17:42:49 -0600
Subject: Moved unit tests to PostsAddTest.php in Api directory.
---
tests/Api/PostsAddTest.php | 219 ++++++++++++++++++++++++-
tests/BookmarkTest.php | 86 ----------
tests/data/BookmarkTest_deliciousbookmarks.xml | 6 +-
tests/data/BookmarkTest_netscapebookmarks.html | 10 +-
4 files changed, 220 insertions(+), 101 deletions(-)
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index f3bb31e..4e2f4fa 100644
--- a/tests/Api/PostsAddTest.php
+++ b/tests/Api/PostsAddTest.php
@@ -421,6 +421,11 @@ TXT;
$this->assertEquals($title2, $data['bookmarks'][0]['bTitle']);
}
+
+ /**
+ * Test that a default privacy setting of 2 (Private) is used in adding
+ * a bookmark.
+ */
public function testDefaultPrivacyPrivate()
{
$this->setUnittestConfig(
@@ -428,17 +433,21 @@ TXT;
);
list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
$req->setMethod(HTTP_Request2::METHOD_POST);
- $req->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com');
+ $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_addprivate');
$req->addPostParameter('description', 'Test bookmark 1 for default privacy.');
$req->send();
-
$this->us->setCurrentUserId($uId);
$bms = $this->bs->getBookmarks(0, null, $uId);
$this->assertEquals(1, count($bms['bookmarks']));
$bm = reset($bms['bookmarks']);
$this->assertEquals('2', $bm['bStatus']);
- }
+ }//end testDefaultPrivacyPrivate
+
+ /**
+ * Test that a default privacy setting of 0 (Public) is used in adding
+ * a bookmark.
+ */
public function testDefaultPrivacyPublic()
{
$this->setUnittestConfig(
@@ -446,19 +455,215 @@ TXT;
);
list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
$req->setMethod(HTTP_Request2::METHOD_POST);
- $req->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com');
+ $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_addpublic');
$req->addPostParameter('description', 'Test bookmark 1 for default privacy.');
$req->send();
-
$this->us->setCurrentUserId($uId);
$bms = $this->bs->getBookmarks(0, null, $uId);
$this->assertEquals(1, count($bms['bookmarks']));
$bm = reset($bms['bookmarks']);
$this->assertEquals('0', $bm['bStatus']);
- }
+ }//end testDefaultPrivacyPublic
+
+
+ /**
+ * Test that the default privacy setting is used when an existing
+ * bookmark is updated with edit.php.
+ */
+ public function testDefaultPrivacyEdit()
+ {
+ $this->setUnittestConfig(
+ array('defaults' => array('privacy' => 2))
+ );
+ list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_edit');
+ $req->addPostParameter('description', 'Test bookmark 2 for default privacy.');
+ $req->addPostParameter('status', '0');
+ $req->send();
+ $bms = $this->bs->getBookmarks(0, null, $uId);
+ $bm = reset($bms['bookmarks']);
+ $bmId = $bm['bId'];
+ $oldUid = $uId;
+ $reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1';
+ list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->setUrl($reqUrl);
+ $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
+ $userinfo = $this->us->getUser($oldUid);
+ $testcookiepassword = $userinfo['password'];
+ $testusername = $userinfo['username'];
+ $testcookievalue = $oldUid . ':' . md5($testusername . $testcookiepassword);
+ $req->setCookieJar(true);
+ $req->addCookie($testcookiekey, $testcookievalue);
+ $req->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit');
+ $req->addPostParameter('title', 'Test bookmark 2 for default privacy.');
+ $req->addPostParameter('submitted', '1');
+ $req->send();
+ $bm = $this->bs->getBookmark($bmId);
+ $this->assertEquals('2', $bm['bStatus']);
+ }//end testDefaultPrivacyEdit
+
+
+ /**
+ * Test that the default privacy setting is used when bookmarks
+ * are imported from an HTML bookmarks file using importNetscape.php.
+ */
+ public function testDefaultPrivacyImportNetscape()
+ {
+ $this->setUnittestConfig(
+ array('defaults' => array('privacy' => 1))
+ );
+ list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->setUrl($GLOBALS['unittestUrl'] . 'importNetscape.php' . '?unittestMode=1');
+ $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
+ $userinfo = $this->us->getUser($uId);
+ $testcookiepassword = $userinfo['password'];
+ $testusername = $userinfo['username'];
+ $testcookievalue = $uId . ':' . md5($testusername . $testcookiepassword);
+ $req->setCookieJar(true);
+ $req->addCookie($testcookiekey, $testcookievalue);
+ $req->addUpload('userfile', '../data/BookmarkTest_netscapebookmarks.html');
+ $req->send();
+ $this->us->setCurrentUserId($uId);
+ $bms = $this->bs->getBookmarks(0, null, $uId);
+ $this->assertEquals(3, count($bms['bookmarks']));
+ $bm = reset($bms['bookmarks']);
+ $this->assertEquals('1', $bm['bStatus']);
+ }//end testDefaultPrivacyImportNetscape
+
+
+ /**
+ * Test that the default privacy setting is used when bookmarks
+ * are imported from an XML bookmarks file using import.php.
+ */
+ public function testDefaultPrivacyImport()
+ {
+ $this->setUnittestConfig(
+ array('defaults' => array('privacy' => 2))
+ );
+ list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->setUrl($GLOBALS['unittestUrl'] . 'import.php' . '?unittestMode=1');
+ $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
+ $userinfo = $this->us->getUser($uId);
+ $testcookiepassword = $userinfo['password'];
+ $testusername = $userinfo['username'];
+ $testcookievalue = $uId . ':' . md5($testusername . $testcookiepassword);
+ $req->setCookieJar(true);
+ $req->addCookie($testcookiekey, $testcookievalue);
+ $req->addUpload('userfile', '../data/BookmarkTest_deliciousbookmarks.xml');
+ $req->send();
+ $this->us->setCurrentUserId($uId);
+ $bms = $this->bs->getBookmarks(0, null, $uId);
+ $this->assertEquals(3, count($bms['bookmarks']));
+ $bm = reset($bms['bookmarks']);
+ $this->assertEquals('2', $bm['bStatus']);
+ }//end testDefaultPrivacyImport
+
+
+ /**
+ * Test that the default privacy setting is selected in the Privacy
+ * drop-down list when an existing bookmark is accessed with bookmarks.php
+ * and the get action.
+ */
+ public function testDefaultPrivacyBookmarksGet()
+ {
+ $this->setUnittestConfig(
+ array('defaults' => array('privacy' => 2))
+ );
+ list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_bookmarksget');
+ $req->addPostParameter('description', 'Test bookmark 1 for default privacy.');
+ $req->addPostParameter('status', '0');
+ $req->send();
+ $bms = $this->bs->getBookmarks(0, null, $uId);
+ $this->assertEquals(1, count($bms['bookmarks']));
+ $bm = reset($bms['bookmarks']);
+ $bmId = $bm['bId'];
+ $oldUid = $uId;
+ $user = $this->us->getUser($uId);
+ $userId = $user['username'];
+ $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $userId . '?action=get' . '&unittestMode=1';
+ list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->setUrl($reqUrl);
+ $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
+ $userinfo = $this->us->getUser($oldUid);
+ $testcookiepassword = $userinfo['password'];
+ $testusername = $userinfo['username'];
+ $testcookievalue = $oldUid . ':' . md5($testusername . $testcookiepassword);
+ $req->setCookieJar(true);
+ $req->addCookie($testcookiekey, $testcookievalue);
+ $req->addPostParameter('submitted', '1');
+ $response = $req->send();
+ $response_body = $response->getBody();
+ $start = strpos($response_body, 'Privacy');
+ $end = strpos($response_body, 'referrer');
+ $length = $end - $start;
+ $response_body = substr($response_body, $start, $length);
+ $start = strpos($response_body, 'selected');
+ $start = $start - 3;
+ $length = 1;
+ $selected_privacy = substr($response_body, $start, $length);
+ $this->assertEquals('2', $selected_privacy);
+ }//end testDefaultPrivacyBookmarksGet
+
+
+ /**
+ * Test that the default privacy setting is selected in the Privacy
+ * drop-down list when an existing bookmark is accessed with bookmarks.php
+ * and the add action.
+ */
+ public function testDefaultPrivacyBookmarksAdd()
+ {
+ $this->setUnittestConfig(
+ array('defaults' => array('privacy' => 1))
+ );
+ list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_bookmarksadd');
+ $req->addPostParameter('description', 'Test bookmark 2 for default privacy.');
+ $req->addPostParameter('status', '0');
+ $req->send();
+ $bms = $this->bs->getBookmarks(0, null, $uId);
+ $this->assertEquals(1, count($bms['bookmarks']));
+ $bm = reset($bms['bookmarks']);
+ $bmId = $bm['bId'];
+ $oldUid = $uId;
+ $user = $this->us->getUser($uId);
+ $userId = $user['username'];
+ $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $userId . '?action=add' . '&unittestMode=1';
+ list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->setUrl($reqUrl);
+ $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
+ $userinfo = $this->us->getUser($oldUid);
+ $testcookiepassword = $userinfo['password'];
+ $testusername = $userinfo['username'];
+ $testcookievalue = $oldUid . ':' . md5($testusername . $testcookiepassword);
+ $req->setCookieJar(true);
+ $req->addCookie($testcookiekey, $testcookievalue);
+ $req->addPostParameter('submitted', '1');
+ $response = $req->send();
+ $response_body = $response->getBody();
+ $start = strpos($response_body, 'Privacy');
+ $end = strpos($response_body, 'referrer');
+ $length = $end - $start;
+ $response_body = substr($response_body, $start, $length);
+ $start = strpos($response_body, 'selected');
+ $start = $start - 3;
+ $length = 1;
+ $selected_privacy = substr($response_body, $start, $length);
+ $this->assertEquals('1', $selected_privacy);
+ }//end testDefaultPrivacyBookmarksAdd
+
+
}
if (PHPUnit_MAIN_METHOD == 'Api_PostsAddTest::main') {
Api_PostsAddTest::main();
}
-?>
\ No newline at end of file
+?>
diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php
index ad1cb48..f54fe9a 100644
--- a/tests/BookmarkTest.php
+++ b/tests/BookmarkTest.php
@@ -1343,92 +1343,6 @@ class BookmarkTest extends TestBase
}
- /**
- * Test that the default privacy setting in
- * $GLOBALS['defaults']['privacy'] is used
- * as expected.
- *
- * @return void
- */
- public function testDefaultPrivacy()
- {
- //For this test, the default privacy has been set to 2 (private) in the configuration file.
- require_once 'HTTP/Request2.php';
- require_once dirname(__FILE__) . '/../data/config.php';
- $this->bs->deleteAll();
- $this->us->deleteAll();
-
- $request = new HTTP_Request2('http://localhost/edit.php/2', HTTP_Request2::METHOD_POST);
- $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
- $userinfo = $this->us->getUser('1');
- $testcookiepassword = $userinfo['password'];
- $testcookievalue = '1:'.md5('dpuser'.$testcookiepassword);
- $request->setCookieJar(true);
- $request->addCookie($testcookiekey, $testcookievalue);
- $request->addPostParameter('title', 'Test bookmark 2 for default privacy.');
- $request->addPostParameter('address', 'http://www.testdefaultprivacyposts_add2.com');
- $request->addPostParameter('submitted', '1');
- $request->send();
- $bm = $this->bs->getBookmark('2');
- $this->assertEquals('2', $bm['bStatus']);
-
- $request = new HTTP_Request2('http://localhost/importNetscape.php', HTTP_Request2::METHOD_POST);
- $request->setCookieJar(true);
- $request->addCookie($testcookiekey, $testcookievalue);
- $request->addUpload('userfile', './data/BookmarkTest_netscapebookmarks.html');
- $request->send();
- $bm = $this->bs->getBookmark('3');
- $this->assertEquals('2', $bm['bStatus']);
- $bm = $this->bs->getBookmark('4');
- $this->assertEquals('2', $bm['bStatus']);
- $bm = $this->bs->getBookmark('5');
- $this->assertEquals('2', $bm['bStatus']);
-
- $request = new HTTP_Request2('http://localhost/import.php', HTTP_Request2::METHOD_POST);
- $request->setCookieJar(true);
- $request->addCookie($testcookiekey, $testcookievalue);
- $request->addUpload('userfile', './data/BookmarkTest_deliciousbookmarks.xml');
- $request->send();
- $bm = $this->bs->getBookmark('6');
- $this->assertEquals('2', $bm['bStatus']);
- $bm = $this->bs->getBookmark('7');
- $this->assertEquals('2', $bm['bStatus']);
- $bm = $this->bs->getBookmark('8');
- $this->assertEquals('2', $bm['bStatus']);
-
- $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=get', HTTP_Request2::METHOD_POST);
- $request->setCookieJar(true);
- $request->addCookie($testcookiekey, $testcookievalue);
- $request->addPostParameter('submitted', '1');
- $response = $request->send();
- $response_body = $response->getBody();
- $start = strpos($response_body, 'Privacy');
- $end = strpos($response_body, 'referrer');
- $length = $end - $start;
- $response_body = substr($response_body, $start, $length);
- $start = strpos($response_body, 'selected');
- $start = $start - 3;
- $length = 1;
- $selected_privacy = substr($response_body, $start, $length);
- $this->assertEquals('2', $selected_privacy);
-
- $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=add', HTTP_Request2::METHOD_POST);
- $request->setCookieJar(true);
- $request->addCookie($testcookiekey, $testcookievalue);
- $response = $request->send();
- $response_body = $response->getBody();
- $start = strpos($response_body, 'Privacy');
- $end = strpos($response_body, 'referrer');
- $length = $end - $start;
- $response_body = substr($response_body, $start, $length);
- $start = strpos($response_body, 'selected');
- $start = $start - 3;
- $length = 1;
- $selected_privacy = substr($response_body, $start, $length);
- $this->assertEquals('2', $selected_privacy);
- }//end function testDefaultPrivacy
-
-
}
diff --git a/tests/data/BookmarkTest_deliciousbookmarks.xml b/tests/data/BookmarkTest_deliciousbookmarks.xml
index d2bcfc5..87c67dc 100755
--- a/tests/data/BookmarkTest_deliciousbookmarks.xml
+++ b/tests/data/BookmarkTest_deliciousbookmarks.xml
@@ -1,7 +1,7 @@
-
-
-
+
+
+
diff --git a/tests/data/BookmarkTest_netscapebookmarks.html b/tests/data/BookmarkTest_netscapebookmarks.html
index 07c7448..305662c 100755
--- a/tests/data/BookmarkTest_netscapebookmarks.html
+++ b/tests/data/BookmarkTest_netscapebookmarks.html
@@ -6,16 +6,16 @@ It will be read and overwritten.
Do Not Edit! -->
-Bookmarks for dpuser
+Bookmarks for testuser
-Bookmarks for dpuser
+Bookmarks for testuser
-
- Test bookmark 3 for default privacy.
-
- Test bookmark 4 for default privacy.
-
- Test bookmark 5 for default privacy.
+
- Test bookmark 1 for default privacy.
+
- Test bookmark 2 for default privacy.
+
- Test bookmark 3 for default privacy.
- This bookmark will be ignored by importNetscape.php.
--
cgit v1.2.3-54-g00ecf
From b937d6ee42f3d5c0bab83f7cdefd7319837eb2fa Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Mon, 18 Apr 2011 07:50:20 +0200
Subject: fix tests that did not find the data file
---
tests/Api/PostsAddTest.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index 4e2f4fa..1753529 100644
--- a/tests/Api/PostsAddTest.php
+++ b/tests/Api/PostsAddTest.php
@@ -524,7 +524,7 @@ TXT;
$testcookievalue = $uId . ':' . md5($testusername . $testcookiepassword);
$req->setCookieJar(true);
$req->addCookie($testcookiekey, $testcookievalue);
- $req->addUpload('userfile', '../data/BookmarkTest_netscapebookmarks.html');
+ $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_netscapebookmarks.html');
$req->send();
$this->us->setCurrentUserId($uId);
$bms = $this->bs->getBookmarks(0, null, $uId);
@@ -553,7 +553,7 @@ TXT;
$testcookievalue = $uId . ':' . md5($testusername . $testcookiepassword);
$req->setCookieJar(true);
$req->addCookie($testcookiekey, $testcookievalue);
- $req->addUpload('userfile', '../data/BookmarkTest_deliciousbookmarks.xml');
+ $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_deliciousbookmarks.xml');
$req->send();
$this->us->setCurrentUserId($uId);
$bms = $this->bs->getBookmarks(0, null, $uId);
--
cgit v1.2.3-54-g00ecf
From f3fdb6ca14691c91201a4febfe43982f81bd7ce4 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Mon, 18 Apr 2011 19:16:18 +0200
Subject: start the session when we are in http unittest mode
---
src/SemanticScuttle/header.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/SemanticScuttle/header.php b/src/SemanticScuttle/header.php
index 5d1ec80..8668bbb 100644
--- a/src/SemanticScuttle/header.php
+++ b/src/SemanticScuttle/header.php
@@ -104,7 +104,7 @@ T_bind_textdomain_codeset($domain, 'UTF-8');
T_textdomain($domain);
// 4 // Session
-if (!defined('UNIT_TEST_MODE')) {
+if (!defined('UNIT_TEST_MODE') || defined('HTTP_UNIT_TEST_MODE')) {
session_start();
if ($GLOBALS['enableVoting']) {
if (isset($_SESSION['lastUrl'])) {
--
cgit v1.2.3-54-g00ecf
From 87eab925e45dd72e18c097329d5b751fd48ceabb Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Mon, 18 Apr 2011 19:16:58 +0200
Subject: make edit test much easier and do not rely on manual cookie setting
---
tests/Api/PostsAddTest.php | 36 ++++++++++++++++++------------------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index 1753529..3f21add 100644
--- a/tests/Api/PostsAddTest.php
+++ b/tests/Api/PostsAddTest.php
@@ -475,31 +475,31 @@ TXT;
$this->setUnittestConfig(
array('defaults' => array('privacy' => 2))
);
- list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
+
+ list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1');
+ $cookies = $req->getCookieJar();
$req->setMethod(HTTP_Request2::METHOD_POST);
$req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_edit');
$req->addPostParameter('description', 'Test bookmark 2 for default privacy.');
$req->addPostParameter('status', '0');
- $req->send();
+ $res = $req->send();
+ $this->assertEquals(
+ 200, $res->getStatus(),
+ 'Adding bookmark failed: ' . $res->getBody());
$bms = $this->bs->getBookmarks(0, null, $uId);
- $bm = reset($bms['bookmarks']);
+ $bm = reset($bms['bookmarks']);
$bmId = $bm['bId'];
- $oldUid = $uId;
+
$reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1';
- list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
- $req->setMethod(HTTP_Request2::METHOD_POST);
- $req->setUrl($reqUrl);
- $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
- $userinfo = $this->us->getUser($oldUid);
- $testcookiepassword = $userinfo['password'];
- $testusername = $userinfo['username'];
- $testcookievalue = $oldUid . ':' . md5($testusername . $testcookiepassword);
- $req->setCookieJar(true);
- $req->addCookie($testcookiekey, $testcookievalue);
- $req->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit');
- $req->addPostParameter('title', 'Test bookmark 2 for default privacy.');
- $req->addPostParameter('submitted', '1');
- $req->send();
+ $req2 = new HTTP_Request2($reqUrl, HTTP_Request2::METHOD_POST);
+ $req2->setCookieJar($cookies);
+ $req2->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit');
+ $req2->addPostParameter('title', 'Test bookmark 2 for default privacy.');
+ $req2->addPostParameter('submitted', '1');
+ $res = $req2->send();
+
+ $this->assertEquals(302, $res->getStatus(), 'Editing bookmark failed');
+
$bm = $this->bs->getBookmark($bmId);
$this->assertEquals('2', $bm['bStatus']);
}//end testDefaultPrivacyEdit
--
cgit v1.2.3-54-g00ecf
From 5d5ca9efdd31fee53c52c601bdf7511bd67ff655 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Mon, 18 Apr 2011 19:20:58 +0200
Subject: clarify documentation; we are returning get requests
---
tests/TestBaseApi.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php
index 9081a4a..b381dad 100644
--- a/tests/TestBaseApi.php
+++ b/tests/TestBaseApi.php
@@ -63,7 +63,7 @@ class TestBaseApi extends TestBase
/**
- * Gets a HTTP request object.
+ * Creates and returns a HTTP GET request object.
* Uses $this->url plus $urlSuffix as request URL.
*
* @param string $urlSuffix Suffix for the URL
@@ -85,7 +85,7 @@ class TestBaseApi extends TestBase
/**
- * Creates a user and a HTTP request object and prepares
+ * Creates a user and a HTTP GET request object and prepares
* the request object with authentication details, so that
* the user is logged in.
*
@@ -118,7 +118,7 @@ class TestBaseApi extends TestBase
/**
* Creates a user and a HTTP_Request2 object, does a normal login
- * and prepares the cookies for the HTTP request object so that
+ * and prepares the cookies for the HTTP GET request object so that
* the user is seen as logged in when requesting any HTML page.
*
* Useful for testing HTML pages or ajax URLs.
--
cgit v1.2.3-54-g00ecf
From 6f04c888bf400d91437ce33b2718dc8529773337 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Mon, 18 Apr 2011 22:37:42 +0200
Subject: make importnetscape-test easier
---
tests/Api/PostsAddTest.php | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index 3f21add..4b0bb0a 100644
--- a/tests/Api/PostsAddTest.php
+++ b/tests/Api/PostsAddTest.php
@@ -514,18 +514,13 @@ TXT;
$this->setUnittestConfig(
array('defaults' => array('privacy' => 1))
);
- list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
+ list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1');
$req->setMethod(HTTP_Request2::METHOD_POST);
$req->setUrl($GLOBALS['unittestUrl'] . 'importNetscape.php' . '?unittestMode=1');
- $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
- $userinfo = $this->us->getUser($uId);
- $testcookiepassword = $userinfo['password'];
- $testusername = $userinfo['username'];
- $testcookievalue = $uId . ':' . md5($testusername . $testcookiepassword);
- $req->setCookieJar(true);
- $req->addCookie($testcookiekey, $testcookievalue);
$req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_netscapebookmarks.html');
- $req->send();
+ $res = $req->send();
+ $this->assertEquals(200, $res->getStatus(), 'Bookmark import failed');
+
$this->us->setCurrentUserId($uId);
$bms = $this->bs->getBookmarks(0, null, $uId);
$this->assertEquals(3, count($bms['bookmarks']));
--
cgit v1.2.3-54-g00ecf
From 79e3f4e121146254a8e17c3bd271679c815eca8c Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Mon, 18 Apr 2011 22:39:06 +0200
Subject: make import test easier
---
tests/Api/PostsAddTest.php | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index 4b0bb0a..1bd6174 100644
--- a/tests/Api/PostsAddTest.php
+++ b/tests/Api/PostsAddTest.php
@@ -514,7 +514,7 @@ TXT;
$this->setUnittestConfig(
array('defaults' => array('privacy' => 1))
);
- list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1');
+ list($req, $uId) = $this->getLoggedInRequest();
$req->setMethod(HTTP_Request2::METHOD_POST);
$req->setUrl($GLOBALS['unittestUrl'] . 'importNetscape.php' . '?unittestMode=1');
$req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_netscapebookmarks.html');
@@ -538,18 +538,13 @@ TXT;
$this->setUnittestConfig(
array('defaults' => array('privacy' => 2))
);
- list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
+ list($req, $uId) = $this->getLoggedInRequest();
$req->setMethod(HTTP_Request2::METHOD_POST);
$req->setUrl($GLOBALS['unittestUrl'] . 'import.php' . '?unittestMode=1');
- $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
- $userinfo = $this->us->getUser($uId);
- $testcookiepassword = $userinfo['password'];
- $testusername = $userinfo['username'];
- $testcookievalue = $uId . ':' . md5($testusername . $testcookiepassword);
- $req->setCookieJar(true);
- $req->addCookie($testcookiekey, $testcookievalue);
$req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_deliciousbookmarks.xml');
- $req->send();
+ $res = $req->send();
+ $this->assertEquals(302, $res->getStatus(), 'Bookmark import failed');
+
$this->us->setCurrentUserId($uId);
$bms = $this->bs->getBookmarks(0, null, $uId);
$this->assertEquals(3, count($bms['bookmarks']));
--
cgit v1.2.3-54-g00ecf
From da36ba7b7e9e56d7dbf9f516f9b2674b78e10ef9 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Tue, 26 Apr 2011 06:48:26 +0200
Subject: replace deprecated split
---
src/SemanticScuttle/Service/User.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php
index 091ea4d..7f0624e 100644
--- a/src/SemanticScuttle/Service/User.php
+++ b/src/SemanticScuttle/Service/User.php
@@ -359,7 +359,7 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
return (int)$_SESSION[$this->getSessionKey()];
} else if (isset($_COOKIE[$this->getCookieKey()])) {
- $cook = split(':', $_COOKIE[$this->getCookieKey()]);
+ $cook = explode(':', $_COOKIE[$this->getCookieKey()]);
//cookie looks like this: 'id:md5(username+password)'
$query = 'SELECT * FROM '. $this->getTableName() .
' WHERE MD5(CONCAT('.$this->getFieldName('username') .
--
cgit v1.2.3-54-g00ecf
From 106bdcec6637a1a4b01514527753f2724c7b6005 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Tue, 26 Apr 2011 06:53:50 +0200
Subject: replace named html entities with their numeric name to be able to
load the generated pages with an xml parser
---
data/templates/editbookmark.tpl.php | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/data/templates/editbookmark.tpl.php b/data/templates/editbookmark.tpl.php
index dd6b100..6ad422b 100644
--- a/data/templates/editbookmark.tpl.php
+++ b/data/templates/editbookmark.tpl.php
@@ -37,12 +37,12 @@ function jsEscTitle($title)
|
|
- ← |
+ ← |
|
|
- ← |
+ ← |
@@ -50,7 +50,7 @@ function jsEscTitle($title)
|
|
- ←
+ | ←
0): ?>
@@ -67,7 +67,7 @@ function jsEscTitle($title)
|
style="display:none">
|
|
- ←
+ | ←
|
@@ -75,15 +75,15 @@ function jsEscTitle($title)
|
- ← |
+ ← |
|
- " to include one tag in another. e.g.: europe>france>paris')?> |
+ " to include one tag in another. e.g.: europe>france>paris')?> |
|
- |
+ |
|
@@ -111,7 +111,7 @@ function jsEscTitle($title)
echo ' (';
echo T_('edit common description').')';
}
-
+
if ($popup) {
?>
@@ -190,5 +190,5 @@ document.write('<\/ul>');
includeTemplate($GLOBALS['bottom_include']);
+$this->includeTemplate($GLOBALS['bottom_include']);
?>
--
cgit v1.2.3-54-g00ecf
From 8e7138bf1fee4c36326ff07fc5d0a7010d69c440 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Tue, 26 Apr 2011 06:58:49 +0200
Subject: make html valid xml to be able to load it with an xml parser
---
data/templates/editbookmark.tpl.php | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/data/templates/editbookmark.tpl.php b/data/templates/editbookmark.tpl.php
index 6ad422b..25524b9 100644
--- a/data/templates/editbookmark.tpl.php
+++ b/data/templates/editbookmark.tpl.php
@@ -137,11 +137,11 @@ if (empty($_REQUEST['popup']) && (!isset($showdelete) || !$showdelete)) {
?>
-
--
cgit v1.2.3-54-g00ecf
From 43b6021be794ff20af9b423ecfacf382916c80b1 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Tue, 26 Apr 2011 06:59:23 +0200
Subject: use xpath instead of manual string-search to verify test results
---
tests/Api/PostsAddTest.php | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index 1bd6174..bc8f13e 100644
--- a/tests/Api/PostsAddTest.php
+++ b/tests/Api/PostsAddTest.php
@@ -563,12 +563,13 @@ TXT;
$this->setUnittestConfig(
array('defaults' => array('privacy' => 2))
);
- list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
+ list($req, $uId) = $this->getLoggedInRequest();
$req->setMethod(HTTP_Request2::METHOD_POST);
$req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_bookmarksget');
$req->addPostParameter('description', 'Test bookmark 1 for default privacy.');
$req->addPostParameter('status', '0');
$req->send();
+
$bms = $this->bs->getBookmarks(0, null, $uId);
$this->assertEquals(1, count($bms['bookmarks']));
$bm = reset($bms['bookmarks']);
@@ -577,6 +578,7 @@ TXT;
$user = $this->us->getUser($uId);
$userId = $user['username'];
$reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $userId . '?action=get' . '&unittestMode=1';
+
list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
$req->setMethod(HTTP_Request2::METHOD_POST);
$req->setUrl($reqUrl);
@@ -590,15 +592,14 @@ TXT;
$req->addPostParameter('submitted', '1');
$response = $req->send();
$response_body = $response->getBody();
- $start = strpos($response_body, 'Privacy');
- $end = strpos($response_body, 'referrer');
- $length = $end - $start;
- $response_body = substr($response_body, $start, $length);
- $start = strpos($response_body, 'selected');
- $start = $start - 3;
- $length = 1;
- $selected_privacy = substr($response_body, $start, $length);
- $this->assertEquals('2', $selected_privacy);
+
+ $x = simplexml_load_string($response_body);
+ $ns = $x->getDocNamespaces();
+ $x->registerXPathNamespace('ns', reset($ns));
+
+ $elements = $x->xpath('//ns:select[@name="status"]/ns:option[@selected="selected"]');
+ $this->assertEquals(1, count($elements), 'No selected status option found');
+ $this->assertEquals(2, (string)$elements[0]['value']);
}//end testDefaultPrivacyBookmarksGet
--
cgit v1.2.3-54-g00ecf
From 3e5cadc7648658e2c92fbb580d622997f5dc874e Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Tue, 26 Apr 2011 07:00:33 +0200
Subject: use cookie jar instead of manually creating the cookie
---
tests/Api/PostsAddTest.php | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index bc8f13e..b915b4c 100644
--- a/tests/Api/PostsAddTest.php
+++ b/tests/Api/PostsAddTest.php
@@ -564,6 +564,7 @@ TXT;
array('defaults' => array('privacy' => 2))
);
list($req, $uId) = $this->getLoggedInRequest();
+ $cookies = $req->getCookieJar();
$req->setMethod(HTTP_Request2::METHOD_POST);
$req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_bookmarksget');
$req->addPostParameter('description', 'Test bookmark 1 for default privacy.');
@@ -582,13 +583,7 @@ TXT;
list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
$req->setMethod(HTTP_Request2::METHOD_POST);
$req->setUrl($reqUrl);
- $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
- $userinfo = $this->us->getUser($oldUid);
- $testcookiepassword = $userinfo['password'];
- $testusername = $userinfo['username'];
- $testcookievalue = $oldUid . ':' . md5($testusername . $testcookiepassword);
- $req->setCookieJar(true);
- $req->addCookie($testcookiekey, $testcookievalue);
+ $req->setCookieJar($cookies);
$req->addPostParameter('submitted', '1');
$response = $req->send();
$response_body = $response->getBody();
--
cgit v1.2.3-54-g00ecf
From 6b02db7920f09cafadc181bbaed283d5adf6cee6 Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Tue, 26 Apr 2011 07:01:48 +0200
Subject: use cookie jar instead of manually creating the cookie
---
tests/Api/PostsAddTest.php | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index b915b4c..ddaa1fd 100644
--- a/tests/Api/PostsAddTest.php
+++ b/tests/Api/PostsAddTest.php
@@ -573,12 +573,8 @@ TXT;
$bms = $this->bs->getBookmarks(0, null, $uId);
$this->assertEquals(1, count($bms['bookmarks']));
- $bm = reset($bms['bookmarks']);
- $bmId = $bm['bId'];
- $oldUid = $uId;
$user = $this->us->getUser($uId);
- $userId = $user['username'];
- $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $userId . '?action=get' . '&unittestMode=1';
+ $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $user['username'] . '?action=get' . '&unittestMode=1';
list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
$req->setMethod(HTTP_Request2::METHOD_POST);
--
cgit v1.2.3-54-g00ecf
From f629d081ddf52e3cb83ffbfc973a97adc691790c Mon Sep 17 00:00:00 2001
From: Christian Weiske
Date: Mon, 2 May 2011 09:03:35 +0200
Subject: make privacy tests clearer
---
tests/Api/PostsAddTest.php | 75 +++++++++++++++++-----------------------------
tests/TestBaseApi.php | 3 ++
2 files changed, 31 insertions(+), 47 deletions(-)
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index ddaa1fd..3c1177f 100644
--- a/tests/Api/PostsAddTest.php
+++ b/tests/Api/PostsAddTest.php
@@ -423,8 +423,8 @@ TXT;
/**
- * Test that a default privacy setting of 2 (Private) is used in adding
- * a bookmark.
+ * Test that a default privacy setting of 2 (Private) is used in adding
+ * a bookmark.
*/
public function testDefaultPrivacyPrivate()
{
@@ -445,8 +445,8 @@ TXT;
/**
- * Test that a default privacy setting of 0 (Public) is used in adding
- * a bookmark.
+ * Test that a default privacy setting of 0 (Public) is used in adding
+ * a bookmark.
*/
public function testDefaultPrivacyPublic()
{
@@ -490,7 +490,7 @@ TXT;
$bm = reset($bms['bookmarks']);
$bmId = $bm['bId'];
- $reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1';
+ $reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1';
$req2 = new HTTP_Request2($reqUrl, HTTP_Request2::METHOD_POST);
$req2->setCookieJar($cookies);
$req2->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit');
@@ -502,7 +502,7 @@ TXT;
$bm = $this->bs->getBookmark($bmId);
$this->assertEquals('2', $bm['bStatus']);
- }//end testDefaultPrivacyEdit
+ }//end testDefaultPrivacyEdit
/**
@@ -550,15 +550,15 @@ TXT;
$this->assertEquals(3, count($bms['bookmarks']));
$bm = reset($bms['bookmarks']);
$this->assertEquals('2', $bm['bStatus']);
- }//end testDefaultPrivacyImport
+ }//end testDefaultPrivacyImport
/**
- * Test that the default privacy setting is selected in the Privacy
- * drop-down list when an existing bookmark is accessed with bookmarks.php
- * and the get action.
+ * Test that the default privacy setting is selected in the Privacy
+ * drop-down list when adding a new bookmark, sending the form and
+ * missing the title and the privacy setting.
*/
- public function testDefaultPrivacyBookmarksGet()
+ public function testDefaultPrivacyBookmarksAddMissingTitleMissingPrivacy()
{
$this->setUnittestConfig(
array('defaults' => array('privacy' => 2))
@@ -574,7 +574,7 @@ TXT;
$bms = $this->bs->getBookmarks(0, null, $uId);
$this->assertEquals(1, count($bms['bookmarks']));
$user = $this->us->getUser($uId);
- $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $user['username'] . '?action=get' . '&unittestMode=1';
+ $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $user['username'] . '?action=get' . '&unittestMode=1';
list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
$req->setMethod(HTTP_Request2::METHOD_POST);
@@ -595,51 +595,32 @@ TXT;
/**
- * Test that the default privacy setting is selected in the Privacy
- * drop-down list when an existing bookmark is accessed with bookmarks.php
- * and the add action.
+ * Test that the default privacy setting is selected in the Privacy
+ * drop-down list when a new bookmark is being created.
*/
public function testDefaultPrivacyBookmarksAdd()
{
$this->setUnittestConfig(
array('defaults' => array('privacy' => 1))
);
- list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
- $req->setMethod(HTTP_Request2::METHOD_POST);
- $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_bookmarksadd');
- $req->addPostParameter('description', 'Test bookmark 2 for default privacy.');
- $req->addPostParameter('status', '0');
- $req->send();
- $bms = $this->bs->getBookmarks(0, null, $uId);
- $this->assertEquals(1, count($bms['bookmarks']));
- $bm = reset($bms['bookmarks']);
- $bmId = $bm['bId'];
- $oldUid = $uId;
+ list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1');
+
$user = $this->us->getUser($uId);
- $userId = $user['username'];
- $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $userId . '?action=add' . '&unittestMode=1';
- list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
- $req->setMethod(HTTP_Request2::METHOD_POST);
+ $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/'
+ . $user['username'] . '?action=add' . '&unittestMode=1';
$req->setUrl($reqUrl);
- $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';
- $userinfo = $this->us->getUser($oldUid);
- $testcookiepassword = $userinfo['password'];
- $testusername = $userinfo['username'];
- $testcookievalue = $oldUid . ':' . md5($testusername . $testcookiepassword);
- $req->setCookieJar(true);
- $req->addCookie($testcookiekey, $testcookievalue);
- $req->addPostParameter('submitted', '1');
+ $req->setMethod(HTTP_Request2::METHOD_GET);
$response = $req->send();
$response_body = $response->getBody();
- $start = strpos($response_body, 'Privacy');
- $end = strpos($response_body, 'referrer');
- $length = $end - $start;
- $response_body = substr($response_body, $start, $length);
- $start = strpos($response_body, 'selected');
- $start = $start - 3;
- $length = 1;
- $selected_privacy = substr($response_body, $start, $length);
- $this->assertEquals('1', $selected_privacy);
+ $this->assertNotEquals('', $response_body, 'Response is empty');
+
+ $x = simplexml_load_string($response_body);
+ $ns = $x->getDocNamespaces();
+ $x->registerXPathNamespace('ns', reset($ns));
+
+ $elements = $x->xpath('//ns:select[@name="status"]/ns:option[@selected="selected"]');
+ $this->assertEquals(1, count($elements), 'No selected status option found');
+ $this->assertEquals(1, (string)$elements[0]['value']);
}//end testDefaultPrivacyBookmarksAdd
diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php
index b381dad..9759db5 100644
--- a/tests/TestBaseApi.php
+++ b/tests/TestBaseApi.php
@@ -89,6 +89,8 @@ class TestBaseApi extends TestBase
* the request object with authentication details, so that
* the user is logged in.
*
+ * Only usable for API requests, not "normal" HTTP page requests
+ *
* @param string $urlSuffix Suffix for the URL
* @param mixed $auth If user authentication is needed (true/false)
* or array with username and password
@@ -96,6 +98,7 @@ class TestBaseApi extends TestBase
* @return array(HTTP_Request2, integer) HTTP request object and user id
*
* @uses getRequest()
+ * @see getLoggedInRequest()
*/
protected function getAuthRequest($urlSuffix = null, $auth = true)
{
--
cgit v1.2.3-54-g00ecf
From fc093a5fe51d35a2991e549e8836cac15dc2888b Mon Sep 17 00:00:00 2001
From: bretticvs
Date: Thu, 5 May 2011 16:24:21 -0600
Subject: Moved testDefaultPrivacyEdit() to tests/www/editTest.php. Moved
testDefaultPrivacyImportNetscape() to tests/www/importNetscapeTest.php. Moved
testDefaultPrivacyImport() to tests/www/importTest.php. Moved
testDefaultPrivacyBookmarksAddMissingTitleMissingPrivacy() to
tests/www/bookmarksTest.php. Moved testDefaultPrivacyBookmarksAdd() to
tests/www/bookmarksTest.php. Kept testDefaultPrivacyPrivate() in
tests/api/PostsAddTest.php. Kept testDefaultPrivacyPublic() in
tests/api/PostsAddTest.php.
---
tests/Api/PostsAddTest.php | 158 ---------------------------------------
tests/www/bookmarksTest.php | 80 ++++++++++++++++++++
tests/www/editTest.php | 48 ++++++++++++
tests/www/importNetscapeTest.php | 33 ++++++++
tests/www/importTest.php | 33 ++++++++
5 files changed, 194 insertions(+), 158 deletions(-)
create mode 100755 tests/www/bookmarksTest.php
create mode 100755 tests/www/editTest.php
create mode 100755 tests/www/importNetscapeTest.php
create mode 100755 tests/www/importTest.php
diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index 24cc600..02e2b38 100644
--- a/tests/Api/PostsAddTest.php
+++ b/tests/Api/PostsAddTest.php
@@ -452,163 +452,5 @@ TXT;
}//end testDefaultPrivacyPublic
- /**
- * Test that the default privacy setting is used when an existing
- * bookmark is updated with edit.php.
- */
- public function testDefaultPrivacyEdit()
- {
- $this->setUnittestConfig(
- array('defaults' => array('privacy' => 2))
- );
-
- list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1');
- $cookies = $req->getCookieJar();
- $req->setMethod(HTTP_Request2::METHOD_POST);
- $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_edit');
- $req->addPostParameter('description', 'Test bookmark 2 for default privacy.');
- $req->addPostParameter('status', '0');
- $res = $req->send();
- $this->assertEquals(
- 200, $res->getStatus(),
- 'Adding bookmark failed: ' . $res->getBody());
- $bms = $this->bs->getBookmarks(0, null, $uId);
- $bm = reset($bms['bookmarks']);
- $bmId = $bm['bId'];
-
- $reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1';
- $req2 = new HTTP_Request2($reqUrl, HTTP_Request2::METHOD_POST);
- $req2->setCookieJar($cookies);
- $req2->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit');
- $req2->addPostParameter('title', 'Test bookmark 2 for default privacy.');
- $req2->addPostParameter('submitted', '1');
- $res = $req2->send();
-
- $this->assertEquals(302, $res->getStatus(), 'Editing bookmark failed');
-
- $bm = $this->bs->getBookmark($bmId);
- $this->assertEquals('2', $bm['bStatus']);
- }//end testDefaultPrivacyEdit
-
-
- /**
- * Test that the default privacy setting is used when bookmarks
- * are imported from an HTML bookmarks file using importNetscape.php.
- */
- public function testDefaultPrivacyImportNetscape()
- {
- $this->setUnittestConfig(
- array('defaults' => array('privacy' => 1))
- );
- list($req, $uId) = $this->getLoggedInRequest();
- $req->setMethod(HTTP_Request2::METHOD_POST);
- $req->setUrl($GLOBALS['unittestUrl'] . 'importNetscape.php' . '?unittestMode=1');
- $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_netscapebookmarks.html');
- $res = $req->send();
- $this->assertEquals(200, $res->getStatus(), 'Bookmark import failed');
-
- $this->us->setCurrentUserId($uId);
- $bms = $this->bs->getBookmarks(0, null, $uId);
- $this->assertEquals(3, count($bms['bookmarks']));
- $bm = reset($bms['bookmarks']);
- $this->assertEquals('1', $bm['bStatus']);
- }//end testDefaultPrivacyImportNetscape
-
-
- /**
- * Test that the default privacy setting is used when bookmarks
- * are imported from an XML bookmarks file using import.php.
- */
- public function testDefaultPrivacyImport()
- {
- $this->setUnittestConfig(
- array('defaults' => array('privacy' => 2))
- );
- list($req, $uId) = $this->getLoggedInRequest();
- $req->setMethod(HTTP_Request2::METHOD_POST);
- $req->setUrl($GLOBALS['unittestUrl'] . 'import.php' . '?unittestMode=1');
- $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_deliciousbookmarks.xml');
- $res = $req->send();
- $this->assertEquals(302, $res->getStatus(), 'Bookmark import failed');
-
- $this->us->setCurrentUserId($uId);
- $bms = $this->bs->getBookmarks(0, null, $uId);
- $this->assertEquals(3, count($bms['bookmarks']));
- $bm = reset($bms['bookmarks']);
- $this->assertEquals('2', $bm['bStatus']);
- }//end testDefaultPrivacyImport
-
-
- /**
- * Test that the default privacy setting is selected in the Privacy
- * drop-down list when adding a new bookmark, sending the form and
- * missing the title and the privacy setting.
- */
- public function testDefaultPrivacyBookmarksAddMissingTitleMissingPrivacy()
- {
- $this->setUnittestConfig(
- array('defaults' => array('privacy' => 2))
- );
- list($req, $uId) = $this->getLoggedInRequest();
- $cookies = $req->getCookieJar();
- $req->setMethod(HTTP_Request2::METHOD_POST);
- $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_bookmarksget');
- $req->addPostParameter('description', 'Test bookmark 1 for default privacy.');
- $req->addPostParameter('status', '0');
- $req->send();
-
- $bms = $this->bs->getBookmarks(0, null, $uId);
- $this->assertEquals(1, count($bms['bookmarks']));
- $user = $this->us->getUser($uId);
- $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $user['username'] . '?action=get' . '&unittestMode=1';
-
- list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
- $req->setMethod(HTTP_Request2::METHOD_POST);
- $req->setUrl($reqUrl);
- $req->setCookieJar($cookies);
- $req->addPostParameter('submitted', '1');
- $response = $req->send();
- $response_body = $response->getBody();
-
- $x = simplexml_load_string($response_body);
- $ns = $x->getDocNamespaces();
- $x->registerXPathNamespace('ns', reset($ns));
-
- $elements = $x->xpath('//ns:select[@name="status"]/ns:option[@selected="selected"]');
- $this->assertEquals(1, count($elements), 'No selected status option found');
- $this->assertEquals(2, (string)$elements[0]['value']);
- }//end testDefaultPrivacyBookmarksGet
-
-
- /**
- * Test that the default privacy setting is selected in the Privacy
- * drop-down list when a new bookmark is being created.
- */
- public function testDefaultPrivacyBookmarksAdd()
- {
- $this->setUnittestConfig(
- array('defaults' => array('privacy' => 1))
- );
- list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1');
-
- $user = $this->us->getUser($uId);
- $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/'
- . $user['username'] . '?action=add' . '&unittestMode=1';
- $req->setUrl($reqUrl);
- $req->setMethod(HTTP_Request2::METHOD_GET);
- $response = $req->send();
- $response_body = $response->getBody();
- $this->assertNotEquals('', $response_body, 'Response is empty');
-
- $x = simplexml_load_string($response_body);
- $ns = $x->getDocNamespaces();
- $x->registerXPathNamespace('ns', reset($ns));
-
- $elements = $x->xpath('//ns:select[@name="status"]/ns:option[@selected="selected"]');
- $this->assertEquals(1, count($elements), 'No selected status option found');
- $this->assertEquals(1, (string)$elements[0]['value']);
- }//end testDefaultPrivacyBookmarksAdd
-
-
}
?>
diff --git a/tests/www/bookmarksTest.php b/tests/www/bookmarksTest.php
new file mode 100755
index 0000000..df360cc
--- /dev/null
+++ b/tests/www/bookmarksTest.php
@@ -0,0 +1,80 @@
+setUnittestConfig(
+ array('defaults' => array('privacy' => 2))
+ );
+ list($req, $uId) = $this->getLoggedInRequest();
+ $cookies = $req->getCookieJar();
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_bookmarksget');
+ $req->addPostParameter('description', 'Test bookmark 1 for default privacy.');
+ $req->addPostParameter('status', '0');
+ $req->send();
+
+ $bms = $this->bs->getBookmarks(0, null, $uId);
+ $this->assertEquals(1, count($bms['bookmarks']));
+ $user = $this->us->getUser($uId);
+ $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $user['username'] . '?action=get' . '&unittestMode=1';
+
+ list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->setUrl($reqUrl);
+ $req->setCookieJar($cookies);
+ $req->addPostParameter('submitted', '1');
+ $response = $req->send();
+ $response_body = $response->getBody();
+
+ $x = simplexml_load_string($response_body);
+ $ns = $x->getDocNamespaces();
+ $x->registerXPathNamespace('ns', reset($ns));
+
+ $elements = $x->xpath('//ns:select[@name="status"]/ns:option[@selected="selected"]');
+ $this->assertEquals(1, count($elements), 'No selected status option found');
+ $this->assertEquals(2, (string)$elements[0]['value']);
+ }//end testDefaultPrivacyBookmarksAddMissingTitleMissingPrivacy
+
+
+ /**
+ * Test that the default privacy setting is selected in the Privacy
+ * drop-down list when a new bookmark is being created.
+ */
+ public function testDefaultPrivacyBookmarksAdd()
+ {
+ $this->setUnittestConfig(
+ array('defaults' => array('privacy' => 1))
+ );
+ list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1');
+
+ $user = $this->us->getUser($uId);
+ $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/'
+ . $user['username'] . '?action=add' . '&unittestMode=1';
+ $req->setUrl($reqUrl);
+ $req->setMethod(HTTP_Request2::METHOD_GET);
+ $response = $req->send();
+ $response_body = $response->getBody();
+ $this->assertNotEquals('', $response_body, 'Response is empty');
+
+ $x = simplexml_load_string($response_body);
+ $ns = $x->getDocNamespaces();
+ $x->registerXPathNamespace('ns', reset($ns));
+
+ $elements = $x->xpath('//ns:select[@name="status"]/ns:option[@selected="selected"]');
+ $this->assertEquals(1, count($elements), 'No selected status option found');
+ $this->assertEquals(1, (string)$elements[0]['value']);
+ }//end testDefaultPrivacyBookmarksAdd
+
+}//end class www_bookmarksTest
+?>
diff --git a/tests/www/editTest.php b/tests/www/editTest.php
new file mode 100755
index 0000000..1e0fbd5
--- /dev/null
+++ b/tests/www/editTest.php
@@ -0,0 +1,48 @@
+setUnittestConfig(
+ array('defaults' => array('privacy' => 2))
+ );
+
+ list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1');
+ $cookies = $req->getCookieJar();
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_edit');
+ $req->addPostParameter('description', 'Test bookmark 2 for default privacy.');
+ $req->addPostParameter('status', '0');
+ $res = $req->send();
+ $this->assertEquals(
+ 200, $res->getStatus(),
+ 'Adding bookmark failed: ' . $res->getBody());
+ $bms = $this->bs->getBookmarks(0, null, $uId);
+ $bm = reset($bms['bookmarks']);
+ $bmId = $bm['bId'];
+
+ $reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1';
+ $req2 = new HTTP_Request2($reqUrl, HTTP_Request2::METHOD_POST);
+ $req2->setCookieJar($cookies);
+ $req2->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit');
+ $req2->addPostParameter('title', 'Test bookmark 2 for default privacy.');
+ $req2->addPostParameter('submitted', '1');
+ $res = $req2->send();
+
+ $this->assertEquals(302, $res->getStatus(), 'Editing bookmark failed');
+
+ $bm = $this->bs->getBookmark($bmId);
+ $this->assertEquals('2', $bm['bStatus']);
+ }//end testDefaultPrivacyEdit
+
+}//end class www_editTest
+?>
diff --git a/tests/www/importNetscapeTest.php b/tests/www/importNetscapeTest.php
new file mode 100755
index 0000000..9d4cacd
--- /dev/null
+++ b/tests/www/importNetscapeTest.php
@@ -0,0 +1,33 @@
+setUnittestConfig(
+ array('defaults' => array('privacy' => 1))
+ );
+ list($req, $uId) = $this->getLoggedInRequest();
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->setUrl($GLOBALS['unittestUrl'] . 'importNetscape.php' . '?unittestMode=1');
+ $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_netscapebookmarks.html');
+ $res = $req->send();
+ $this->assertEquals(200, $res->getStatus(), 'Bookmark import failed');
+
+ $this->us->setCurrentUserId($uId);
+ $bms = $this->bs->getBookmarks(0, null, $uId);
+ $this->assertEquals(3, count($bms['bookmarks']));
+ $bm = reset($bms['bookmarks']);
+ $this->assertEquals('1', $bm['bStatus']);
+ }//end testDefaultPrivacyImportNetscape
+
+}//end class www_importNetscapeTest
+?>
diff --git a/tests/www/importTest.php b/tests/www/importTest.php
new file mode 100755
index 0000000..895a320
--- /dev/null
+++ b/tests/www/importTest.php
@@ -0,0 +1,33 @@
+setUnittestConfig(
+ array('defaults' => array('privacy' => 2))
+ );
+ list($req, $uId) = $this->getLoggedInRequest();
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->setUrl($GLOBALS['unittestUrl'] . 'import.php' . '?unittestMode=1');
+ $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_deliciousbookmarks.xml');
+ $res = $req->send();
+ $this->assertEquals(302, $res->getStatus(), 'Bookmark import failed');
+
+ $this->us->setCurrentUserId($uId);
+ $bms = $this->bs->getBookmarks(0, null, $uId);
+ $this->assertEquals(3, count($bms['bookmarks']));
+ $bm = reset($bms['bookmarks']);
+ $this->assertEquals('2', $bm['bStatus']);
+ }//end testDefaultPrivacyImport
+
+}//end class www_importTest
+?>
--
cgit v1.2.3-54-g00ecf