diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Api/PostsAddTest.php | 219 | ||||
-rw-r--r-- | tests/BookmarkTest.php | 86 | ||||
-rwxr-xr-x | tests/data/BookmarkTest_deliciousbookmarks.xml | 6 | ||||
-rwxr-xr-x | 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 @@ <?xml version="1.0" encoding="UTF-8"?> <posts user="dpuser" update="2011-03-24T21:09:22Z" tag="" total="3"> - <post href="http://www.testdefaultprivacyposts_add6.com/" hash="4f8533885bb5740b98b6415140a0c8c6" description="Test bookmark 6 for default privacy." tag="tag1, tag2" time="2011-03-24T21:09:11Z" extended="" meta="5c80704730a1bf1b9eb615d4ba7a59bd" /> - <post href="http://www.testdefaultprivacyposts_add7.com/" hash="21eee08d7945ac23c4cc2b6d08d02212" description="Test bookmark 7 for default privacy." tag="tag2, tag3" time="2011-03-24T21:08:33Z" extended="" meta="7514ab84f61ba1dd0413572f7c12348d" /> - <post href="http://www.testdefaultprivacyposts_add8.com/" hash="cd64042205a083f1cf1e009344daef84" description="Test bookmark 8 for default privacy." tag="tag1, tag2, tag3" time="2011-03-24T21:07:44Z" extended="" meta="9cb24fddbc011e9634595d2f5e1a6537" /> + <post href="http://www.example.org/testdefaultprivacyposts_import1/" hash="4f8533885bb5740b98b6415140a0c8c6" description="Test bookmark 1 for default privacy." tag="tag1, tag2" time="2011-03-24T21:09:11Z" extended="" meta="5c80704730a1bf1b9eb615d4ba7a59bd" /> + <post href="http://www.example.org/testdefaultprivacyposts_import2/" hash="21eee08d7945ac23c4cc2b6d08d02212" description="Test bookmark 2 for default privacy." tag="tag2, tag3" time="2011-03-24T21:08:33Z" extended="" meta="7514ab84f61ba1dd0413572f7c12348d" /> + <post href="http://www.example.org/testdefaultprivacyposts_import3/" hash="cd64042205a083f1cf1e009344daef84" description="Test bookmark 3 for default privacy." tag="tag1, tag2, tag3" time="2011-03-24T21:07:44Z" extended="" meta="9cb24fddbc011e9634595d2f5e1a6537" /> </posts> <!-- fe09.api.del.ac4.yahoo.net uncompressed/chunked Thur Mar 24 21:09:33 UTC 2011 --> 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! --> -<TITLE>Bookmarks for dpuser</TITLE> +<TITLE>Bookmarks for testuser</TITLE> -<H1>Bookmarks for dpuser</H1> +<H1>Bookmarks for testuser</H1> <DL><p> - <DT><A HREF="http://www.testdefaultprivacyposts_add3.com" ADD_DATE="1301178264" LAST_VISIT="1301178075" LAST_MODIFIED="1301178075">Test bookmark 3 for default privacy.</A> - <DT><A HREF="http://www.testdefaultprivacyposts_add4.com" ADD_DATE="1301178264" LAST_VISIT="1301178075" LAST_MODIFIED="1301178075">Test bookmark 4 for default privacy.</A> - <DT><A HREF="http://www.testdefaultprivacyposts_add5.com" ADD_DATE="1301178264" LAST_VISIT="1301178075" LAST_MODIFIED="1301178075">Test bookmark 5 for default privacy.</A> + <DT><A HREF="http://www.example.org/testdefaultprivacyposts_importNetscape1" ADD_DATE="1301178264" LAST_VISIT="1301178075" LAST_MODIFIED="1301178075">Test bookmark 1 for default privacy.</A> + <DT><A HREF="http://www.example.org/testdefaultprivacyposts_importNetscape2" ADD_DATE="1301178264" LAST_VISIT="1301178075" LAST_MODIFIED="1301178075">Test bookmark 2 for default privacy.</A> + <DT><A HREF="http://www.example.org/testdefaultprivacyposts_importNetscape3" ADD_DATE="1301178264" LAST_VISIT="1301178075" LAST_MODIFIED="1301178075">Test bookmark 3 for default privacy.</A> <DT><A HREF="http://www.thisbookmarkwillnotbeadded.com" ADD_DATE="1301178264" LAST_VISIT="1301178075" LAST_MODIFIED="1301178075">This bookmark will be ignored by importNetscape.php.</A> </DL><p> |