]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
Further updates for configurable-privacy2.
authorbretticvs <bsdee@frii.com>
Thu, 31 Mar 2011 05:30:43 +0000 (22:30 -0700)
committerU-SYBASE\bdee <bdee@bdeexp.sybase.com>
Thu, 31 Mar 2011 05:31:51 +0000 (22:31 -0700)
data/config.php.dist
data/templates/bookmarks.tpl.php
tests/BookmarkTest.php

index 0f849e2182b41091a8831632dc29ab98f8b36249..a8d84a687410479026c48191d59445f5639d06bb 100644 (file)
-<?php
-/**
- * Configuration for SemanticScuttle.
- *
- * Copy this file to config.inc.php and adjust it.
- *
- * See config.default.inc.php for more options.
- */
-
-/**
- * Array for defaults.
- *
- * @var array 
- */
-$defaults = array();
-
-/**
- * The name of this site.
- *
- * @var string
- */
-$sitename = 'SemanticScuttle';
-
-/**
- * The welcome message on the homepage.
- *
- * @var string
- */
-$welcomeMessage = 'Welcome to SemanticScuttle! Social bookmarking for small communities.';
-
-/**
- * Translation from locales/ folder.
- *
- * Examples: de_DE, en_GB, fr_FR
- *
- * @var string
- */
-$locale = 'en_GB';
-
-/**
- * Use clean urls without .php filenames.
- * Requires mod_rewrite (for Apache) to be active.
- *
- * @var boolean
- */
-$cleanurls = false;
-
-/**
- * Show debug messages.
- * This setting is recommended when setting up SemanticScuttle,
- * and when hacking on it.
- *
- * @var boolean
- */
-$debugMode = true;
-
-
-/***************************************************
- * Database configuration
- */
-
-/**
- * Database driver
- *
- * available:
- * mysql4, mysqli, mysql, oracle, postgres, sqlite, db2, firebird,
- * mssql, mssq-odbc
- *
- * @var string
- */
-$dbtype = 'mysql4';
-/**
- * Database username
- *
- * @var string
- */
-$dbuser = 'username';
-
-/**
- * Database password
- *
- * @var string
- */
-$dbpass = 'password';
-
-/**
- * Name of database
- *
- * @var string
- */
-$dbname = 'scuttle';
-
-/**
- * Database hostname/IP
- *
- * @var string
- */
-$dbhost = '127.0.0.1';
-
-
-/***************************************************
- * Users
- */
-
-/**
- * Contact address for the site administrator.
- * Used as the FROM address in password retrieval e-mails.
- *
- * @var string
- */
-$adminemail = 'admin@example.org';
-
-/**
- * Array of user names who have admin rights
- *
- * Example:
- * <code>
- * $admin_users = array('adminnickname', 'user1nick', 'user2nick');
- * </code>
- *
- * @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.
-*/
-?>
+<?php\r
+/**\r
+ * Configuration for SemanticScuttle.\r
+ *\r
+ * Copy this file to config.inc.php and adjust it.\r
+ *\r
+ * See config.default.inc.php for more options.\r
+ */\r
+\r
+/**\r
+ * The name of this site.\r
+ *\r
+ * @var string\r
+ */\r
+$sitename = 'SemanticScuttle';\r
+\r
+/**\r
+ * The welcome message on the homepage.\r
+ *\r
+ * @var string\r
+ */\r
+$welcomeMessage = 'Welcome to SemanticScuttle! Social bookmarking for small communities.';\r
+\r
+/**\r
+ * Translation from locales/ folder.\r
+ *\r
+ * Examples: de_DE, en_GB, fr_FR\r
+ *\r
+ * @var string\r
+ */\r
+$locale = 'en_GB';\r
+\r
+/**\r
+ * Use clean urls without .php filenames.\r
+ * Requires mod_rewrite (for Apache) to be active.\r
+ *\r
+ * @var boolean\r
+ */\r
+$cleanurls = false;\r
+\r
+/**\r
+ * Show debug messages.\r
+ * This setting is recommended when setting up SemanticScuttle,\r
+ * and when hacking on it.\r
+ *\r
+ * @var boolean\r
+ */\r
+$debugMode = true;\r
+\r
+\r
+/***************************************************\r
+ * Database configuration\r
+ */\r
+\r
+/**\r
+ * Database driver\r
+ *\r
+ * available:\r
+ * mysql4, mysqli, mysql, oracle, postgres, sqlite, db2, firebird,\r
+ * mssql, mssq-odbc\r
+ *\r
+ * @var string\r
+ */\r
+$dbtype = 'mysql4';\r
+/**\r
+ * Database username\r
+ *\r
+ * @var string\r
+ */\r
+$dbuser = 'username';\r
+\r
+/**\r
+ * Database password\r
+ *\r
+ * @var string\r
+ */\r
+$dbpass = 'password';\r
+\r
+/**\r
+ * Name of database\r
+ *\r
+ * @var string\r
+ */\r
+$dbname = 'scuttle';\r
+\r
+/**\r
+ * Database hostname/IP\r
+ *\r
+ * @var string\r
+ */\r
+$dbhost = '127.0.0.1';\r
+\r
+\r
+/***************************************************\r
+ * Users\r
+ */\r
+\r
+/**\r
+ * Contact address for the site administrator.\r
+ * Used as the FROM address in password retrieval e-mails.\r
+ *\r
+ * @var string\r
+ */\r
+$adminemail = 'admin@example.org';\r
+\r
+/**\r
+ * Array of user names who have admin rights\r
+ *\r
+ * Example:\r
+ * <code>\r
+ * $admin_users = array('adminnickname', 'user1nick', 'user2nick');\r
+ * </code>\r
+ *\r
+ * @var array\r
+ */\r
+$admin_users = array();\r
+\r
+\r
+/***************************************************\r
+ * Bookmarks \r
+ */\r
+\r
+/**\r
+ * Default privacy setting for bookmarks.\r
+ * 0 - Public\r
+ * 1 - Shared with Watchlist\r
+ * 2 - Private\r
+ *\r
+ * @var integer \r
+ */\r
+$defaults['privacy'] = 0;\r
+\r
+\r
+/**\r
+* You have completed the basic configuration!\r
+* More options can be found in config.default.php.\r
+*/\r
+?>\r
index 44dfe905a800248a7a0be4406667afa2945fb356..b241a716aec1320c841e805bf053d0d596c1d954 100644 (file)
-<?php
-/**
- * Show a list of bookmarks.
- *
- * SemanticScuttle - your social bookmark manager.
- *
- * PHP version 5.
- *
- * @category    Bookmarking
- * @package     SemanticScuttle
- * @subcategory Templates
- * @author      Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
- * @author      Christian Weiske <cweiske@cweiske.de>
- * @author      Eric Dane <ericdane@users.sourceforge.net>
- * @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');
-?>
-
-<?php if($pageName == PAGE_INDEX && $GLOBALS['welcomeMessage']):?>
-<p id="welcome"><?php echo $GLOBALS['welcomeMessage'];?></p>
-<?php endif?>
-
-
-<?php if($GLOBALS['enableAdminColors']!=false && isset($userid) && $userservice->isAdmin($userid) && $pageName != PAGE_WATCHLIST) : ?>
-<div style="width:70%;text-align:center;">
-<img src="<?php echo ROOT ?>images/logo_24.gif" width="12px"/> <?php echo T_('Bookmarks on this page are managed by an admin user.'); ?><img src="<?php echo ROOT ?>images/logo_24.gif" width="12px"/>
-</div>
-<?php endif?>
-
-
-<?php
-// common tag description
-if(($currenttag!= '' && $GLOBALS['enableCommonTagDescription'])
-|| (isset($hash) && $GLOBALS['enableCommonBookmarkDescription'])):?>
-
-
-<p class="commondescription"><?php
-$cDescription = '';
-if($currenttag!= '' && $cdservice->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'])). "<br/>";
-       echo nl2br(filter($cDescription['cdDescription'])). "<br/>";
-}
-
-//common tag description edit
-if($userservice->isLoggedOn()) {
-       if($currenttag!= '' && ($GLOBALS['enableCommonTagDescriptionEditedByAll'] || $currentUser->isAdmin())) {
-               echo ' <a href="'. createURL('tagcommondescriptionedit', $currenttag).'" title="'.T_('Edit the common description of this tag').'">';
-               echo !is_array($cDescription) || strlen($cDescription['cdDescription'])==0?T_('Edit the common description of this tag'):'';
-               echo ' <img src="'.ROOT.'images/b_edit.png" /></a>';
-       } elseif(isset($hash)) {
-               echo ' (<a href="'.createURL('bookmarkcommondescriptionedit', $hash).'" title="'.T_('Edit the common description of this bookmark').'">';
-               echo T_('Edit the common description of this bookmark').'</a>)';
-       }
-}
-?></p>
-<?php endif ?>
-
-
-<?php
-/* personal tag description */
-if($currenttag!= '' && $user!='') {
-       $userObject = $userservice->getUserByUsername($user);
-       if($tagservice->getDescription($currenttag, $userObject['uId'])) { ?>
-
-<p class="commondescription"><?php
-$pDescription = $tagservice->getDescription($currenttag, $userObject['uId']);
-echo nl2br(filter($pDescription['tDescription']));
-
-//personal tag description edit
-if($userservice->isLoggedOn()) {
-       if($currenttag!= '') {
-               echo ' <a href="'. createURL('tagedit', $currenttag).'" title="'.T_('Edit your personal description of this tag').'" >';
-               echo strlen($pDescription['tDescription'])==0?T_('Edit your personal description of this tag'):'';
-               echo ' <img src="'.ROOT.'images/b_edit.png" /></a>';
-       }
-}
-?></p>
-
-<?php
-       }
-}
-?>
-
-<?php if (count($bookmarks) > 0) { ?>
-<script type="text/javascript">
-window.onload = playerLoad;
-</script>
-
-<p id="sort"><?php echo $total.' '.T_("bookmark(s)"); ?> - <?php echo T_("Sort by:"); ?>
- <?php
-$titleArrow  = '';
-$dateArrow   = '';
-$votingArrow = '';
-$dateSort    = 'date_desc';
-$titleSort   = 'title_asc';
-$votingSort  = 'voting_desc';
-
-switch(getSortOrder()) {
-case 'date_asc':
-       $dateArrow = ' &uarr;';
-       $dateSort  = 'date_desc';
-       break;
-
-case 'title_asc':
-       $titleArrow = ' &uarr;';
-       $titleSort  = 'title_desc';
-       break;
-
-case 'title_desc':
-       $titleArrow = ' &darr;';
-       $titleSort  = 'title_asc';
-       break;
-
-case 'voting_asc':
-       $votingArrow = ' &uarr;';
-       $votingSort  = 'voting_desc';
-       break;
-
-case 'voting_desc':
-       $votingArrow = ' &darr;';
-       $votingSort  = 'voting_asc';
-       break;
-
-case 'date_desc':
-default:
-       $dateArrow = ' &darr;';
-       $dateSort = 'date_asc';
-       break;
-}
-?>
- <a href="?sort=<?php echo $dateSort ?>"><?php echo T_("Date").$dateArrow; ?></a>
- <span>/</span>
- <a href="?sort=<?php echo $titleSort ?>"><?php echo T_("Title").$titleArrow; ?></a>
- <span>/</span>
-<?php if ($GLOBALS['enableVoting']) { ?>
- <a href="?sort=<?php echo $votingSort ?>"><?php echo T_("Voting").$votingArrow; ?></a>
- <span>/</span>
-<?php } ?>
-
-<?php
-if ($currenttag!= '') {
-       if ($user!= '') {
-               echo ' - ';
-               echo '<a href="'. createURL('tags', $currenttag) .'">';
-               echo T_('Bookmarks from other users for this tag').'</a>';
-               //echo T_(' for these tags');
-       } else if ($userservice->isLoggedOn()){
-               echo ' - ';
-               echo '<a href="'. createURL('bookmarks', $currentUser->getUsername().'/'.$currenttag) .'">';
-               echo T_('Only your bookmarks for this tag').'</a>';
-               //echo T_(' for these tags');
-       }
-}
-?></p>
-
-<?php
-       // PAGINATION
-
-       // Ordering
-       $sortOrder = '';
-       if (GET_SORT != '') {
-               $sortOrder = 'sort=' . getSortOrder();
-       }
-
-       $sortAmp = (($sortOrder) ? '&amp;'. $sortOrder : '');
-       $sortQue = (($sortOrder) ? '?'. $sortOrder : '');
-
-       // Previous
-       $perpage = getPerPageCount($currentUser);
-       if (!$page || $page < 2) {
-               $page = 1;
-               $start = 0;
-               $bfirst = '<span class="disable">'. T_('First') .'</span>';
-               $bprev = '<span class="disable">'. T_('Previous') .'</span>';
-       } else {
-               $prev = $page - 1;
-               $prev = 'page='. $prev;
-               $start = ($page - 1) * $perpage;
-               $bfirst= '<a href="'. sprintf($nav_url, $user, $currenttag, '') . $sortQue .'">'. T_('First') .'</a>';
-               $bprev = '<a href="'. sprintf($nav_url, $user, $currenttag, '?') . $prev . $sortAmp .'">'. T_('Previous') .'</a>';
-       }
-
-       // Next
-       $next = $page + 1;
-       $totalpages = ceil($total / $perpage);
-       if (count($bookmarks) < $perpage || $perpage * $page == $total) {
-               $bnext = '<span class="disable">'. T_('Next') .'</span>';
-               $blast = '<span class="disable">'. T_('Last') ."</span>\n";
-       } else {
-               $bnext = '<a href="'. sprintf($nav_url, $user, $currenttag, '?page=') . $next . $sortAmp .'">'. T_('Next') .'</a>';
-               $blast = '<a href="'. sprintf($nav_url, $user, $currenttag, '?page=') . $totalpages . $sortAmp .'">'. T_('Last') ."</a>\n";
-       }
-
-       // RSS
-       $brss = '';
-       $size = count($rsschannels);
-       for ($i = 0; $i < $size; $i++) {
-               $brss =  '<a style="background:#FFFFFF" href="'. htmlspecialchars($rsschannels[$i][1]) . '"'
-            . ' title="' . htmlspecialchars($rsschannels[$i][0]) . '">'
-            . '<img src="' . ROOT . 'images/rss.gif" width="16" height="16" alt="' . htmlspecialchars($rsschannels[$i][0]) .'"/>'
-            . '</a>';
-       }
-
-       $pagesBanner = '<p class="paging">'. $bfirst .'<span> / </span>'. $bprev .'<span> / </span>'. $bnext .'<span> / </span>'. $blast .'<span> / </span>'. sprintf(T_('Page %d of %d'), $page, $totalpages) ." ". $brss ." </p>\n";
-
-       if (getPerPageCount($currentUser) > 10) {
-               echo $pagesBanner; // display a page banner if too many bookmarks to manage
-       }
-
-
-?>
-
-
-
-<ol<?php echo ($start > 0 ? ' start="'. ++$start .'"' : ''); ?> id="bookmarks">
-<?php
-    $addresses = array();
-    foreach ($bookmarks as $key => &$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(
-                '<a href="%s" rel="tag">%s</a>, ',
-                $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 = ' - <a href="' . createURL('edit', $row['bId']) . '">'
-                . T_('Edit')
-                . '</a>'
-                . '<script type="text/javascript">'
-                . 'document.write(" - <a href=\"#\" onclick=\"deleteBookmark(this, '. $row['bId'] .'); return false;\">'
-                . T_('Delete')
-                .'<\/a>");</script>';
-               }
-
-               // Last update
-               $update = '   <small title="'. T_('Last update') .'">('. date($GLOBALS['shortdate'], strtotime($row['bModified'])). ') </small>';
-
-               // User attribution
-               $copy = '   ' . T_('by') . ' ';
-               if ($userservice->isLoggedOn()
-            && $currentUser->getUsername() == $row['username']
-        ) {
-                       $copy .= T_('you');
-               } else {
-                       $copy .= '<a href="' . createURL('bookmarks', $row['username']) . '">'
-                . $row['username'] . '</a>';
-               }
-
-               // Udders!
-               if (!isset($hash)) {
-                       $others = $otherCounts[$row['bAddress']];
-                       $ostart = '<a href="' . createURL('history', $row['bHash']) . '">';
-                       $oend = '</a>';
-                       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 .= ' - <a href="'
-                . createURL(
-                    'bookmarks',
-                    $currentUser->getUsername()
-                    . '?action=add&amp;copyOf=' . $row['bId'])
-                . '" title="'.T_('Copy this bookmark to YOUR bookmarks.').'">'
-                . T_('Copy')
-                . '</a>';
-               }
-
-               // 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    = ' <img src="'. ROOT .'images/logo_24.gif" width="12px" title="'. T_('This bookmark is certified by an admin user.') .'" />';
-               } 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 ' <li class="xfolkentry'. $access .'">'."\n";
-        include 'bookmarks-thumbnail.inc.tpl.php';
-        include 'bookmarks-vote.inc.tpl.php';
-
-               echo '  <div' . $adminBgClass . '>' . "\n";
-
-               echo '   <div class="link">'
-            . '<a href="'. $address .'"'. $rel .' class="taggedlink" target="_blank">'
-            . filter($row['bTitle'])
-            . '</a>' . $adminStar . "</div>\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('|\[(.*?)\]|', ' <span class="anchorBookmark">$1</span> Â» ', $bkDescription); // highlight starting anchor
-                       $bkDescription = preg_replace('@((http|https|ftp)://.*?)( |\r|$)@', '<a href="$1" rel="nofollow">$1</a>$3', $bkDescription); // make url clickable
-
-               }
-               echo '   <div class="description">'. nl2br($bkDescription) ."</div>\n";
-        echo '   <div class="address">' . shortenString($oaddress) . "</div>\n";
-
-               echo '   <div class="meta">'
-            . $cats . "\n"
-            . $copy . "\n"
-            . $edit . "\n"
-            . $update . "\n"
-            . "  </div>\n";
-               echo $privateNoteField != ''
-            ? '    <div class="privateNote" title="'. T_('Private Note on this bookmark') .'">'.$privateNoteField."</div>\n"
-            : '';
-        echo '  ';
-        include 'bookmarks-vote-horizontal.inc.tpl.php';
-               echo " </div>\n";
-
-               echo " </li>\n";
-       }
-       ?>
-
-</ol>
-
-       <?php
-       if(getPerPageCount($currentUser)>7) {
-               echo '<p class="backToTop"><a href="#header" title="'.T_('Come back to the top of this page.').'">'.T_('Top of the page').'</a></p>';
-       }
-       echo $pagesBanner;  // display previous and next links pages + RSS link
-
-
-} else {
-       echo '<p class="error">'.T_('No bookmarks available').'</p>';
-}
-$this->includeTemplate('sidebar.tpl');
-$this->includeTemplate($GLOBALS['bottom_include']);
-?>
+<?php\r
+/**\r
+ * Show a list of bookmarks.\r
+ *\r
+ * SemanticScuttle - your social bookmark manager.\r
+ *\r
+ * PHP version 5.\r
+ *\r
+ * @category    Bookmarking\r
+ * @package     SemanticScuttle\r
+ * @subcategory Templates\r
+ * @author      Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>\r
+ * @author      Christian Weiske <cweiske@cweiske.de>\r
+ * @author      Eric Dane <ericdane@users.sourceforge.net>\r
+ * @license     GPL http://www.gnu.org/licenses/gpl.html\r
+ * @link        http://sourceforge.net/projects/semanticscuttle\r
+ */\r
+\r
+/* Service creation: only useful services are created */\r
+$bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');\r
+$tagservice      = SemanticScuttle_Service_Factory::get('Tag');\r
+$cdservice       = SemanticScuttle_Service_Factory::get('CommonDescription');\r
+\r
+\r
+$pageName   = isset($pageName) ? $pageName : '';\r
+$user       = isset($user) ? $user : '';\r
+$currenttag = isset($currenttag) ? $currenttag : '';\r
+\r
+\r
+$this->includeTemplate($GLOBALS['top_include']);\r
+\r
+include('search.menu.php');\r
+?>\r
+\r
+<?php if($pageName == PAGE_INDEX && $GLOBALS['welcomeMessage']):?>\r
+<p id="welcome"><?php echo $GLOBALS['welcomeMessage'];?></p>\r
+<?php endif?>\r
+\r
+\r
+<?php if($GLOBALS['enableAdminColors']!=false && isset($userid) && $userservice->isAdmin($userid) && $pageName != PAGE_WATCHLIST) : ?>\r
+<div style="width:70%;text-align:center;">\r
+<img src="<?php echo ROOT ?>images/logo_24.gif" width="12px"/> <?php echo T_('Bookmarks on this page are managed by an admin user.'); ?><img src="<?php echo ROOT ?>images/logo_24.gif" width="12px"/>\r
+</div>\r
+<?php endif?>\r
+\r
+\r
+<?php\r
+// common tag description\r
+if(($currenttag!= '' && $GLOBALS['enableCommonTagDescription'])\r
+|| (isset($hash) && $GLOBALS['enableCommonBookmarkDescription'])):?>\r
+\r
+\r
+<p class="commondescription"><?php\r
+$cDescription = '';\r
+if($currenttag!= '' && $cdservice->getLastTagDescription($currenttag)) {\r
+       $cDescription = $cdservice->getLastTagDescription($currenttag);\r
+       echo nl2br(filter($cDescription['cdDescription']));\r
+} elseif(isset($hash) && $cdservice->getLastBookmarkDescription($hash)) {\r
+       $cDescription = $cdservice->getLastBookmarkDescription($hash);\r
+       echo nl2br(filter($cDescription['cdTitle'])). "<br/>";\r
+       echo nl2br(filter($cDescription['cdDescription'])). "<br/>";\r
+}\r
+\r
+//common tag description edit\r
+if($userservice->isLoggedOn()) {\r
+       if($currenttag!= '' && ($GLOBALS['enableCommonTagDescriptionEditedByAll'] || $currentUser->isAdmin())) {\r
+               echo ' <a href="'. createURL('tagcommondescriptionedit', $currenttag).'" title="'.T_('Edit the common description of this tag').'">';\r
+               echo !is_array($cDescription) || strlen($cDescription['cdDescription'])==0?T_('Edit the common description of this tag'):'';\r
+               echo ' <img src="'.ROOT.'images/b_edit.png" /></a>';\r
+       } elseif(isset($hash)) {\r
+               echo ' (<a href="'.createURL('bookmarkcommondescriptionedit', $hash).'" title="'.T_('Edit the common description of this bookmark').'">';\r
+               echo T_('Edit the common description of this bookmark').'</a>)';\r
+       }\r
+}\r
+?></p>\r
+<?php endif ?>\r
+\r
+\r
+<?php\r
+/* personal tag description */\r
+if($currenttag!= '' && $user!='') {\r
+       $userObject = $userservice->getUserByUsername($user);\r
+       if($tagservice->getDescription($currenttag, $userObject['uId'])) { ?>\r
+\r
+<p class="commondescription"><?php\r
+$pDescription = $tagservice->getDescription($currenttag, $userObject['uId']);\r
+echo nl2br(filter($pDescription['tDescription']));\r
+\r
+//personal tag description edit\r
+if($userservice->isLoggedOn()) {\r
+       if($currenttag!= '') {\r
+               echo ' <a href="'. createURL('tagedit', $currenttag).'" title="'.T_('Edit your personal description of this tag').'" >';\r
+               echo strlen($pDescription['tDescription'])==0?T_('Edit your personal description of this tag'):'';\r
+               echo ' <img src="'.ROOT.'images/b_edit.png" /></a>';\r
+       }\r
+}\r
+?></p>\r
+\r
+<?php\r
+       }\r
+}\r
+?>\r
+\r
+<?php if (count($bookmarks) > 0) { ?>\r
+<script type="text/javascript">\r
+window.onload = playerLoad;\r
+</script>\r
+\r
+<p id="sort"><?php echo $total.' '.T_("bookmark(s)"); ?> - <?php echo T_("Sort by:"); ?>\r
+ <?php\r
+$titleArrow  = '';\r
+$dateArrow   = '';\r
+$votingArrow = '';\r
+$dateSort    = 'date_desc';\r
+$titleSort   = 'title_asc';\r
+$votingSort  = 'voting_desc';\r
+\r
+switch(getSortOrder()) {\r
+case 'date_asc':\r
+       $dateArrow = ' &uarr;';\r
+       $dateSort  = 'date_desc';\r
+       break;\r
+\r
+case 'title_asc':\r
+       $titleArrow = ' &uarr;';\r
+       $titleSort  = 'title_desc';\r
+       break;\r
+\r
+case 'title_desc':\r
+       $titleArrow = ' &darr;';\r
+       $titleSort  = 'title_asc';\r
+       break;\r
+\r
+case 'voting_asc':\r
+       $votingArrow = ' &uarr;';\r
+       $votingSort  = 'voting_desc';\r
+       break;\r
+\r
+case 'voting_desc':\r
+       $votingArrow = ' &darr;';\r
+       $votingSort  = 'voting_asc';\r
+       break;\r
+\r
+case 'date_desc':\r
+default:\r
+       $dateArrow = ' &darr;';\r
+       $dateSort = 'date_asc';\r
+       break;\r
+}\r
+?>\r
+ <a href="?sort=<?php echo $dateSort ?>"><?php echo T_("Date").$dateArrow; ?></a>\r
+ <span>/</span>\r
+ <a href="?sort=<?php echo $titleSort ?>"><?php echo T_("Title").$titleArrow; ?></a>\r
+ <span>/</span>\r
+<?php if ($GLOBALS['enableVoting']) { ?>\r
+ <a href="?sort=<?php echo $votingSort ?>"><?php echo T_("Voting").$votingArrow; ?></a>\r
+ <span>/</span>\r
+<?php } ?>\r
+\r
+<?php\r
+if ($currenttag!= '') {\r
+       if ($user!= '') {\r
+               echo ' - ';\r
+               echo '<a href="'. createURL('tags', $currenttag) .'">';\r
+               echo T_('Bookmarks from other users for this tag').'</a>';\r
+               //echo T_(' for these tags');\r
+       } else if ($userservice->isLoggedOn()){\r
+               echo ' - ';\r
+               echo '<a href="'. createURL('bookmarks', $currentUser->getUsername().'/'.$currenttag) .'">';\r
+               echo T_('Only your bookmarks for this tag').'</a>';\r
+               //echo T_(' for these tags');\r
+       }\r
+}\r
+?></p>\r
+\r
+<?php\r
+       // PAGINATION\r
+\r
+       // Ordering\r
+       $sortOrder = '';\r
+       if (GET_SORT != '') {\r
+               $sortOrder = 'sort=' . getSortOrder();\r
+       }\r
+\r
+       $sortAmp = (($sortOrder) ? '&amp;'. $sortOrder : '');\r
+       $sortQue = (($sortOrder) ? '?'. $sortOrder : '');\r
+\r
+       // Previous\r
+       $perpage = getPerPageCount($currentUser);\r
+       if (!$page || $page < 2) {\r
+               $page = 1;\r
+               $start = 0;\r
+               $bfirst = '<span class="disable">'. T_('First') .'</span>';\r
+               $bprev = '<span class="disable">'. T_('Previous') .'</span>';\r
+       } else {\r
+               $prev = $page - 1;\r
+               $prev = 'page='. $prev;\r
+               $start = ($page - 1) * $perpage;\r
+               $bfirst= '<a href="'. sprintf($nav_url, $user, $currenttag, '') . $sortQue .'">'. T_('First') .'</a>';\r
+               $bprev = '<a href="'. sprintf($nav_url, $user, $currenttag, '?') . $prev . $sortAmp .'">'. T_('Previous') .'</a>';\r
+       }\r
+\r
+       // Next\r
+       $next = $page + 1;\r
+       $totalpages = ceil($total / $perpage);\r
+       if (count($bookmarks) < $perpage || $perpage * $page == $total) {\r
+               $bnext = '<span class="disable">'. T_('Next') .'</span>';\r
+               $blast = '<span class="disable">'. T_('Last') ."</span>\n";\r
+       } else {\r
+               $bnext = '<a href="'. sprintf($nav_url, $user, $currenttag, '?page=') . $next . $sortAmp .'">'. T_('Next') .'</a>';\r
+               $blast = '<a href="'. sprintf($nav_url, $user, $currenttag, '?page=') . $totalpages . $sortAmp .'">'. T_('Last') ."</a>\n";\r
+       }\r
+\r
+       // RSS\r
+       $brss = '';\r
+       $size = count($rsschannels);\r
+       for ($i = 0; $i < $size; $i++) {\r
+               $brss =  '<a style="background:#FFFFFF" href="'. htmlspecialchars($rsschannels[$i][1]) . '"'\r
+            . ' title="' . htmlspecialchars($rsschannels[$i][0]) . '">'\r
+            . '<img src="' . ROOT . 'images/rss.gif" width="16" height="16" alt="' . htmlspecialchars($rsschannels[$i][0]) .'"/>'\r
+            . '</a>';\r
+       }\r
+\r
+       $pagesBanner = '<p class="paging">'. $bfirst .'<span> / </span>'. $bprev .'<span> / </span>'. $bnext .'<span> / </span>'. $blast .'<span> / </span>'. sprintf(T_('Page %d of %d'), $page, $totalpages) ." ". $brss ." </p>\n";\r
+\r
+       if (getPerPageCount($currentUser) > 10) {\r
+               echo $pagesBanner; // display a page banner if too many bookmarks to manage\r
+       }\r
+\r
+\r
+?>\r
+\r
+\r
+\r
+<ol<?php echo ($start > 0 ? ' start="'. ++$start .'"' : ''); ?> id="bookmarks">\r
+<?php\r
+    $addresses = array();\r
+    foreach ($bookmarks as $key => &$row) {\r
+        $addresses[$row['bId']] = $row['bAddress'];\r
+    }\r
+    $otherCounts = $bookmarkservice->countOthers($addresses);\r
+    if ($userservice->isLoggedOn()) {\r
+        $existence = $bookmarkservice->bookmarksExist(\r
+            $addresses, $currentUser->getId()\r
+        );\r
+    }\r
+\r
+    if ($userservice->isLoggedOn()) {\r
+        $watchedNames = $userservice->getWatchNames(\r
+            $currentUser->getId(), true\r
+        );\r
+    } else {\r
+        $watchedNames = null;\r
+    }\r
+\r
+       foreach ($bookmarks as $key => &$row) {\r
+               switch ($row['bStatus']) {\r
+                       case 0:\r
+                               $access = '';\r
+                               break;\r
+                       case 1:\r
+                               $access = ' shared';\r
+                               break;\r
+                       case 2:\r
+                               $access = ' private';\r
+                               break;\r
+               }\r
+\r
+               $cats = '';\r
+               $tagsForCopy = '';\r
+               $tags = $row['tags'];\r
+               foreach ($tags as $tkey => &$tag) {\r
+            $tagcaturl = sprintf(\r
+                $cat_url,\r
+                filter($row['username'], 'url'),\r
+                filter($tag, 'url')\r
+            );\r
+                       $cats .= sprintf(\r
+                '<a href="%s" rel="tag">%s</a>, ',\r
+                $tagcaturl, filter($tag)\r
+            );\r
+                       $tagsForCopy .= $tag . ',';\r
+               }\r
+               $cats = substr($cats, 0, -2);\r
+               if ($cats != '') {\r
+                       $cats = T_('Tags:') . ' ' . $cats;\r
+               }\r
+\r
+               // Edit and delete links\r
+               $edit = '';\r
+               if ($bookmarkservice->editAllowed($row)) {\r
+                       $edit = ' - <a href="' . createURL('edit', $row['bId']) . '">'\r
+                . T_('Edit')\r
+                . '</a>'\r
+                . '<script type="text/javascript">'\r
+                . 'document.write(" - <a href=\"#\" onclick=\"deleteBookmark(this, '. $row['bId'] .'); return false;\">'\r
+                . T_('Delete')\r
+                .'<\/a>");</script>';\r
+               }\r
+\r
+               // Last update\r
+               $update = '   <small title="'. T_('Last update') .'">('. date($GLOBALS['shortdate'], strtotime($row['bModified'])). ') </small>';\r
+\r
+               // User attribution\r
+               $copy = '   ' . T_('by') . ' ';\r
+               if ($userservice->isLoggedOn()\r
+            && $currentUser->getUsername() == $row['username']\r
+        ) {\r
+                       $copy .= T_('you');\r
+               } else {\r
+                       $copy .= '<a href="' . createURL('bookmarks', $row['username']) . '">'\r
+                . $row['username'] . '</a>';\r
+               }\r
+\r
+               // Udders!\r
+               if (!isset($hash)) {\r
+                       $others = $otherCounts[$row['bAddress']];\r
+                       $ostart = '<a href="' . createURL('history', $row['bHash']) . '">';\r
+                       $oend = '</a>';\r
+                       switch ($others) {\r
+                               case 0:\r
+                                       break;\r
+                               case 1:\r
+                                       $copy .= sprintf(T_(' and %s1 other%s'), $ostart, $oend);\r
+                                       break;\r
+                               default:\r
+                                       $copy .= sprintf(T_(' and %2$s%1$s others%3$s'), $others, $ostart, $oend);\r
+                       }\r
+               }\r
+\r
+               // Copy link\r
+               if ($userservice->isLoggedOn()\r
+            && ($currentUser->getId() != $row['uId'])\r
+            && !$existence[$row['bAddress']]\r
+        ) {\r
+                       $copy .= ' - <a href="'\r
+                . createURL(\r
+                    'bookmarks',\r
+                    $currentUser->getUsername()\r
+                    . '?action=add&amp;copyOf=' . $row['bId'])\r
+                . '" title="'.T_('Copy this bookmark to YOUR bookmarks.').'">'\r
+                . T_('Copy')\r
+                . '</a>';\r
+               }\r
+\r
+               // Nofollow option\r
+               $rel = '';\r
+               if ($GLOBALS['nofollow']) {\r
+                       $rel = ' rel="nofollow"';\r
+               }\r
+\r
+               $address  = filter($row['bAddress']);\r
+               $oaddress = $address;\r
+               // Redirection option\r
+               if ($GLOBALS['useredir']) {\r
+                       $address = $GLOBALS['url_redir'] . $address;\r
+               }\r
+\r
+               // Admin specific design\r
+               if ($userservice->isAdmin($row['username']) && $GLOBALS['enableAdminColors']) {\r
+                       $adminBgClass = ' class="adminBackground"';\r
+                       $adminStar    = ' <img src="'. ROOT .'images/logo_24.gif" width="12px" title="'. T_('This bookmark is certified by an admin user.') .'" />';\r
+               } else {\r
+                       $adminBgClass = '';\r
+                       $adminStar    = '';\r
+               }\r
+\r
+               // Private Note (just visible by the owner and his/her contacts)\r
+        if ($watchedNames !== null\r
+            && ($currentUser->getId() == $row['uId']\r
+                || in_array($row['username'], $watchedNames)\r
+            )\r
+        ) {\r
+                       $privateNoteField = $row['bPrivateNote'];\r
+               } else {\r
+                       $privateNoteField = '';\r
+               }\r
+\r
+        if ($GLOBALS['enableVoting'] && $GLOBALS['hideBelowVoting'] !== null\r
+            && $row['bVoting'] < $GLOBALS['hideBelowVoting']\r
+        ) {\r
+            $access .= ' below-threshold';\r
+        }\r
+\r
+               // Output\r
+               echo ' <li class="xfolkentry'. $access .'">'."\n";\r
+        include 'bookmarks-thumbnail.inc.tpl.php';\r
+        include 'bookmarks-vote.inc.tpl.php';\r
+\r
+               echo '  <div' . $adminBgClass . '>' . "\n";\r
+\r
+               echo '   <div class="link">'\r
+            . '<a href="'. $address .'"'. $rel .' class="taggedlink" target="_blank">'\r
+            . filter($row['bTitle'])\r
+            . '</a>' . $adminStar . "</div>\n";\r
+               if ($row['bDescription'] == '') {\r
+                       $bkDescription = $GLOBALS['blankDescription'];\r
+               } else {\r
+                       // Improve description display (anchors, links, ...)\r
+                       $bkDescription = preg_replace('|\[\/.*?\]|', '', filter($row['bDescription'])); // remove final anchor\r
+                       $bkDescription = preg_replace('|\[(.*?)\]|', ' <span class="anchorBookmark">$1</span> Â» ', $bkDescription); // highlight starting anchor\r
+                       $bkDescription = preg_replace('@((http|https|ftp)://.*?)( |\r|$)@', '<a href="$1" rel="nofollow">$1</a>$3', $bkDescription); // make url clickable\r
+\r
+               }\r
+               echo '   <div class="description">'. nl2br($bkDescription) ."</div>\n";\r
+        echo '   <div class="address">' . shortenString($oaddress) . "</div>\n";\r
+\r
+               echo '   <div class="meta">'\r
+            . $cats . "\n"\r
+            . $copy . "\n"\r
+            . $edit . "\n"\r
+            . $update . "\n"\r
+            . "  </div>\n";\r
+               echo $privateNoteField != ''\r
+            ? '    <div class="privateNote" title="'. T_('Private Note on this bookmark') .'">'.$privateNoteField."</div>\n"\r
+            : '';\r
+        echo '  ';\r
+        include 'bookmarks-vote-horizontal.inc.tpl.php';\r
+               echo " </div>\n";\r
+\r
+               echo " </li>\n";\r
+       }\r
+       ?>\r
+\r
+</ol>\r
+\r
+       <?php\r
+       if(getPerPageCount($currentUser)>7) {\r
+               echo '<p class="backToTop"><a href="#header" title="'.T_('Come back to the top of this page.').'">'.T_('Top of the page').'</a></p>';\r
+       }\r
+       echo $pagesBanner;  // display previous and next links pages + RSS link\r
+\r
+\r
+} else {\r
+       echo '<p class="error">'.T_('No bookmarks available').'</p>';\r
+}\r
+$this->includeTemplate('sidebar.tpl');\r
+$this->includeTemplate($GLOBALS['bottom_include']);\r
+?>\r
index aa0b8c3aa51918d9ae72e3f25ed5ecf3a7728bd0..0912d55cc821dcbb8afc873b1ee5a32094a5cedc 100644 (file)
-<?php
-/**
- * SemanticScuttle - your social bookmark manager.
- *
- * PHP version 5.
- *
- * @category Bookmarking
- * @package  SemanticScuttle
- * @author   Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
- * @author   Christian Weiske <cweiske@cweiske.de>
- * @author   Eric Dane <ericdane@users.sourceforge.net>
- * @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 <mensonge@users.sourceforge.net>
- * @author   Christian Weiske <cweiske@cweiske.de>
- * @author   Eric Dane <ericdane@users.sourceforge.net>
- * @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();
-}
-?>
+<?php\r
+/**\r
+ * SemanticScuttle - your social bookmark manager.\r
+ *\r
+ * PHP version 5.\r
+ *\r
+ * @category Bookmarking\r
+ * @package  SemanticScuttle\r
+ * @author   Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>\r
+ * @author   Christian Weiske <cweiske@cweiske.de>\r
+ * @author   Eric Dane <ericdane@users.sourceforge.net>\r
+ * @license  GPL http://www.gnu.org/licenses/gpl.html\r
+ * @link     http://sourceforge.net/projects/semanticscuttle\r
+ */\r
+if (!defined('PHPUnit_MAIN_METHOD')) {\r
+    define('PHPUnit_MAIN_METHOD', 'BookmarkTest::main');\r
+}\r
+\r
+require_once 'prepare.php';\r
+\r
+/**\r
+ * Unit tests for the SemanticScuttle bookmark service.\r
+ *\r
+ * @category Bookmarking\r
+ * @package  SemanticScuttle\r
+ * @author   Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>\r
+ * @author   Christian Weiske <cweiske@cweiske.de>\r
+ * @author   Eric Dane <ericdane@users.sourceforge.net>\r
+ * @license  GPL http://www.gnu.org/licenses/gpl.html\r
+ * @link     http://sourceforge.net/projects/semanticscuttle\r
+ */\r
+class BookmarkTest extends TestBase\r
+{\r
+    protected $us;\r
+    protected $bs;\r
+    protected $ts;\r
+    protected $tts;\r
+\r
+\r
+\r
+    /**\r
+     * Used to run this test class standalone\r
+     *\r
+     * @return void\r
+     */\r
+    public static function main()\r
+    {\r
+        require_once 'PHPUnit/TextUI/TestRunner.php';\r
+        PHPUnit_TextUI_TestRunner::run(\r
+            new PHPUnit_Framework_TestSuite(__CLASS__)\r
+        );\r
+    }\r
+\r
+\r
+\r
+    protected function setUp()\r
+    {\r
+        $this->us = SemanticScuttle_Service_Factory::get('User');\r
+        $this->bs = SemanticScuttle_Service_Factory::get('Bookmark');\r
+        $this->bs->deleteAll();\r
+        $this->b2ts= SemanticScuttle_Service_Factory::get('Bookmark2Tag');\r
+        $this->b2ts->deleteAll();\r
+        $this->tts = SemanticScuttle_Service_Factory::get('Tag2Tag');\r
+        $this->tts->deleteAll();\r
+        $this->tsts = SemanticScuttle_Service_Factory::get('TagStat');\r
+        $this->tsts->deleteAll();\r
+        $this->vs = SemanticScuttle_Service_Factory::get('Vote');\r
+        $this->vs->deleteAll();\r
+    }\r
+\r
+    /**\r
+     * Tests if adding a bookmark with short url name\r
+     * saves it in the database.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testAddBookmarkShort()\r
+    {\r
+        $bid = $this->bs->addBookmark(\r
+            'http://example.org', 'title', 'desc', 'priv',\r
+            0, array(), 'myShortName'\r
+        );\r
+        $bm = $this->bs->getBookmark($bid);\r
+        $this->assertEquals('http://example.org', $bm['bAddress']);\r
+        $this->assertArrayHasKey('bShort', $bm);\r
+        $this->assertEquals('myShortName', $bm['bShort']);\r
+    }\r
+\r
+    public function testHardCharactersInBookmarks()\r
+    {\r
+        $bs = $this->bs;\r
+        $title = "title&é\"'(-è_çà)=";\r
+        $desc = "description#{[|`\^@]}³<> Â¹Â¡Ã·Ã—¿&é\"'(-è\\_çà)=";\r
+        $tag1 = "#{|`^@]³¹¡¿<&é\"'(-è\\_çà)";\r
+        $tag2 = "&é\"'(-è.[?./§!_çà)";\r
+\r
+        $uid = $this->addUser();\r
+        $bid = $bs->addBookmark(\r
+            'http://site1.com', $title, $desc, 'note',\r
+            0, array($tag1, $tag2),\r
+            null, null, false, false, $uid\r
+        );\r
+\r
+        $bookmarks = $bs->getBookmarks(0, 1);\r
+\r
+        $b0 = $bookmarks['bookmarks'][0];\r
+        $this->assertEquals($title, $b0['bTitle']);\r
+        $this->assertEquals($desc, $b0['bDescription']);\r
+        $this->assertEquals(\r
+            str_replace(array('"', '\'', '/'), "_", $tag1),\r
+            $b0['tags'][0]\r
+        );\r
+        $this->assertEquals(\r
+            str_replace(array('"', '\'', '/'), "_", $tag2),\r
+            $b0['tags'][1]\r
+        );\r
+    }\r
+\r
+    public function testUnificationOfBookmarks()\r
+    {\r
+        $bs = $this->bs;\r
+\r
+        $uid  = $this->addUser();\r
+        $uid2 = $this->addUser();\r
+\r
+        $bs->addBookmark(\r
+            'http://site1.com', "title", "description", 'note',\r
+            0, array('tag1'), null, null, false, false,\r
+            $uid\r
+        );\r
+        $bs->addBookmark(\r
+            "http://site1.com", "title2", "description2", 'note',\r
+            0, array('tag2'), null, null, false, false,\r
+            $uid2\r
+        );\r
+\r
+        $bookmarks = $bs->getBookmarks();\r
+        $this->assertEquals(1, $bookmarks['total']);\r
+    }\r
+\r
+    /*public function testSearchingBookmarksAccentsInsensible()\r
+     {\r
+     $bs = $this->bs;\r
+\r
+     $bs->addBookmark("http://site1.com", "title", "éèüaàê", "status", array('tag1'), null, false, false, 1);\r
+     $bookmarks =& $bs->getBookmarks(0, NULL, NULL, NULL, $terms = "eeaae"); //void\r
+     $this->assertEquals(0, $bookmarks['total']);\r
+     $bookmarks =& $bs->getBookmarks(0, NULL, NULL, NULL, $terms = "eeuaae");\r
+     $this->assertEquals(1, $bookmarks['total']);\r
+     }*/\r
+\r
+\r
+\r
+    /**\r
+     * Tests if bookmarkExists() returns false when the given\r
+     * parameter is invalid.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testBookmarkExistsInvalidParam()\r
+    {\r
+        $this->assertFalse($this->bs->bookmarkExists(false));\r
+        $this->assertFalse($this->bs->bookmarkExists(null));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Tests if bookmarkExists() returns true when a bookmark\r
+     * exists\r
+     *\r
+     * @return void\r
+     */\r
+    public function testBookmarkExistsTrue()\r
+    {\r
+        $bid = $this->addBookmark();\r
+        $bookmark = $this->bs->getBookmark($bid);\r
+\r
+        $this->assertTrue($this->bs->bookmarkExists($bookmark['bAddress']));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Tests if bookmarkExists() returns false when a bookmark\r
+     * does not exist\r
+     *\r
+     * @return void\r
+     */\r
+    public function testBookmarkExistsFalse()\r
+    {\r
+        $this->assertFalse($this->bs->bookmarkExists('does-not-exist'));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Tests if bookmarkExists() returns true when a bookmark\r
+     * exists for a user\r
+     *\r
+     * @return void\r
+     */\r
+    public function testBookmarkExistsUserTrue()\r
+    {\r
+        $bid = $this->addBookmark();\r
+        $bookmark = $this->bs->getBookmark($bid);\r
+\r
+        $this->assertTrue(\r
+            $this->bs->bookmarkExists(\r
+                $bookmark['bAddress'],\r
+                $bookmark['uId']\r
+            )\r
+        );\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Tests if bookmarkExists() returns false when a bookmark\r
+     * does not exist for a user\r
+     *\r
+     * @return void\r
+     */\r
+    public function testBookmarkExistsUserFalse()\r
+    {\r
+        $this->assertFalse(\r
+            $this->bs->bookmarkExists('does-not-exist', 1234)\r
+        );\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Tests if bookmarkExists() returns false when a bookmark\r
+     * does not exist for a user but for another user\r
+     *\r
+     * @return void\r
+     */\r
+    public function testBookmarkExistsOtherUser()\r
+    {\r
+        $bid = $this->addBookmark();\r
+        $bookmark = $this->bs->getBookmark($bid);\r
+\r
+        $this->assertFalse(\r
+            $this->bs->bookmarkExists(\r
+                $bookmark['bAddress'],\r
+                $bookmark['uId'] + 1\r
+            )\r
+        );\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Tests if bookmarksExist() returns true when a bookmark\r
+     * exists\r
+     *\r
+     * @return void\r
+     */\r
+    public function testBookmarksExistTrueSingle()\r
+    {\r
+        $bid = $this->addBookmark();\r
+        $bookmark = $this->bs->getBookmark($bid);\r
+\r
+        $ret = $this->bs->bookmarksExist(array($bookmark['bAddress']));\r
+        $this->assertInternalType('array', $ret);\r
+        $this->assertEquals(1, count($ret));\r
+        $this->assertTrue($ret[$bookmark['bAddress']]);\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Tests if bookmarksExist() returns true when all bookmarks\r
+     * exist\r
+     *\r
+     * @return void\r
+     */\r
+    public function testBookmarksExistTrueMultiple()\r
+    {\r
+        $bid = $this->addBookmark();\r
+        $bookmark = $this->bs->getBookmark($bid);\r
+\r
+        $bid2 = $this->addBookmark();\r
+        $bookmark2 = $this->bs->getBookmark($bid2);\r
+\r
+\r
+        $ret = $this->bs->bookmarksExist(\r
+            array(\r
+                $bookmark['bAddress'],\r
+                $bookmark2['bAddress']\r
+            )\r
+        );\r
+        $this->assertInternalType('array', $ret);\r
+        $this->assertEquals(2, count($ret));\r
+        $this->assertTrue($ret[$bookmark['bAddress']]);\r
+        $this->assertTrue($ret[$bookmark2['bAddress']]);\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Tests if bookmarksExist() returns false when a bookmark\r
+     * does not exist\r
+     *\r
+     * @return void\r
+     */\r
+    public function testBookmarksExistFalseSingle()\r
+    {\r
+        $ret = $this->bs->bookmarksExist(array('does-not-exist'));\r
+        $this->assertInternalType('array', $ret);\r
+        $this->assertEquals(1, count($ret));\r
+        $this->assertFalse($ret['does-not-exist']);\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Tests if bookmarksExist() returns false when all bookmarks\r
+     * do not exist\r
+     *\r
+     * @return void\r
+     */\r
+    public function testBookmarksExistFalseMultiple()\r
+    {\r
+        $bms = array(\r
+            'does-not-exist',\r
+            'does-not-exist-2',\r
+            'does-not-exist-3',\r
+        );\r
+        $ret = $this->bs->bookmarksExist($bms);\r
+        $this->assertInternalType('array', $ret);\r
+        $this->assertEquals(3, count($ret));\r
+        $this->assertFalse($ret['does-not-exist']);\r
+        $this->assertFalse($ret['does-not-exist-2']);\r
+        $this->assertFalse($ret['does-not-exist-3']);\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Tests if bookmarksExist() returns true when some bookmarks\r
+     * exist.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testBookmarksExistSome()\r
+    {\r
+        $bid = $this->addBookmark();\r
+        $bookmark = $this->bs->getBookmark($bid);\r
+\r
+        $bid2 = $this->addBookmark();\r
+        $bookmark2 = $this->bs->getBookmark($bid2);\r
+\r
+        //do not search for this one\r
+        $bid3 = $this->addBookmark();\r
+        $bookmark3 = $this->bs->getBookmark($bid3);\r
+\r
+\r
+        $ret = $this->bs->bookmarksExist(\r
+            array(\r
+                $bookmark['bAddress'],\r
+                'does-not-exist',\r
+                $bookmark2['bAddress'],\r
+                'does-not-exist-2',\r
+                'does-not-exist-3'\r
+            )\r
+        );\r
+        $this->assertInternalType('array', $ret);\r
+        $this->assertEquals(5, count($ret));\r
+        $this->assertTrue($ret[$bookmark['bAddress']]);\r
+        $this->assertTrue($ret[$bookmark2['bAddress']]);\r
+        $this->assertFalse($ret['does-not-exist']);\r
+        $this->assertFalse($ret['does-not-exist-2']);\r
+        $this->assertFalse($ret['does-not-exist-3']);\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test if countBookmarks() works with no bookmarks\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountBookmarksNone()\r
+    {\r
+        $uid = $this->addUser();\r
+        $this->assertEquals(0, $this->bs->countBookmarks($uid));\r
+        $this->assertEquals(0, $this->bs->countBookmarks($uid, 'public'));\r
+        $this->assertEquals(0, $this->bs->countBookmarks($uid, 'private'));\r
+        $this->assertEquals(0, $this->bs->countBookmarks($uid, 'shared'));\r
+        $this->assertEquals(0, $this->bs->countBookmarks($uid, 'all'));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test if countBookmarks() works with one public bookmark\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountBookmarksOnePublic()\r
+    {\r
+        $uid = $this->addUser();\r
+        $this->addBookmark($uid);\r
+        $this->assertEquals(1, $this->bs->countBookmarks($uid));\r
+        $this->assertEquals(1, $this->bs->countBookmarks($uid, 'public'));\r
+        $this->assertEquals(0, $this->bs->countBookmarks($uid, 'private'));\r
+        $this->assertEquals(0, $this->bs->countBookmarks($uid, 'shared'));\r
+        $this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test if countBookmarks() works with one private bookmark\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountBookmarksOnePrivate()\r
+    {\r
+        $uid = $this->addUser();\r
+        $this->bs->addBookmark(\r
+            'http://test', 'test', 'desc', 'note',\r
+            2,//private\r
+            array(), null, null, false, false, $uid\r
+        );\r
+        $this->assertEquals(0, $this->bs->countBookmarks($uid));\r
+        $this->assertEquals(0, $this->bs->countBookmarks($uid, 'public'));\r
+        $this->assertEquals(1, $this->bs->countBookmarks($uid, 'private'));\r
+        $this->assertEquals(0, $this->bs->countBookmarks($uid, 'shared'));\r
+        $this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test if countBookmarks() works with one shared bookmark\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountBookmarksOneShared()\r
+    {\r
+        $uid = $this->addUser();\r
+        $this->bs->addBookmark(\r
+            'http://test', 'test', 'desc', 'note',\r
+            1,//shared\r
+            array(), null, null, false, false, $uid\r
+        );\r
+        $this->assertEquals(0, $this->bs->countBookmarks($uid));\r
+        $this->assertEquals(0, $this->bs->countBookmarks($uid, 'public'));\r
+        $this->assertEquals(0, $this->bs->countBookmarks($uid, 'private'));\r
+        $this->assertEquals(1, $this->bs->countBookmarks($uid, 'shared'));\r
+        $this->assertEquals(1, $this->bs->countBookmarks($uid, 'all'));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Check tag loading functionality of getBookmarks()\r
+     *\r
+     * @return void\r
+     */\r
+    public function testGetBookmarksIncludeTags()\r
+    {\r
+        $uid = $this->addUser();\r
+        $bid = $this->addBookmark($uid);\r
+        $this->b2ts->attachTags($bid, array('foo', 'bar'));\r
+        $bid2 = $this->addBookmark($uid);\r
+        $this->b2ts->attachTags($bid2, array('fuu', 'baz'));\r
+\r
+        $bms = $this->bs->getBookmarks();\r
+        $this->assertEquals(2, count($bms['bookmarks']));\r
+        $this->assertEquals(2, $bms['total']);\r
+\r
+        foreach ($bms['bookmarks'] as $bm) {\r
+            $this->assertArrayHasKey('tags', $bm);\r
+            $this->assertInternalType('array', $bm['tags']);\r
+            if ($bm['bId'] == $bid) {\r
+                $this->assertContains('foo', $bm['tags']);\r
+                $this->assertContains('bar', $bm['tags']);\r
+            } else if ($bm['bId'] == $bid2) {\r
+                $this->assertContains('fuu', $bm['tags']);\r
+                $this->assertContains('baz', $bm['tags']);\r
+            } else {\r
+                $this->assertTrue(false, 'Unknown bookmark id');\r
+            }\r
+        }\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test if deleting a bookmark works.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testDeleteBookmark()\r
+    {\r
+        $bookmarks = $this->bs->getBookmarks();\r
+        $this->assertEquals(0, $bookmarks['total']);\r
+\r
+        $bid = $this->addBookmark();\r
+        $bookmarks = $this->bs->getBookmarks();\r
+        $this->assertEquals(1, $bookmarks['total']);\r
+\r
+        $bid2 = $this->addBookmark();\r
+        $bookmarks = $this->bs->getBookmarks();\r
+        $this->assertEquals(2, $bookmarks['total']);\r
+\r
+        $this->assertTrue($this->bs->deleteBookmark($bid));\r
+        $bookmarks = $this->bs->getBookmarks();\r
+        $this->assertEquals(1, $bookmarks['total']);\r
+\r
+        $this->assertTrue($this->bs->deleteBookmark($bid2));\r
+        $bookmarks = $this->bs->getBookmarks();\r
+        $this->assertEquals(0, $bookmarks['total']);\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test if deleting all bookmarks for a user works.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testDeleteBookmarksForUser()\r
+    {\r
+        $uid = $this->addUser();\r
+        $bookmarks = $this->bs->getBookmarks(0, null, $uid);\r
+        $this->assertEquals(0, $bookmarks['total']);\r
+\r
+        $this->addBookmark($uid);\r
+        $this->addBookmark($uid);\r
+        $bookmarks = $this->bs->getBookmarks(0, null, $uid);\r
+        $this->assertEquals(2, $bookmarks['total']);\r
+\r
+        $this->bs->deleteBookmarksForUser($uid);\r
+        $bookmarks = $this->bs->getBookmarks(0, null, $uid);\r
+        $this->assertEquals(0, $bookmarks['total']);\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test if deleting all bookmarks for a user works\r
+     * and does not damage other user's bookmarks.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testDeleteBookmarksForUserOthers()\r
+    {\r
+        $uidOther = $this->addUser();\r
+        $this->addBookmark($uidOther);\r
+\r
+        $uid = $this->addUser();\r
+        $bookmarks = $this->bs->getBookmarks(0, null, $uid);\r
+        $this->assertEquals(0, $bookmarks['total']);\r
+\r
+        $this->addBookmark($uid);\r
+        $this->addBookmark($uid);\r
+        $bookmarks = $this->bs->getBookmarks(0, null, $uid);\r
+        $this->assertEquals(2, $bookmarks['total']);\r
+\r
+        $this->bs->deleteBookmarksForUser($uid);\r
+        $bookmarks = $this->bs->getBookmarks(0, null, $uid);\r
+        $this->assertEquals(0, $bookmarks['total']);\r
+\r
+        $bookmarks = $this->bs->getBookmarks(0, null, $uidOther);\r
+        $this->assertEquals(1, $bookmarks['total']);\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test if deleting a bookmark with a vote works.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testDeleteBookmarkWithVote()\r
+    {\r
+        $GLOBALS['enableVoting'] = true;\r
+\r
+        $uid = $this->addUser();\r
+        $bid = $this->addBookmark();\r
+\r
+        $bid = $this->addBookmark();\r
+        $this->vs->vote($bid, $uid, 1);\r
+        $this->assertTrue($this->vs->hasVoted($bid, $uid));\r
+\r
+        $bid2 = $this->addBookmark();\r
+        $this->vs->vote($bid2, $uid, 1);\r
+        $this->assertTrue($this->vs->hasVoted($bid2, $uid));\r
+\r
+        $this->assertTrue($this->bs->deleteBookmark($bid));\r
+        $this->assertFalse($this->vs->hasVoted($bid, $uid));\r
+        $this->assertTrue($this->vs->hasVoted($bid2, $uid));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test if editAllowed() returns false when the bookmark\r
+     * id is invalid.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testEditAllowedInvalidBookmarkId()\r
+    {\r
+        $this->assertFalse($this->bs->editAllowed('invalid'));\r
+        $this->assertFalse($this->bs->editAllowed(array()));\r
+        $this->assertFalse($this->bs->editAllowed(array('some', 'where')));\r
+        $this->assertFalse($this->bs->editAllowed(array('bId' => false)));\r
+        $this->assertFalse($this->bs->editAllowed(array('bId' => 'foo')));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test if editAllowed() works when passing the ID of\r
+     * an existing bookmark.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testEditAllowedBookmarkId()\r
+    {\r
+        $uid = $this->addUser();\r
+        $bid = $this->addBookmark($uid);\r
+        $this->us->setCurrentUserId($uid);\r
+        $this->assertTrue($this->bs->editAllowed($bid));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test if editAllowed() works when passing the ID of\r
+     * an existing bookmark that does not belong to the current\r
+     * user.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testEditAllowedBookmarkIdNotOwn()\r
+    {\r
+        $uid = $this->addUser();\r
+        $bid = $this->addBookmark();\r
+        $this->us->setCurrentUserId($uid);\r
+        $this->assertFalse($this->bs->editAllowed($bid));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test if editAllowed() works when passing the ID of\r
+     * an existing bookmark that does not belong to the current\r
+     * user.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testEditAllowedBookmarkIdNoUser()\r
+    {\r
+        $bid = $this->addBookmark();\r
+        $this->us->setCurrentUserId(null);\r
+        $this->assertFalse($this->bs->editAllowed($bid));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test if editAllowed() works when passing a bookmark\r
+     * row.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testEditAllowedBookmarkRow()\r
+    {\r
+        $uid = $this->addUser();\r
+        $this->us->setCurrentUserId($uid);\r
+\r
+        $bid = $this->addBookmark($uid);\r
+        $bookmark = $this->bs->getBookmark($bid);\r
+        $this->assertTrue($this->bs->editAllowed($bookmark));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test if editAllowed() returns false when the bookmark\r
+     * specified by the ID does not exist.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testEditAllowedIdNotFound()\r
+    {\r
+        $this->assertFalse($this->bs->editAllowed(98765));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test if editAllowed() works when the user is an administrator.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testEditAllowedBookmarkAdmin()\r
+    {\r
+        //make the user admin\r
+        $uid = $this->addUser();\r
+        $user = $this->us->getUser($uid);\r
+        $GLOBALS['admin_users'][] = $user['username'];\r
+\r
+        $bid = $this->addBookmark($uid);\r
+        $this->us->setCurrentUserId($uid);\r
+        $this->assertTrue($this->bs->editAllowed($bid));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Verify that getBookmark() returns false when the\r
+     * bookmark cannot be found.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testGetBookmarkNotFound()\r
+    {\r
+        $this->assertFalse($this->bs->getBookmark(987654));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Verify that getBookmark() returns false when the\r
+     * bookmark ID is not numeric\r
+     *\r
+     * @return void\r
+     */\r
+    public function testGetBookmarkInvalidParam()\r
+    {\r
+        $this->assertFalse($this->bs->getBookmark('foo'));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Check tag loading functionality of getBookmark()\r
+     *\r
+     * @return void\r
+     */\r
+    public function testGetBookmarkIncludeTags()\r
+    {\r
+        $uid = $this->addUser();\r
+        $bid = $this->addBookmark($uid);\r
+        $this->b2ts->attachTags($bid, array('foo', 'bar'));\r
+        $bid2 = $this->addBookmark($uid);\r
+        $this->b2ts->attachTags($bid2, array('fuu', 'baz'));\r
+\r
+        $bm = $this->bs->getBookmark($bid, true);\r
+        $this->assertArrayHasKey('tags', $bm);\r
+        $this->assertInternalType('array', $bm['tags']);\r
+        $this->assertContains('foo', $bm['tags']);\r
+        $this->assertContains('bar', $bm['tags']);\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Verify that getBookmark() does not include user voting\r
+     * data when no user is logged on.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testGetBookmarkUserVotingNoUser()\r
+    {\r
+        $GLOBALS['enableVoting'] = true;\r
+\r
+        $uid = $this->addUser();\r
+        $bid = $this->addBookmark($uid);\r
+        //no user\r
+        $this->us->setCurrentUserId(null);\r
+\r
+        $bm = $this->bs->getBookmark($bid);\r
+        $this->assertArrayNotHasKey('hasVoted', $bm);\r
+        $this->assertArrayNotHasKey('vote', $bm);\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Verify that getBookmark() automatically includes\r
+     * voting data of the currently logged on user,\r
+     * even if he did not vote yet.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testGetBookmarkUserVotingWithUserNoVote()\r
+    {\r
+        $GLOBALS['enableVoting'] = true;\r
+\r
+        $uid = $this->addUser();\r
+        $bid = $this->addBookmark($uid);\r
+        //log user in\r
+        $this->us->setCurrentUserId($uid);\r
+\r
+        $bm = $this->bs->getBookmark($bid);\r
+        $this->assertArrayHasKey('hasVoted', $bm);\r
+        $this->assertArrayHasKey('vote', $bm);\r
+        $this->assertEquals(0, $bm['hasVoted']);\r
+        $this->assertEquals(null, $bm['vote']);\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Verify that getBookmark() automatically includes\r
+     * voting data of the currently logged on user\r
+     * when he voted positive.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testGetBookmarkUserVotingWithUserPositiveVote()\r
+    {\r
+        $GLOBALS['enableVoting'] = true;\r
+\r
+        $uid = $this->addUser();\r
+        $bid = $this->addBookmark($uid);\r
+        //log user in\r
+        $this->us->setCurrentUserId($uid);\r
+        $this->assertTrue($this->vs->vote($bid, $uid, 1));\r
+\r
+        $bm = $this->bs->getBookmark($bid);\r
+        $this->assertArrayHasKey('hasVoted', $bm);\r
+        $this->assertArrayHasKey('vote', $bm);\r
+        $this->assertEquals(1, $bm['hasVoted']);\r
+        $this->assertEquals(1, $bm['vote']);\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Verify that getBookmark() automatically includes\r
+     * voting data of the currently logged on user\r
+     * when he voted positive.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testGetBookmarkUserVotingWithUserNegativeVote()\r
+    {\r
+        $GLOBALS['enableVoting'] = true;\r
+\r
+        $uid = $this->addUser();\r
+        $bid = $this->addBookmark($uid);\r
+        //log user in\r
+        $this->us->setCurrentUserId($uid);\r
+        $this->assertTrue($this->vs->vote($bid, $uid, -1));\r
+\r
+        $bm = $this->bs->getBookmark($bid);\r
+        $this->assertArrayHasKey('hasVoted', $bm);\r
+        $this->assertArrayHasKey('vote', $bm);\r
+        $this->assertEquals(1, $bm['hasVoted']);\r
+        $this->assertEquals(-1, $bm['vote']);\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Tests if getBookmarkByAddress() works correctly.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testGetBookmarkByAddress()\r
+    {\r
+        $url = 'http://example.org';\r
+        $uid = $this->addUser();\r
+        $bid = $this->addBookmark($uid, $url);\r
+\r
+        $bm = $this->bs->getBookmarkByAddress($url);\r
+        $this->assertInternalType('array', $bm);\r
+        $this->assertEquals($url, $bm['bAddress']);\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Tests if getBookmarkByAddress() works correctly with aliases.\r
+     * When passing an incomplete address i.e. without protocol,\r
+     * the full URL needs to be searched for.\r
+     *\r
+     * The failure of this test lead to #2953732.\r
+     *\r
+     * @return void\r
+     *\r
+     * @link https://sourceforge.net/tracker/?func=detail&atid=1017430&aid=2953732&group_id=211356\r
+     */\r
+    public function testGetBookmarkByAddressAlias()\r
+    {\r
+        $url = 'http://example.org';\r
+        $incomplete = 'example.org';\r
+\r
+        $uid = $this->addUser();\r
+        $bid = $this->addBookmark($uid, $url);\r
+\r
+        $bm = $this->bs->getBookmarkByAddress($incomplete);\r
+        $this->assertInternalType('array', $bm);\r
+        $this->assertEquals($url, $bm['bAddress']);\r
+    }\r
+\r
+\r
+\r
+    public function testNormalize()\r
+    {\r
+        $this->assertEquals(\r
+            'http://example.org', $this->bs->normalize('http://example.org')\r
+        );\r
+        $this->assertEquals(\r
+            'ftp://example.org', $this->bs->normalize('ftp://example.org')\r
+        );\r
+        $this->assertEquals(\r
+            'http://example.org', $this->bs->normalize('http://example.org/')\r
+        );\r
+        $this->assertEquals(\r
+            'http://example.org', $this->bs->normalize('example.org')\r
+        );\r
+        $this->assertEquals(\r
+            'mailto:foo@example.org',\r
+            $this->bs->normalize('mailto:foo@example.org')\r
+        );\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * test if updating an existing bookmark works\r
+     */\r
+    public function testUpdateBookmark()\r
+    {\r
+        $bid = $this->addBookmark();\r
+        $this->assertTrue(\r
+            $this->bs->updateBookmark(\r
+                $bid,\r
+                'http://example.org/foo',\r
+                'my new title',\r
+                'new description',\r
+                'new private note',\r
+                1,\r
+                array('new')\r
+            )\r
+        );\r
+        $bm = $this->bs->getBookmark($bid, true);\r
+        $this->assertEquals('http://example.org/foo', $bm['bAddress']);\r
+        $this->assertEquals('my new title', $bm['bTitle']);\r
+        $this->assertEquals('new description', $bm['bDescription']);\r
+        $this->assertEquals('new private note', $bm['bPrivateNote']);\r
+        $this->assertEquals(1, $bm['bStatus']);\r
+        $this->assertInternalType('array', $bm['tags']);\r
+        $this->assertEquals(1, count($bm['tags']));\r
+        $this->assertContains('new', $bm['tags']);\r
+    }\r
+\r
+    /**\r
+     * Tests if updating a bookmark's short url name\r
+     * saves it in the database.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testUpdateBookmarkShort()\r
+    {\r
+        $bid = $this->bs->addBookmark(\r
+            'http://example.org', 'title', 'desc', 'priv',\r
+            0, array(), 'myShortName'\r
+        );\r
+        $bm = $this->bs->getBookmark($bid);\r
+        $this->assertEquals('myShortName', $bm['bShort']);\r
+\r
+        $this->assertTrue(\r
+            $this->bs->updateBookmark(\r
+                $bid, 'http://example2.org', 'my title', 'desc',\r
+                'priv', 0, array(), 'newShortNambb'\r
+            )\r
+        );\r
+        $bm = $this->bs->getBookmark($bid);\r
+        $this->assertEquals('newShortNambb', $bm['bShort']);\r
+    }\r
+\r
+    /**\r
+     * Tests if updating a bookmark's date works.\r
+     * This once was a bug, see bug #3073215.\r
+     *\r
+     * @return void\r
+     *\r
+     * @link https://sourceforge.net/tracker/?func=detail&atid=1017430&aid=3073215&group_id=211356\r
+     */\r
+    public function testUpdateBookmarkDate()\r
+    {\r
+        $bid = $this->bs->addBookmark(\r
+            'http://example.org', 'title', 'desc', 'priv',\r
+            0, array(), 'myShortName'\r
+        );\r
+        $bm = $this->bs->getBookmark($bid);\r
+        $this->assertEquals('myShortName', $bm['bShort']);\r
+\r
+        $this->assertTrue(\r
+            $this->bs->updateBookmark(\r
+                $bid, 'http://example2.org', 'my title', 'desc',\r
+                'priv', 0, array(), 'newShortNambb',\r
+                //we need to use zulu (GMT) time zone here\r
+                // since the dates/times are stored as that\r
+                // in the database\r
+                '2002-03-04T05:06:07Z'\r
+            )\r
+        );\r
+        $bm = $this->bs->getBookmark($bid);\r
+        $this->assertEquals('newShortNambb', $bm['bShort']);\r
+        $this->assertEquals('2002-03-04 05:06:07', $bm['bDatetime']);\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test what countOther() returns when the address does not exist\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountOthersAddressDoesNotExist()\r
+    {\r
+        $this->assertEquals(0, $this->bs->countOthers('http://example.org'));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test what countOther() returns when nobody else has the same bookmark\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountOthersNone()\r
+    {\r
+        $uid = $this->addUser();\r
+        $address = 'http://example.org';\r
+        $this->addBookmark($uid, $address);\r
+        $this->assertEquals(0, $this->bs->countOthers($address));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test what countOther() returns when the address exists only once\r
+     * and multiple bookmarks are in the database.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountOthersMultipleNone()\r
+    {\r
+        $uid = $this->addUser();\r
+        $address = 'http://example.org';\r
+        $this->addBookmark($uid, $address);\r
+        $this->addBookmark($uid);\r
+        $this->addBookmark($uid);\r
+        $this->assertEquals(0, $this->bs->countOthers($address));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test what countOther() returns when the address exists only once\r
+     * and the same user and other users have other bookmarks\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountOthersMultipleUsersNone()\r
+    {\r
+        $uid  = $this->addUser();\r
+        $uid2 = $this->addUser();\r
+        $address = 'http://example.org';\r
+        $this->addBookmark($uid, $address);\r
+        $this->addBookmark($uid);\r
+        $this->addBookmark($uid2);\r
+        $this->assertEquals(0, $this->bs->countOthers($address));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test what countOther() returns when the address exists two\r
+     * times in the database.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountOthersOne()\r
+    {\r
+        $uid  = $this->addUser();\r
+        $uid2 = $this->addUser();\r
+        $address = 'http://example.org';\r
+        $this->addBookmark($uid, $address);\r
+        $this->addBookmark($uid2, $address);\r
+        $this->assertEquals(1, $this->bs->countOthers($address));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test what countOther() returns when the address exists four\r
+     * times in the database.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountOthersThree()\r
+    {\r
+        $uid  = $this->addUser();\r
+        $address = 'http://example.org';\r
+        $this->addBookmark($uid, $address);\r
+        $this->addBookmark(null, $address);\r
+        $this->addBookmark(null, $address);\r
+        $this->addBookmark(null, $address);\r
+        $this->assertEquals(3, $this->bs->countOthers($address));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test what countOther() returns when the user is logged in\r
+     * and a friend (people on the watchlist) has bookmarked\r
+     * and the same address with public status.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountOthersWatchlistPublic()\r
+    {\r
+        $uid  = $this->addUser();\r
+        $address = 'http://example.org';\r
+\r
+        //create other user and add main user to his watchlist\r
+        $friendPublic1 = $this->addUser();\r
+        $this->us->setCurrentUserId($friendPublic1);\r
+        $this->us->setWatchStatus($uid);\r
+\r
+        //create bookmarks for main user and other one\r
+        $this->addBookmark($uid, $address, 0);\r
+        $this->addBookmark($friendPublic1,  $address, 0);//0 is public\r
+\r
+        //log main user in\r
+        $this->us->setCurrentUserId($uid);\r
+\r
+        $this->assertEquals(1, $this->bs->countOthers($address));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test what countOther() returns when the user is logged in\r
+     * and a friend (people on the watchlist) has bookmarked\r
+     * and shared the same address for the watchlist.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountOthersWatchlistShared()\r
+    {\r
+        $uid  = $this->addUser();\r
+        $address = 'http://example.org';\r
+\r
+        //create other user and add main user to his watchlist\r
+        $friendPublic1 = $this->addUser();\r
+        $this->us->setCurrentUserId($friendPublic1);\r
+        $this->us->setWatchStatus($uid);\r
+\r
+        //create bookmarks for main user and other one\r
+        $this->addBookmark($uid, $address, 0);\r
+        $this->addBookmark($friendPublic1,  $address, 1);//1 is shared\r
+\r
+        //log main user in\r
+        $this->us->setCurrentUserId($uid);\r
+\r
+        $this->assertEquals(1, $this->bs->countOthers($address));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test what countOther() returns when the user is logged in\r
+     * and one friends (people on the watchlist) has bookmarked\r
+     * the same address but made it private.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountOthersWatchlistPrivate()\r
+    {\r
+        $uid  = $this->addUser();\r
+        $address = 'http://example.org';\r
+\r
+        //create other user and add main user to his watchlist\r
+        $friendPublic1 = $this->addUser();\r
+        $this->us->setCurrentUserId($friendPublic1);\r
+        $this->us->setWatchStatus($uid);\r
+\r
+        //create bookmarks for main user and other one\r
+        $this->addBookmark($uid, $address, 0);\r
+        $this->addBookmark($friendPublic1,  $address, 2);//2 is private\r
+\r
+        //log main user in\r
+        $this->us->setCurrentUserId($uid);\r
+\r
+        $this->assertEquals(0, $this->bs->countOthers($address));\r
+    }\r
+\r
+\r
+    /**\r
+     * Test what countOther() returns when the user is logged in\r
+     * and friends (people on the watchlist) have bookmarked\r
+     * and shared the same address.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountOthersWatchlistComplex()\r
+    {\r
+        $uid  = $this->addUser();\r
+        $address = 'http://example.org';\r
+        //log user in\r
+        $this->us->setCurrentUserId($uid);\r
+\r
+        //setup users\r
+        $otherPublic1   = $this->addUser();\r
+        $otherPublic2   = $this->addUser();\r
+        $otherShared1   = $this->addUser();\r
+        $otherPrivate1  = $this->addUser();\r
+        $friendPublic1  = $this->addUser();\r
+        $friendShared1  = $this->addUser();\r
+        $friendShared2  = $this->addUser();\r
+        $friendPrivate1 = $this->addUser();\r
+        $friendSharing1 = $this->addUser();\r
+\r
+        //setup watchlists\r
+        $us = SemanticScuttle_Service_Factory::get('User');\r
+        $this->us->setCurrentUserId($friendPublic1);\r
+        $us->setWatchStatus($uid);\r
+        $this->us->setCurrentUserId($friendShared1);\r
+        $us->setWatchStatus($uid);\r
+        $this->us->setCurrentUserId($friendShared2);\r
+        $us->setWatchStatus($uid);\r
+        $this->us->setCurrentUserId($friendPrivate1);\r
+        $us->setWatchStatus($uid);\r
+\r
+        //back to login of main user\r
+        $this->us->setCurrentUserId($uid);\r
+        $us->setWatchStatus($friendSharing1);\r
+\r
+        //add bookmarks\r
+        $this->addBookmark($uid, $address, 0);\r
+        $this->addBookmark($otherPublic1,   $address, 0);\r
+        $this->addBookmark($otherPublic2,   $address, 0);\r
+        $this->addBookmark($otherShared1,   $address, 1);\r
+        $this->addBookmark($otherPrivate1,  $address, 2);\r
+        $this->addBookmark($friendPublic1,  $address, 0);\r
+        $this->addBookmark($friendShared1,  $address, 1);\r
+        $this->addBookmark($friendShared2,  $address, 1);\r
+        $this->addBookmark($friendPrivate1, $address, 2);\r
+        //this user is on our watchlist, but we not on his\r
+        $this->addBookmark($friendSharing1, $address, 1);\r
+\r
+        //2 public\r
+        //1 public (friend)\r
+        //2 shared\r
+        //-> 5\r
+        $this->assertEquals(5, $this->bs->countOthers($address));\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test what countOther() returns when multiple addresses are\r
+     * passed to it and none of them exists.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountOthersArrayNone()\r
+    {\r
+        $this->assertEquals(\r
+            array('1' => 0, '2' => 0, '3' => 0),\r
+            $this->bs->countOthers(array('1', '2', '3'))\r
+        );\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test what countOther() returns when multiple addresses are\r
+     * passed to it and only one of them exists.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountOthersArrayOneNone()\r
+    {\r
+        $uid  = $this->addUser();\r
+        $uid2 = $this->addUser();\r
+        $address1 = 'http://example.org/1';\r
+        $address2 = 'http://example.org/2';\r
+        $this->addBookmark($uid, $address1);\r
+        $this->addBookmark($uid, $address2);\r
+        $this->addBookmark($uid2, $address1);\r
+        $this->assertEquals(\r
+            array(\r
+                $address1 => 1,\r
+                $address2 => 0\r
+            ),\r
+            $this->bs->countOthers(\r
+                array($address1, $address2)\r
+            )\r
+        );\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * Test what countOther() returns when multiple addresses are passed\r
+     * to it and both of them exist with different numbers for each.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testCountOthersArrayTwoOne()\r
+    {\r
+        $uid  = $this->addUser();\r
+        $uid2 = $this->addUser();\r
+        $uid3 = $this->addUser();\r
+\r
+        $address1 = 'http://example.org/1';\r
+        $address2 = 'http://example.org/2';\r
+\r
+        $this->addBookmark($uid, $address1);\r
+        $this->addBookmark($uid, $address2);\r
+\r
+        $this->addBookmark($uid2, $address1);\r
+        $this->addBookmark($uid2, $address2);\r
+\r
+        $this->addBookmark($uid3, $address1);\r
+\r
+        $this->assertEquals(\r
+            array(\r
+                $address1 => 2,\r
+                $address2 => 1\r
+            ),\r
+            $this->bs->countOthers(\r
+                array($address1, $address2)\r
+            )\r
+        );\r
+    }\r
+\r
+\r
+    /**\r
+     * Test that the default privacy setting in \r
+     * $GLOBALS['defaults']['privacy'] is used\r
+     * as expected.\r
+     *\r
+     * @return void\r
+     */\r
+    public function testDefaultPrivacy()\r
+    {\r
+        //For this test, the default privacy has been set to 2 (private) in the configuration file.\r
+        require_once 'HTTP/Request2.php';\r
+        require_once dirname(__FILE__) . '/../data/config.php';\r
+        $this->bs->deleteAll();\r
+        $this->us->deleteAll();\r
+        $request = new HTTP_Request2('http://localhost/api/posts_add.php', HTTP_Request2::METHOD_POST);\r
+        $dpuid = $this->addUser('dpuser', 'dpuserpassword');\r
+        $request->setAuth('dpuser', 'dpuserpassword'); \r
+        $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com');\r
+        $request->addPostParameter('description', 'Test bookmark 1 for default privacy.');\r
+        $request->send();\r
+        $bm = $this->bs->getBookmark('1');\r
+        $this->assertEquals('2', $bm['bStatus']);\r
+\r
+        $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add2.com');\r
+        $request->addPostParameter('description', 'Test bookmark 2 for default privacy.');\r
+        $request->addPostParameter('status', '0');\r
+        $request->send();\r
+\r
+        $request = new HTTP_Request2('http://localhost/edit.php/2', HTTP_Request2::METHOD_POST);\r
+        $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login';\r
+        $userinfo = $this->us->getUser('1');\r
+        $testcookiepassword = $userinfo['password'];\r
+        $testcookievalue = '1:'.md5('dpuser'.$testcookiepassword);\r
+        $request->setCookieJar(true);\r
+        $request->addCookie($testcookiekey, $testcookievalue);\r
+        $request->addPostParameter('title', 'Test bookmark 2 for default privacy.');\r
+        $request->addPostParameter('address', 'http://www.testdefaultprivacyposts_add2.com');\r
+        $request->addPostParameter('submitted', '1');\r
+        $request->send();\r
+        $bm = $this->bs->getBookmark('2');\r
+        $this->assertEquals('2', $bm['bStatus']);\r
+\r
+        $request = new HTTP_Request2('http://localhost/importNetscape.php', HTTP_Request2::METHOD_POST);\r
+        $request->setCookieJar(true);\r
+        $request->addCookie($testcookiekey, $testcookievalue);\r
+        $request->addUpload('userfile', './data/BookmarkTest_netscapebookmarks.html');\r
+        $request->send();\r
+        $bm = $this->bs->getBookmark('3');\r
+        $this->assertEquals('2', $bm['bStatus']);\r
+        $bm = $this->bs->getBookmark('4');\r
+        $this->assertEquals('2', $bm['bStatus']);\r
+        $bm = $this->bs->getBookmark('5');\r
+        $this->assertEquals('2', $bm['bStatus']);\r
+\r
+        $request = new HTTP_Request2('http://localhost/import.php', HTTP_Request2::METHOD_POST);\r
+        $request->setCookieJar(true);\r
+        $request->addCookie($testcookiekey, $testcookievalue);\r
+        $request->addUpload('userfile', './data/BookmarkTest_deliciousbookmarks.xml');\r
+        $request->send();\r
+        $bm = $this->bs->getBookmark('6');\r
+        $this->assertEquals('2', $bm['bStatus']);\r
+        $bm = $this->bs->getBookmark('7');\r
+        $this->assertEquals('2', $bm['bStatus']);\r
+        $bm = $this->bs->getBookmark('8');\r
+        $this->assertEquals('2', $bm['bStatus']);\r
+\r
+        $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=get', HTTP_Request2::METHOD_POST);\r
+        $request->setCookieJar(true);\r
+        $request->addCookie($testcookiekey, $testcookievalue);\r
+        $request->addPostParameter('submitted', '1');\r
+        $response = $request->send();\r
+        $response_body = $response->getBody();\r
+        $start = strpos($response_body, 'Privacy');\r
+        $end = strpos($response_body, 'referrer');\r
+        $length = $end - $start;\r
+        $response_body = substr($response_body, $start, $length);\r
+        $start = strpos($response_body, 'selected');\r
+        $start = $start - 3;\r
+        $length = 1;\r
+        $selected_privacy = substr($response_body, $start, $length);\r
+        $this->assertEquals('2', $selected_privacy);\r
+\r
+        $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=add', HTTP_Request2::METHOD_POST);\r
+        $request->setCookieJar(true);\r
+        $request->addCookie($testcookiekey, $testcookievalue);\r
+        $response = $request->send();\r
+        $response_body = $response->getBody();\r
+        $start = strpos($response_body, 'Privacy');\r
+        $end = strpos($response_body, 'referrer');\r
+        $length = $end - $start;\r
+        $response_body = substr($response_body, $start, $length);\r
+        $start = strpos($response_body, 'selected');\r
+        $start = $start - 3;\r
+        $length = 1;\r
+        $selected_privacy = substr($response_body, $start, $length);\r
+        $this->assertEquals('2', $selected_privacy);\r
+    }//end function testDefaultPrivacy\r
+\r
+\r
+\r
+}\r
+\r
+\r
+if (PHPUnit_MAIN_METHOD == 'BookmarkTest::main') {\r
+    BookmarkTest::main();\r
+}\r
+?>\r