From 3b582fd875de425d91bc143a33dc07e554246a80 Mon Sep 17 00:00:00 2001 From: bretticvs Date: Sun, 17 Apr 2011 17:42:49 -0600 Subject: Moved unit tests to PostsAddTest.php in Api directory. --- tests/Api/PostsAddTest.php | 219 ++++++++++++++++++++++++- tests/BookmarkTest.php | 86 ---------- tests/data/BookmarkTest_deliciousbookmarks.xml | 6 +- tests/data/BookmarkTest_netscapebookmarks.html | 10 +- 4 files changed, 220 insertions(+), 101 deletions(-) diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index f3bb31e..4e2f4fa 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -421,6 +421,11 @@ TXT; $this->assertEquals($title2, $data['bookmarks'][0]['bTitle']); } + + /** + * Test that a default privacy setting of 2 (Private) is used in adding + * a bookmark. + */ public function testDefaultPrivacyPrivate() { $this->setUnittestConfig( @@ -428,17 +433,21 @@ TXT; ); list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); $req->setMethod(HTTP_Request2::METHOD_POST); - $req->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com'); + $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_addprivate'); $req->addPostParameter('description', 'Test bookmark 1 for default privacy.'); $req->send(); - $this->us->setCurrentUserId($uId); $bms = $this->bs->getBookmarks(0, null, $uId); $this->assertEquals(1, count($bms['bookmarks'])); $bm = reset($bms['bookmarks']); $this->assertEquals('2', $bm['bStatus']); - } + }//end testDefaultPrivacyPrivate + + /** + * Test that a default privacy setting of 0 (Public) is used in adding + * a bookmark. + */ public function testDefaultPrivacyPublic() { $this->setUnittestConfig( @@ -446,19 +455,215 @@ TXT; ); list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); $req->setMethod(HTTP_Request2::METHOD_POST); - $req->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com'); + $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_addpublic'); $req->addPostParameter('description', 'Test bookmark 1 for default privacy.'); $req->send(); - $this->us->setCurrentUserId($uId); $bms = $this->bs->getBookmarks(0, null, $uId); $this->assertEquals(1, count($bms['bookmarks'])); $bm = reset($bms['bookmarks']); $this->assertEquals('0', $bm['bStatus']); - } + }//end testDefaultPrivacyPublic + + + /** + * Test that the default privacy setting is used when an existing + * bookmark is updated with edit.php. + */ + public function testDefaultPrivacyEdit() + { + $this->setUnittestConfig( + array('defaults' => array('privacy' => 2)) + ); + list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_edit'); + $req->addPostParameter('description', 'Test bookmark 2 for default privacy.'); + $req->addPostParameter('status', '0'); + $req->send(); + $bms = $this->bs->getBookmarks(0, null, $uId); + $bm = reset($bms['bookmarks']); + $bmId = $bm['bId']; + $oldUid = $uId; + $reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1'; + list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->setUrl($reqUrl); + $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login'; + $userinfo = $this->us->getUser($oldUid); + $testcookiepassword = $userinfo['password']; + $testusername = $userinfo['username']; + $testcookievalue = $oldUid . ':' . md5($testusername . $testcookiepassword); + $req->setCookieJar(true); + $req->addCookie($testcookiekey, $testcookievalue); + $req->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit'); + $req->addPostParameter('title', 'Test bookmark 2 for default privacy.'); + $req->addPostParameter('submitted', '1'); + $req->send(); + $bm = $this->bs->getBookmark($bmId); + $this->assertEquals('2', $bm['bStatus']); + }//end testDefaultPrivacyEdit + + + /** + * Test that the default privacy setting is used when bookmarks + * are imported from an HTML bookmarks file using importNetscape.php. + */ + public function testDefaultPrivacyImportNetscape() + { + $this->setUnittestConfig( + array('defaults' => array('privacy' => 1)) + ); + list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->setUrl($GLOBALS['unittestUrl'] . 'importNetscape.php' . '?unittestMode=1'); + $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login'; + $userinfo = $this->us->getUser($uId); + $testcookiepassword = $userinfo['password']; + $testusername = $userinfo['username']; + $testcookievalue = $uId . ':' . md5($testusername . $testcookiepassword); + $req->setCookieJar(true); + $req->addCookie($testcookiekey, $testcookievalue); + $req->addUpload('userfile', '../data/BookmarkTest_netscapebookmarks.html'); + $req->send(); + $this->us->setCurrentUserId($uId); + $bms = $this->bs->getBookmarks(0, null, $uId); + $this->assertEquals(3, count($bms['bookmarks'])); + $bm = reset($bms['bookmarks']); + $this->assertEquals('1', $bm['bStatus']); + }//end testDefaultPrivacyImportNetscape + + + /** + * Test that the default privacy setting is used when bookmarks + * are imported from an XML bookmarks file using import.php. + */ + public function testDefaultPrivacyImport() + { + $this->setUnittestConfig( + array('defaults' => array('privacy' => 2)) + ); + list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->setUrl($GLOBALS['unittestUrl'] . 'import.php' . '?unittestMode=1'); + $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login'; + $userinfo = $this->us->getUser($uId); + $testcookiepassword = $userinfo['password']; + $testusername = $userinfo['username']; + $testcookievalue = $uId . ':' . md5($testusername . $testcookiepassword); + $req->setCookieJar(true); + $req->addCookie($testcookiekey, $testcookievalue); + $req->addUpload('userfile', '../data/BookmarkTest_deliciousbookmarks.xml'); + $req->send(); + $this->us->setCurrentUserId($uId); + $bms = $this->bs->getBookmarks(0, null, $uId); + $this->assertEquals(3, count($bms['bookmarks'])); + $bm = reset($bms['bookmarks']); + $this->assertEquals('2', $bm['bStatus']); + }//end testDefaultPrivacyImport + + + /** + * Test that the default privacy setting is selected in the Privacy + * drop-down list when an existing bookmark is accessed with bookmarks.php + * and the get action. + */ + public function testDefaultPrivacyBookmarksGet() + { + $this->setUnittestConfig( + array('defaults' => array('privacy' => 2)) + ); + list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_bookmarksget'); + $req->addPostParameter('description', 'Test bookmark 1 for default privacy.'); + $req->addPostParameter('status', '0'); + $req->send(); + $bms = $this->bs->getBookmarks(0, null, $uId); + $this->assertEquals(1, count($bms['bookmarks'])); + $bm = reset($bms['bookmarks']); + $bmId = $bm['bId']; + $oldUid = $uId; + $user = $this->us->getUser($uId); + $userId = $user['username']; + $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $userId . '?action=get' . '&unittestMode=1'; + list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->setUrl($reqUrl); + $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login'; + $userinfo = $this->us->getUser($oldUid); + $testcookiepassword = $userinfo['password']; + $testusername = $userinfo['username']; + $testcookievalue = $oldUid . ':' . md5($testusername . $testcookiepassword); + $req->setCookieJar(true); + $req->addCookie($testcookiekey, $testcookievalue); + $req->addPostParameter('submitted', '1'); + $response = $req->send(); + $response_body = $response->getBody(); + $start = strpos($response_body, 'Privacy'); + $end = strpos($response_body, 'referrer'); + $length = $end - $start; + $response_body = substr($response_body, $start, $length); + $start = strpos($response_body, 'selected'); + $start = $start - 3; + $length = 1; + $selected_privacy = substr($response_body, $start, $length); + $this->assertEquals('2', $selected_privacy); + }//end testDefaultPrivacyBookmarksGet + + + /** + * Test that the default privacy setting is selected in the Privacy + * drop-down list when an existing bookmark is accessed with bookmarks.php + * and the add action. + */ + public function testDefaultPrivacyBookmarksAdd() + { + $this->setUnittestConfig( + array('defaults' => array('privacy' => 1)) + ); + list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_bookmarksadd'); + $req->addPostParameter('description', 'Test bookmark 2 for default privacy.'); + $req->addPostParameter('status', '0'); + $req->send(); + $bms = $this->bs->getBookmarks(0, null, $uId); + $this->assertEquals(1, count($bms['bookmarks'])); + $bm = reset($bms['bookmarks']); + $bmId = $bm['bId']; + $oldUid = $uId; + $user = $this->us->getUser($uId); + $userId = $user['username']; + $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $userId . '?action=add' . '&unittestMode=1'; + list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->setUrl($reqUrl); + $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login'; + $userinfo = $this->us->getUser($oldUid); + $testcookiepassword = $userinfo['password']; + $testusername = $userinfo['username']; + $testcookievalue = $oldUid . ':' . md5($testusername . $testcookiepassword); + $req->setCookieJar(true); + $req->addCookie($testcookiekey, $testcookievalue); + $req->addPostParameter('submitted', '1'); + $response = $req->send(); + $response_body = $response->getBody(); + $start = strpos($response_body, 'Privacy'); + $end = strpos($response_body, 'referrer'); + $length = $end - $start; + $response_body = substr($response_body, $start, $length); + $start = strpos($response_body, 'selected'); + $start = $start - 3; + $length = 1; + $selected_privacy = substr($response_body, $start, $length); + $this->assertEquals('1', $selected_privacy); + }//end testDefaultPrivacyBookmarksAdd + + } if (PHPUnit_MAIN_METHOD == 'Api_PostsAddTest::main') { Api_PostsAddTest::main(); } -?> \ No newline at end of file +?> diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index ad1cb48..f54fe9a 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -1343,92 +1343,6 @@ class BookmarkTest extends TestBase } - /** - * Test that the default privacy setting in - * $GLOBALS['defaults']['privacy'] is used - * as expected. - * - * @return void - */ - public function testDefaultPrivacy() - { - //For this test, the default privacy has been set to 2 (private) in the configuration file. - require_once 'HTTP/Request2.php'; - require_once dirname(__FILE__) . '/../data/config.php'; - $this->bs->deleteAll(); - $this->us->deleteAll(); - - $request = new HTTP_Request2('http://localhost/edit.php/2', HTTP_Request2::METHOD_POST); - $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login'; - $userinfo = $this->us->getUser('1'); - $testcookiepassword = $userinfo['password']; - $testcookievalue = '1:'.md5('dpuser'.$testcookiepassword); - $request->setCookieJar(true); - $request->addCookie($testcookiekey, $testcookievalue); - $request->addPostParameter('title', 'Test bookmark 2 for default privacy.'); - $request->addPostParameter('address', 'http://www.testdefaultprivacyposts_add2.com'); - $request->addPostParameter('submitted', '1'); - $request->send(); - $bm = $this->bs->getBookmark('2'); - $this->assertEquals('2', $bm['bStatus']); - - $request = new HTTP_Request2('http://localhost/importNetscape.php', HTTP_Request2::METHOD_POST); - $request->setCookieJar(true); - $request->addCookie($testcookiekey, $testcookievalue); - $request->addUpload('userfile', './data/BookmarkTest_netscapebookmarks.html'); - $request->send(); - $bm = $this->bs->getBookmark('3'); - $this->assertEquals('2', $bm['bStatus']); - $bm = $this->bs->getBookmark('4'); - $this->assertEquals('2', $bm['bStatus']); - $bm = $this->bs->getBookmark('5'); - $this->assertEquals('2', $bm['bStatus']); - - $request = new HTTP_Request2('http://localhost/import.php', HTTP_Request2::METHOD_POST); - $request->setCookieJar(true); - $request->addCookie($testcookiekey, $testcookievalue); - $request->addUpload('userfile', './data/BookmarkTest_deliciousbookmarks.xml'); - $request->send(); - $bm = $this->bs->getBookmark('6'); - $this->assertEquals('2', $bm['bStatus']); - $bm = $this->bs->getBookmark('7'); - $this->assertEquals('2', $bm['bStatus']); - $bm = $this->bs->getBookmark('8'); - $this->assertEquals('2', $bm['bStatus']); - - $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=get', HTTP_Request2::METHOD_POST); - $request->setCookieJar(true); - $request->addCookie($testcookiekey, $testcookievalue); - $request->addPostParameter('submitted', '1'); - $response = $request->send(); - $response_body = $response->getBody(); - $start = strpos($response_body, 'Privacy'); - $end = strpos($response_body, 'referrer'); - $length = $end - $start; - $response_body = substr($response_body, $start, $length); - $start = strpos($response_body, 'selected'); - $start = $start - 3; - $length = 1; - $selected_privacy = substr($response_body, $start, $length); - $this->assertEquals('2', $selected_privacy); - - $request = new HTTP_Request2('http://localhost/bookmarks.php/dpuser?action=add', HTTP_Request2::METHOD_POST); - $request->setCookieJar(true); - $request->addCookie($testcookiekey, $testcookievalue); - $response = $request->send(); - $response_body = $response->getBody(); - $start = strpos($response_body, 'Privacy'); - $end = strpos($response_body, 'referrer'); - $length = $end - $start; - $response_body = substr($response_body, $start, $length); - $start = strpos($response_body, 'selected'); - $start = $start - 3; - $length = 1; - $selected_privacy = substr($response_body, $start, $length); - $this->assertEquals('2', $selected_privacy); - }//end function testDefaultPrivacy - - } diff --git a/tests/data/BookmarkTest_deliciousbookmarks.xml b/tests/data/BookmarkTest_deliciousbookmarks.xml index d2bcfc5..87c67dc 100755 --- a/tests/data/BookmarkTest_deliciousbookmarks.xml +++ b/tests/data/BookmarkTest_deliciousbookmarks.xml @@ -1,7 +1,7 @@ - - - + + + diff --git a/tests/data/BookmarkTest_netscapebookmarks.html b/tests/data/BookmarkTest_netscapebookmarks.html index 07c7448..305662c 100755 --- a/tests/data/BookmarkTest_netscapebookmarks.html +++ b/tests/data/BookmarkTest_netscapebookmarks.html @@ -6,16 +6,16 @@ It will be read and overwritten. Do Not Edit! --> -Bookmarks for dpuser +Bookmarks for testuser -

Bookmarks for dpuser

+

Bookmarks for testuser

-

Test bookmark 3 for default privacy. -
Test bookmark 4 for default privacy. -
Test bookmark 5 for default privacy. +
Test bookmark 1 for default privacy. +
Test bookmark 2 for default privacy. +
Test bookmark 3 for default privacy.
This bookmark will be ignored by importNetscape.php.

-- cgit v1.2.3