From 675eadd584e264ba92091579bbc1166dcf3a5715 Mon Sep 17 00:00:00 2001 From: bretticvs Date: Thu, 31 Mar 2011 15:59:44 -0700 Subject: Updates for configurable-privacy2, hopefully without carriage returns. --- data/config.php.dist | 6 -- data/templates/bookmarks.tpl.php | 2 +- tests/BookmarkTest.php | 97 +++++++++++++++++++++++--- tests/data/BookmarkTest_deliciousbookmarks.xml | 2 +- tests/data/BookmarkTest_netscapebookmarks.html | 2 +- 5 files changed, 89 insertions(+), 20 deletions(-) diff --git a/data/config.php.dist b/data/config.php.dist index 0f849e2..302d55f 100644 --- a/data/config.php.dist +++ b/data/config.php.dist @@ -7,12 +7,6 @@ * See config.default.inc.php for more options. */ -/** - * Array for defaults. - * - * @var array - */ -$defaults = array(); /** * The name of this site. diff --git a/data/templates/bookmarks.tpl.php b/data/templates/bookmarks.tpl.php index 44dfe90..e32d3c9 100644 --- a/data/templates/bookmarks.tpl.php +++ b/data/templates/bookmarks.tpl.php @@ -256,7 +256,7 @@ if ($currenttag!= '') { foreach ($bookmarks as $key => &$row) { switch ($row['bStatus']) { case 0: - $access = ' public'; + $access = ''; break; case 1: $access = ' shared'; diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index aa0b8c3..e6f2b26 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -1352,18 +1352,93 @@ class BookmarkTest extends TestBase */ public function testDefaultPrivacy() { - $GLOBALS['defaults']['privacy'] = 1; - $uid = $this->addUser(); - $this->us->setCurrentUserId($uid); - $bid = $this->bs->addBookmark('http://www.somedomain.com', 'mybookmark1', 'descr1', 'privatenote1', $GLOBALS['defaults']['privacy'], array()); - $bm = $this->bs->getBookmark($bid); - $this->assertEquals('1', $bm['bStatus']); - $GLOBALS['defaults']['privacy'] = 2; - $uid = $this->addUser(); - $this->us->setCurrentUserId($uid); - $bid = $this->bs->addBookmark('http://www.anotherdomain.com', 'mybookmark2', 'descr2', 'privatenote2', $GLOBALS['defaults']['privacy'], array()); - $bm = $this->bs->getBookmark($bid); + //For this test, the default privacy has been set to 2 (private) in the configuration file. + require_once 'HTTP/Request2.php'; + require_once dirname(__FILE__) . '/../data/config.php'; + $this->bs->deleteAll(); + $this->us->deleteAll(); + $request = new HTTP_Request2('http://localhost/api/posts_add.php', HTTP_Request2::METHOD_POST); + $dpuid = $this->addUser('dpuser', 'dpuserpassword'); + $request->setAuth('dpuser', 'dpuserpassword'); + $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com'); + $request->addPostParameter('description', 'Test bookmark 1 for default privacy.'); + $request->send(); + $bm = $this->bs->getBookmark('1'); + $this->assertEquals('2', $bm['bStatus']); + + $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add2.com'); + $request->addPostParameter('description', 'Test bookmark 2 for default privacy.'); + $request->addPostParameter('status', '0'); + $request->send(); + + $request = new HTTP_Request2('http://localhost/edit.php/2', HTTP_Request2::METHOD_POST); + $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login'; + $userinfo = $this->us->getUser('1'); + $testcookiepassword = $userinfo['password']; + $testcookievalue = '1:'.md5('dpuser'.$testcookiepassword); + $request->setCookieJar(true); + $request->addCookie($testcookiekey, $testcookievalue); + $request->addPostParameter('title', 'Test bookmark 2 for default privacy.'); + $request->addPostParameter('address', 'http://www.testdefaultprivacyposts_add2.com'); + $request->addPostParameter('submitted', '1'); + $request->send(); + $bm = $this->bs->getBookmark('2'); $this->assertEquals('2', $bm['bStatus']); + + $request = new HTTP_Request2('http://localhost/importNetscape.php', HTTP_Request2::METHOD_POST); + $request->setCookieJar(true); + $request->addCookie($testcookiekey, $testcookievalue); + $request->addUpload('userfile', './data/BookmarkTest_netscapebookmarks.html'); + $request->send(); + $bm = $this->bs->getBookmark('3'); + $this->assertEquals('2', $bm['bStatus']); + $bm = $this->bs->getBookmark('4'); + $this->assertEquals('2', $bm['bStatus']); + $bm = $this->bs->getBookmark('5'); + $this->assertEquals('2', $bm['bStatus']); + + $request = new HTTP_Request2('http://localhost/import.php', HTTP_Request2::METHOD_POST); + $request->setCookieJar(true); + $request->addCookie($testcookiekey, $testcookievalue); + $request->addUpload('userfile', './data/BookmarkTest_deliciousbookmarks.xml'); + $request->send(); + $bm = $this->bs->getBookmark('6'); + $this->assertEquals('2', $bm['bStatus']); + $bm = $this->bs->getBookmark('7'); + $this->assertEquals('2', $bm['bStatus']); + $bm = $this->bs->getBookmark('8'); + $this->assertEquals('2', $bm['bStatus']); + + $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=get', HTTP_Request2::METHOD_POST); + $request->setCookieJar(true); + $request->addCookie($testcookiekey, $testcookievalue); + $request->addPostParameter('submitted', '1'); + $response = $request->send(); + $response_body = $response->getBody(); + $start = strpos($response_body, 'Privacy'); + $end = strpos($response_body, 'referrer'); + $length = $end - $start; + $response_body = substr($response_body, $start, $length); + $start = strpos($response_body, 'selected'); + $start = $start - 3; + $length = 1; + $selected_privacy = substr($response_body, $start, $length); + $this->assertEquals('2', $selected_privacy); + + $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=add', HTTP_Request2::METHOD_POST); + $request->setCookieJar(true); + $request->addCookie($testcookiekey, $testcookievalue); + $response = $request->send(); + $response_body = $response->getBody(); + $start = strpos($response_body, 'Privacy'); + $end = strpos($response_body, 'referrer'); + $length = $end - $start; + $response_body = substr($response_body, $start, $length); + $start = strpos($response_body, 'selected'); + $start = $start - 3; + $length = 1; + $selected_privacy = substr($response_body, $start, $length); + $this->assertEquals('2', $selected_privacy); }//end function testDefaultPrivacy diff --git a/tests/data/BookmarkTest_deliciousbookmarks.xml b/tests/data/BookmarkTest_deliciousbookmarks.xml index 1c12110..1c3fd8d 100755 --- a/tests/data/BookmarkTest_deliciousbookmarks.xml +++ b/tests/data/BookmarkTest_deliciousbookmarks.xml @@ -1,5 +1,5 @@ - + diff --git a/tests/data/BookmarkTest_netscapebookmarks.html b/tests/data/BookmarkTest_netscapebookmarks.html index 3e1bd7d..c91d20a 100755 --- a/tests/data/BookmarkTest_netscapebookmarks.html +++ b/tests/data/BookmarkTest_netscapebookmarks.html @@ -1,7 +1,7 @@ -- cgit v1.2.3