From 988e564ec3af4191cc9a7a8a04ae1cb582271518 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 6 Apr 2011 07:46:55 +0200 Subject: always delete all bookmarks in setUp since almost all methods do it anyway --- tests/Api/PostsAddTest.php | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'tests/Api/PostsAddTest.php') diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index 1f21d04..226a7c9 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -51,6 +51,13 @@ class Api_PostsAddTest extends TestBaseApi } + public function setUp() + { + parent::setUp(); + $this->bs->deleteAll(); + } + + /** * Test if authentication is required when sending no auth data @@ -82,8 +89,6 @@ class Api_PostsAddTest extends TestBaseApi */ public function testAddBookmarkPost() { - $this->bs->deleteAll(); - $bmUrl = 'http://example.org/tag-1'; $bmTags = array('foo', 'bar', 'baz'); $bmDatetime = '2010-09-08T03:02:01Z'; @@ -144,8 +149,6 @@ TXT; */ public function testAddBookmarkGet() { - $this->bs->deleteAll(); - $bmUrl = 'http://example.org/tag-1'; $bmTags = array('foo', 'bar', 'baz'); $bmDatetime = '2010-09-08T03:02:01Z'; @@ -205,8 +208,6 @@ TXT; */ public function testUrlDescEnough() { - $this->bs->deleteAll(); - list($req, $uId) = $this->getAuthRequest(); $req->setMethod(HTTP_Request2::METHOD_POST); $req->addPostParameter('url', 'http://example.org/tag2'); @@ -241,8 +242,6 @@ TXT; */ public function testUrlRequired() { - $this->bs->deleteAll(); - list($req, $uId) = $this->getAuthRequest(); $req->setMethod(HTTP_Request2::METHOD_POST); //$req->addPostParameter('url', 'http://example.org/tag2'); @@ -277,8 +276,6 @@ TXT; */ public function testDescriptionRequired() { - $this->bs->deleteAll(); - list($req, $uId) = $this->getAuthRequest(); $req->setMethod(HTTP_Request2::METHOD_POST); $req->addPostParameter('url', 'http://example.org/tag2'); @@ -313,8 +310,6 @@ TXT; */ public function testReplaceNo() { - $this->bs->deleteAll(); - $url = 'http://example.org/tag2'; $title1 = 'foo bar 1'; $title2 = 'bar 2 foo'; @@ -381,8 +376,6 @@ TXT; */ public function testReplaceYes() { - $this->bs->deleteAll(); - $url = 'http://example.org/tag2'; $title1 = 'foo bar 1'; $title2 = 'bar 2 foo'; -- cgit v1.2.3 From 200cb1d3c54dfaae54d26c0d51f6086435bcee8e Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 6 Apr 2011 09:52:02 +0200 Subject: move privacy tests for api/post_add to the correct location --- tests/Api/PostsAddTest.php | 36 ++++++++++++++++++++++++++++++++++++ tests/BookmarkTest.php | 13 ------------- 2 files changed, 36 insertions(+), 13 deletions(-) (limited to 'tests/Api/PostsAddTest.php') diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index 226a7c9..f3bb31e 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -420,6 +420,42 @@ TXT; $this->assertEquals(1, $data['total']); $this->assertEquals($title2, $data['bookmarks'][0]['bTitle']); } + + public function testDefaultPrivacyPrivate() + { + $this->setUnittestConfig( + array('defaults' => array('privacy' => 2)) + ); + list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com'); + $req->addPostParameter('description', 'Test bookmark 1 for default privacy.'); + $req->send(); + + $this->us->setCurrentUserId($uId); + $bms = $this->bs->getBookmarks(0, null, $uId); + $this->assertEquals(1, count($bms['bookmarks'])); + $bm = reset($bms['bookmarks']); + $this->assertEquals('2', $bm['bStatus']); + } + + public function testDefaultPrivacyPublic() + { + $this->setUnittestConfig( + array('defaults' => array('privacy' => 0)) + ); + list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com'); + $req->addPostParameter('description', 'Test bookmark 1 for default privacy.'); + $req->send(); + + $this->us->setCurrentUserId($uId); + $bms = $this->bs->getBookmarks(0, null, $uId); + $this->assertEquals(1, count($bms['bookmarks'])); + $bm = reset($bms['bookmarks']); + $this->assertEquals('0', $bm['bStatus']); + } } if (PHPUnit_MAIN_METHOD == 'Api_PostsAddTest::main') { diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php index e6f2b26..ad1cb48 100644 --- a/tests/BookmarkTest.php +++ b/tests/BookmarkTest.php @@ -1357,19 +1357,6 @@ class BookmarkTest extends TestBase require_once dirname(__FILE__) . '/../data/config.php'; $this->bs->deleteAll(); $this->us->deleteAll(); - $request = new HTTP_Request2('http://localhost/api/posts_add.php', HTTP_Request2::METHOD_POST); - $dpuid = $this->addUser('dpuser', 'dpuserpassword'); - $request->setAuth('dpuser', 'dpuserpassword'); - $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add1.com'); - $request->addPostParameter('description', 'Test bookmark 1 for default privacy.'); - $request->send(); - $bm = $this->bs->getBookmark('1'); - $this->assertEquals('2', $bm['bStatus']); - - $request->addPostParameter('url', 'http://www.testdefaultprivacyposts_add2.com'); - $request->addPostParameter('description', 'Test bookmark 2 for default privacy.'); - $request->addPostParameter('status', '0'); - $request->send(); $request = new HTTP_Request2('http://localhost/edit.php/2', HTTP_Request2::METHOD_POST); $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login'; -- cgit v1.2.3 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(-) (limited to 'tests/Api/PostsAddTest.php') 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 From b937d6ee42f3d5c0bab83f7cdefd7319837eb2fa Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 18 Apr 2011 07:50:20 +0200 Subject: fix tests that did not find the data file --- tests/Api/PostsAddTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/Api/PostsAddTest.php') diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index 4e2f4fa..1753529 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -524,7 +524,7 @@ TXT; $testcookievalue = $uId . ':' . md5($testusername . $testcookiepassword); $req->setCookieJar(true); $req->addCookie($testcookiekey, $testcookievalue); - $req->addUpload('userfile', '../data/BookmarkTest_netscapebookmarks.html'); + $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_netscapebookmarks.html'); $req->send(); $this->us->setCurrentUserId($uId); $bms = $this->bs->getBookmarks(0, null, $uId); @@ -553,7 +553,7 @@ TXT; $testcookievalue = $uId . ':' . md5($testusername . $testcookiepassword); $req->setCookieJar(true); $req->addCookie($testcookiekey, $testcookievalue); - $req->addUpload('userfile', '../data/BookmarkTest_deliciousbookmarks.xml'); + $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_deliciousbookmarks.xml'); $req->send(); $this->us->setCurrentUserId($uId); $bms = $this->bs->getBookmarks(0, null, $uId); -- cgit v1.2.3 From 87eab925e45dd72e18c097329d5b751fd48ceabb Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 18 Apr 2011 19:16:58 +0200 Subject: make edit test much easier and do not rely on manual cookie setting --- tests/Api/PostsAddTest.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'tests/Api/PostsAddTest.php') diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index 1753529..3f21add 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -475,31 +475,31 @@ TXT; $this->setUnittestConfig( array('defaults' => array('privacy' => 2)) ); - list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + + list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1'); + $cookies = $req->getCookieJar(); $req->setMethod(HTTP_Request2::METHOD_POST); $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_edit'); $req->addPostParameter('description', 'Test bookmark 2 for default privacy.'); $req->addPostParameter('status', '0'); - $req->send(); + $res = $req->send(); + $this->assertEquals( + 200, $res->getStatus(), + 'Adding bookmark failed: ' . $res->getBody()); $bms = $this->bs->getBookmarks(0, null, $uId); - $bm = reset($bms['bookmarks']); + $bm = reset($bms['bookmarks']); $bmId = $bm['bId']; - $oldUid = $uId; + $reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1'; - list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); - $req->setMethod(HTTP_Request2::METHOD_POST); - $req->setUrl($reqUrl); - $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login'; - $userinfo = $this->us->getUser($oldUid); - $testcookiepassword = $userinfo['password']; - $testusername = $userinfo['username']; - $testcookievalue = $oldUid . ':' . md5($testusername . $testcookiepassword); - $req->setCookieJar(true); - $req->addCookie($testcookiekey, $testcookievalue); - $req->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit'); - $req->addPostParameter('title', 'Test bookmark 2 for default privacy.'); - $req->addPostParameter('submitted', '1'); - $req->send(); + $req2 = new HTTP_Request2($reqUrl, HTTP_Request2::METHOD_POST); + $req2->setCookieJar($cookies); + $req2->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit'); + $req2->addPostParameter('title', 'Test bookmark 2 for default privacy.'); + $req2->addPostParameter('submitted', '1'); + $res = $req2->send(); + + $this->assertEquals(302, $res->getStatus(), 'Editing bookmark failed'); + $bm = $this->bs->getBookmark($bmId); $this->assertEquals('2', $bm['bStatus']); }//end testDefaultPrivacyEdit -- cgit v1.2.3 From 6f04c888bf400d91437ce33b2718dc8529773337 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 18 Apr 2011 22:37:42 +0200 Subject: make importnetscape-test easier --- tests/Api/PostsAddTest.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'tests/Api/PostsAddTest.php') diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index 3f21add..4b0bb0a 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -514,18 +514,13 @@ TXT; $this->setUnittestConfig( array('defaults' => array('privacy' => 1)) ); - list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1'); $req->setMethod(HTTP_Request2::METHOD_POST); $req->setUrl($GLOBALS['unittestUrl'] . 'importNetscape.php' . '?unittestMode=1'); - $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login'; - $userinfo = $this->us->getUser($uId); - $testcookiepassword = $userinfo['password']; - $testusername = $userinfo['username']; - $testcookievalue = $uId . ':' . md5($testusername . $testcookiepassword); - $req->setCookieJar(true); - $req->addCookie($testcookiekey, $testcookievalue); $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_netscapebookmarks.html'); - $req->send(); + $res = $req->send(); + $this->assertEquals(200, $res->getStatus(), 'Bookmark import failed'); + $this->us->setCurrentUserId($uId); $bms = $this->bs->getBookmarks(0, null, $uId); $this->assertEquals(3, count($bms['bookmarks'])); -- cgit v1.2.3 From 79e3f4e121146254a8e17c3bd271679c815eca8c Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 18 Apr 2011 22:39:06 +0200 Subject: make import test easier --- tests/Api/PostsAddTest.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'tests/Api/PostsAddTest.php') diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index 4b0bb0a..1bd6174 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -514,7 +514,7 @@ TXT; $this->setUnittestConfig( array('defaults' => array('privacy' => 1)) ); - list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1'); + list($req, $uId) = $this->getLoggedInRequest(); $req->setMethod(HTTP_Request2::METHOD_POST); $req->setUrl($GLOBALS['unittestUrl'] . 'importNetscape.php' . '?unittestMode=1'); $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_netscapebookmarks.html'); @@ -538,18 +538,13 @@ TXT; $this->setUnittestConfig( array('defaults' => array('privacy' => 2)) ); - list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + list($req, $uId) = $this->getLoggedInRequest(); $req->setMethod(HTTP_Request2::METHOD_POST); $req->setUrl($GLOBALS['unittestUrl'] . 'import.php' . '?unittestMode=1'); - $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login'; - $userinfo = $this->us->getUser($uId); - $testcookiepassword = $userinfo['password']; - $testusername = $userinfo['username']; - $testcookievalue = $uId . ':' . md5($testusername . $testcookiepassword); - $req->setCookieJar(true); - $req->addCookie($testcookiekey, $testcookievalue); $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_deliciousbookmarks.xml'); - $req->send(); + $res = $req->send(); + $this->assertEquals(302, $res->getStatus(), 'Bookmark import failed'); + $this->us->setCurrentUserId($uId); $bms = $this->bs->getBookmarks(0, null, $uId); $this->assertEquals(3, count($bms['bookmarks'])); -- cgit v1.2.3 From 43b6021be794ff20af9b423ecfacf382916c80b1 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 26 Apr 2011 06:59:23 +0200 Subject: use xpath instead of manual string-search to verify test results --- tests/Api/PostsAddTest.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'tests/Api/PostsAddTest.php') diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index 1bd6174..bc8f13e 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -563,12 +563,13 @@ TXT; $this->setUnittestConfig( array('defaults' => array('privacy' => 2)) ); - list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + list($req, $uId) = $this->getLoggedInRequest(); $req->setMethod(HTTP_Request2::METHOD_POST); $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_bookmarksget'); $req->addPostParameter('description', 'Test bookmark 1 for default privacy.'); $req->addPostParameter('status', '0'); $req->send(); + $bms = $this->bs->getBookmarks(0, null, $uId); $this->assertEquals(1, count($bms['bookmarks'])); $bm = reset($bms['bookmarks']); @@ -577,6 +578,7 @@ TXT; $user = $this->us->getUser($uId); $userId = $user['username']; $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $userId . '?action=get' . '&unittestMode=1'; + list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); $req->setMethod(HTTP_Request2::METHOD_POST); $req->setUrl($reqUrl); @@ -590,15 +592,14 @@ TXT; $req->addPostParameter('submitted', '1'); $response = $req->send(); $response_body = $response->getBody(); - $start = strpos($response_body, 'Privacy'); - $end = strpos($response_body, 'referrer'); - $length = $end - $start; - $response_body = substr($response_body, $start, $length); - $start = strpos($response_body, 'selected'); - $start = $start - 3; - $length = 1; - $selected_privacy = substr($response_body, $start, $length); - $this->assertEquals('2', $selected_privacy); + + $x = simplexml_load_string($response_body); + $ns = $x->getDocNamespaces(); + $x->registerXPathNamespace('ns', reset($ns)); + + $elements = $x->xpath('//ns:select[@name="status"]/ns:option[@selected="selected"]'); + $this->assertEquals(1, count($elements), 'No selected status option found'); + $this->assertEquals(2, (string)$elements[0]['value']); }//end testDefaultPrivacyBookmarksGet -- cgit v1.2.3 From 3e5cadc7648658e2c92fbb580d622997f5dc874e Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 26 Apr 2011 07:00:33 +0200 Subject: use cookie jar instead of manually creating the cookie --- tests/Api/PostsAddTest.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'tests/Api/PostsAddTest.php') diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index bc8f13e..b915b4c 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -564,6 +564,7 @@ TXT; array('defaults' => array('privacy' => 2)) ); list($req, $uId) = $this->getLoggedInRequest(); + $cookies = $req->getCookieJar(); $req->setMethod(HTTP_Request2::METHOD_POST); $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_bookmarksget'); $req->addPostParameter('description', 'Test bookmark 1 for default privacy.'); @@ -582,13 +583,7 @@ TXT; list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); $req->setMethod(HTTP_Request2::METHOD_POST); $req->setUrl($reqUrl); - $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login'; - $userinfo = $this->us->getUser($oldUid); - $testcookiepassword = $userinfo['password']; - $testusername = $userinfo['username']; - $testcookievalue = $oldUid . ':' . md5($testusername . $testcookiepassword); - $req->setCookieJar(true); - $req->addCookie($testcookiekey, $testcookievalue); + $req->setCookieJar($cookies); $req->addPostParameter('submitted', '1'); $response = $req->send(); $response_body = $response->getBody(); -- cgit v1.2.3 From 6b02db7920f09cafadc181bbaed283d5adf6cee6 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 26 Apr 2011 07:01:48 +0200 Subject: use cookie jar instead of manually creating the cookie --- tests/Api/PostsAddTest.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'tests/Api/PostsAddTest.php') diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index b915b4c..ddaa1fd 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -573,12 +573,8 @@ TXT; $bms = $this->bs->getBookmarks(0, null, $uId); $this->assertEquals(1, count($bms['bookmarks'])); - $bm = reset($bms['bookmarks']); - $bmId = $bm['bId']; - $oldUid = $uId; $user = $this->us->getUser($uId); - $userId = $user['username']; - $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $userId . '?action=get' . '&unittestMode=1'; + $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $user['username'] . '?action=get' . '&unittestMode=1'; list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); $req->setMethod(HTTP_Request2::METHOD_POST); -- cgit v1.2.3 From f629d081ddf52e3cb83ffbfc973a97adc691790c Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 2 May 2011 09:03:35 +0200 Subject: make privacy tests clearer --- tests/Api/PostsAddTest.php | 75 +++++++++++++++++----------------------------- tests/TestBaseApi.php | 3 ++ 2 files changed, 31 insertions(+), 47 deletions(-) (limited to 'tests/Api/PostsAddTest.php') diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index ddaa1fd..3c1177f 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -423,8 +423,8 @@ TXT; /** - * Test that a default privacy setting of 2 (Private) is used in adding - * a bookmark. + * Test that a default privacy setting of 2 (Private) is used in adding + * a bookmark. */ public function testDefaultPrivacyPrivate() { @@ -445,8 +445,8 @@ TXT; /** - * Test that a default privacy setting of 0 (Public) is used in adding - * a bookmark. + * Test that a default privacy setting of 0 (Public) is used in adding + * a bookmark. */ public function testDefaultPrivacyPublic() { @@ -490,7 +490,7 @@ TXT; $bm = reset($bms['bookmarks']); $bmId = $bm['bId']; - $reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1'; + $reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1'; $req2 = new HTTP_Request2($reqUrl, HTTP_Request2::METHOD_POST); $req2->setCookieJar($cookies); $req2->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit'); @@ -502,7 +502,7 @@ TXT; $bm = $this->bs->getBookmark($bmId); $this->assertEquals('2', $bm['bStatus']); - }//end testDefaultPrivacyEdit + }//end testDefaultPrivacyEdit /** @@ -550,15 +550,15 @@ TXT; $this->assertEquals(3, count($bms['bookmarks'])); $bm = reset($bms['bookmarks']); $this->assertEquals('2', $bm['bStatus']); - }//end testDefaultPrivacyImport + }//end testDefaultPrivacyImport /** - * Test that the default privacy setting is selected in the Privacy - * drop-down list when an existing bookmark is accessed with bookmarks.php - * and the get action. + * Test that the default privacy setting is selected in the Privacy + * drop-down list when adding a new bookmark, sending the form and + * missing the title and the privacy setting. */ - public function testDefaultPrivacyBookmarksGet() + public function testDefaultPrivacyBookmarksAddMissingTitleMissingPrivacy() { $this->setUnittestConfig( array('defaults' => array('privacy' => 2)) @@ -574,7 +574,7 @@ TXT; $bms = $this->bs->getBookmarks(0, null, $uId); $this->assertEquals(1, count($bms['bookmarks'])); $user = $this->us->getUser($uId); - $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $user['username'] . '?action=get' . '&unittestMode=1'; + $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $user['username'] . '?action=get' . '&unittestMode=1'; list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); $req->setMethod(HTTP_Request2::METHOD_POST); @@ -595,51 +595,32 @@ TXT; /** - * Test that the default privacy setting is selected in the Privacy - * drop-down list when an existing bookmark is accessed with bookmarks.php - * and the add action. + * Test that the default privacy setting is selected in the Privacy + * drop-down list when a new bookmark is being created. */ public function testDefaultPrivacyBookmarksAdd() { $this->setUnittestConfig( array('defaults' => array('privacy' => 1)) ); - list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); - $req->setMethod(HTTP_Request2::METHOD_POST); - $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_bookmarksadd'); - $req->addPostParameter('description', 'Test bookmark 2 for default privacy.'); - $req->addPostParameter('status', '0'); - $req->send(); - $bms = $this->bs->getBookmarks(0, null, $uId); - $this->assertEquals(1, count($bms['bookmarks'])); - $bm = reset($bms['bookmarks']); - $bmId = $bm['bId']; - $oldUid = $uId; + list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1'); + $user = $this->us->getUser($uId); - $userId = $user['username']; - $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $userId . '?action=add' . '&unittestMode=1'; - list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); - $req->setMethod(HTTP_Request2::METHOD_POST); + $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' + . $user['username'] . '?action=add' . '&unittestMode=1'; $req->setUrl($reqUrl); - $testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login'; - $userinfo = $this->us->getUser($oldUid); - $testcookiepassword = $userinfo['password']; - $testusername = $userinfo['username']; - $testcookievalue = $oldUid . ':' . md5($testusername . $testcookiepassword); - $req->setCookieJar(true); - $req->addCookie($testcookiekey, $testcookievalue); - $req->addPostParameter('submitted', '1'); + $req->setMethod(HTTP_Request2::METHOD_GET); $response = $req->send(); $response_body = $response->getBody(); - $start = strpos($response_body, 'Privacy'); - $end = strpos($response_body, 'referrer'); - $length = $end - $start; - $response_body = substr($response_body, $start, $length); - $start = strpos($response_body, 'selected'); - $start = $start - 3; - $length = 1; - $selected_privacy = substr($response_body, $start, $length); - $this->assertEquals('1', $selected_privacy); + $this->assertNotEquals('', $response_body, 'Response is empty'); + + $x = simplexml_load_string($response_body); + $ns = $x->getDocNamespaces(); + $x->registerXPathNamespace('ns', reset($ns)); + + $elements = $x->xpath('//ns:select[@name="status"]/ns:option[@selected="selected"]'); + $this->assertEquals(1, count($elements), 'No selected status option found'); + $this->assertEquals(1, (string)$elements[0]['value']); }//end testDefaultPrivacyBookmarksAdd diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index b381dad..9759db5 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -89,6 +89,8 @@ class TestBaseApi extends TestBase * the request object with authentication details, so that * the user is logged in. * + * Only usable for API requests, not "normal" HTTP page requests + * * @param string $urlSuffix Suffix for the URL * @param mixed $auth If user authentication is needed (true/false) * or array with username and password @@ -96,6 +98,7 @@ class TestBaseApi extends TestBase * @return array(HTTP_Request2, integer) HTTP request object and user id * * @uses getRequest() + * @see getLoggedInRequest() */ protected function getAuthRequest($urlSuffix = null, $auth = true) { -- cgit v1.2.3 From fc093a5fe51d35a2991e549e8836cac15dc2888b Mon Sep 17 00:00:00 2001 From: bretticvs Date: Thu, 5 May 2011 16:24:21 -0600 Subject: Moved testDefaultPrivacyEdit() to tests/www/editTest.php. Moved testDefaultPrivacyImportNetscape() to tests/www/importNetscapeTest.php. Moved testDefaultPrivacyImport() to tests/www/importTest.php. Moved testDefaultPrivacyBookmarksAddMissingTitleMissingPrivacy() to tests/www/bookmarksTest.php. Moved testDefaultPrivacyBookmarksAdd() to tests/www/bookmarksTest.php. Kept testDefaultPrivacyPrivate() in tests/api/PostsAddTest.php. Kept testDefaultPrivacyPublic() in tests/api/PostsAddTest.php. --- tests/Api/PostsAddTest.php | 158 --------------------------------------- tests/www/bookmarksTest.php | 80 ++++++++++++++++++++ tests/www/editTest.php | 48 ++++++++++++ tests/www/importNetscapeTest.php | 33 ++++++++ tests/www/importTest.php | 33 ++++++++ 5 files changed, 194 insertions(+), 158 deletions(-) create mode 100755 tests/www/bookmarksTest.php create mode 100755 tests/www/editTest.php create mode 100755 tests/www/importNetscapeTest.php create mode 100755 tests/www/importTest.php (limited to 'tests/Api/PostsAddTest.php') diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php index 24cc600..02e2b38 100644 --- a/tests/Api/PostsAddTest.php +++ b/tests/Api/PostsAddTest.php @@ -452,163 +452,5 @@ TXT; }//end testDefaultPrivacyPublic - /** - * Test that the default privacy setting is used when an existing - * bookmark is updated with edit.php. - */ - public function testDefaultPrivacyEdit() - { - $this->setUnittestConfig( - array('defaults' => array('privacy' => 2)) - ); - - list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1'); - $cookies = $req->getCookieJar(); - $req->setMethod(HTTP_Request2::METHOD_POST); - $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_edit'); - $req->addPostParameter('description', 'Test bookmark 2 for default privacy.'); - $req->addPostParameter('status', '0'); - $res = $req->send(); - $this->assertEquals( - 200, $res->getStatus(), - 'Adding bookmark failed: ' . $res->getBody()); - $bms = $this->bs->getBookmarks(0, null, $uId); - $bm = reset($bms['bookmarks']); - $bmId = $bm['bId']; - - $reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1'; - $req2 = new HTTP_Request2($reqUrl, HTTP_Request2::METHOD_POST); - $req2->setCookieJar($cookies); - $req2->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit'); - $req2->addPostParameter('title', 'Test bookmark 2 for default privacy.'); - $req2->addPostParameter('submitted', '1'); - $res = $req2->send(); - - $this->assertEquals(302, $res->getStatus(), 'Editing bookmark failed'); - - $bm = $this->bs->getBookmark($bmId); - $this->assertEquals('2', $bm['bStatus']); - }//end testDefaultPrivacyEdit - - - /** - * Test that the default privacy setting is used when bookmarks - * are imported from an HTML bookmarks file using importNetscape.php. - */ - public function testDefaultPrivacyImportNetscape() - { - $this->setUnittestConfig( - array('defaults' => array('privacy' => 1)) - ); - list($req, $uId) = $this->getLoggedInRequest(); - $req->setMethod(HTTP_Request2::METHOD_POST); - $req->setUrl($GLOBALS['unittestUrl'] . 'importNetscape.php' . '?unittestMode=1'); - $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_netscapebookmarks.html'); - $res = $req->send(); - $this->assertEquals(200, $res->getStatus(), 'Bookmark import failed'); - - $this->us->setCurrentUserId($uId); - $bms = $this->bs->getBookmarks(0, null, $uId); - $this->assertEquals(3, count($bms['bookmarks'])); - $bm = reset($bms['bookmarks']); - $this->assertEquals('1', $bm['bStatus']); - }//end testDefaultPrivacyImportNetscape - - - /** - * Test that the default privacy setting is used when bookmarks - * are imported from an XML bookmarks file using import.php. - */ - public function testDefaultPrivacyImport() - { - $this->setUnittestConfig( - array('defaults' => array('privacy' => 2)) - ); - list($req, $uId) = $this->getLoggedInRequest(); - $req->setMethod(HTTP_Request2::METHOD_POST); - $req->setUrl($GLOBALS['unittestUrl'] . 'import.php' . '?unittestMode=1'); - $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_deliciousbookmarks.xml'); - $res = $req->send(); - $this->assertEquals(302, $res->getStatus(), 'Bookmark import failed'); - - $this->us->setCurrentUserId($uId); - $bms = $this->bs->getBookmarks(0, null, $uId); - $this->assertEquals(3, count($bms['bookmarks'])); - $bm = reset($bms['bookmarks']); - $this->assertEquals('2', $bm['bStatus']); - }//end testDefaultPrivacyImport - - - /** - * Test that the default privacy setting is selected in the Privacy - * drop-down list when adding a new bookmark, sending the form and - * missing the title and the privacy setting. - */ - public function testDefaultPrivacyBookmarksAddMissingTitleMissingPrivacy() - { - $this->setUnittestConfig( - array('defaults' => array('privacy' => 2)) - ); - list($req, $uId) = $this->getLoggedInRequest(); - $cookies = $req->getCookieJar(); - $req->setMethod(HTTP_Request2::METHOD_POST); - $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_bookmarksget'); - $req->addPostParameter('description', 'Test bookmark 1 for default privacy.'); - $req->addPostParameter('status', '0'); - $req->send(); - - $bms = $this->bs->getBookmarks(0, null, $uId); - $this->assertEquals(1, count($bms['bookmarks'])); - $user = $this->us->getUser($uId); - $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $user['username'] . '?action=get' . '&unittestMode=1'; - - list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); - $req->setMethod(HTTP_Request2::METHOD_POST); - $req->setUrl($reqUrl); - $req->setCookieJar($cookies); - $req->addPostParameter('submitted', '1'); - $response = $req->send(); - $response_body = $response->getBody(); - - $x = simplexml_load_string($response_body); - $ns = $x->getDocNamespaces(); - $x->registerXPathNamespace('ns', reset($ns)); - - $elements = $x->xpath('//ns:select[@name="status"]/ns:option[@selected="selected"]'); - $this->assertEquals(1, count($elements), 'No selected status option found'); - $this->assertEquals(2, (string)$elements[0]['value']); - }//end testDefaultPrivacyBookmarksGet - - - /** - * Test that the default privacy setting is selected in the Privacy - * drop-down list when a new bookmark is being created. - */ - public function testDefaultPrivacyBookmarksAdd() - { - $this->setUnittestConfig( - array('defaults' => array('privacy' => 1)) - ); - list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1'); - - $user = $this->us->getUser($uId); - $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' - . $user['username'] . '?action=add' . '&unittestMode=1'; - $req->setUrl($reqUrl); - $req->setMethod(HTTP_Request2::METHOD_GET); - $response = $req->send(); - $response_body = $response->getBody(); - $this->assertNotEquals('', $response_body, 'Response is empty'); - - $x = simplexml_load_string($response_body); - $ns = $x->getDocNamespaces(); - $x->registerXPathNamespace('ns', reset($ns)); - - $elements = $x->xpath('//ns:select[@name="status"]/ns:option[@selected="selected"]'); - $this->assertEquals(1, count($elements), 'No selected status option found'); - $this->assertEquals(1, (string)$elements[0]['value']); - }//end testDefaultPrivacyBookmarksAdd - - } ?> diff --git a/tests/www/bookmarksTest.php b/tests/www/bookmarksTest.php new file mode 100755 index 0000000..df360cc --- /dev/null +++ b/tests/www/bookmarksTest.php @@ -0,0 +1,80 @@ +setUnittestConfig( + array('defaults' => array('privacy' => 2)) + ); + list($req, $uId) = $this->getLoggedInRequest(); + $cookies = $req->getCookieJar(); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_bookmarksget'); + $req->addPostParameter('description', 'Test bookmark 1 for default privacy.'); + $req->addPostParameter('status', '0'); + $req->send(); + + $bms = $this->bs->getBookmarks(0, null, $uId); + $this->assertEquals(1, count($bms['bookmarks'])); + $user = $this->us->getUser($uId); + $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $user['username'] . '?action=get' . '&unittestMode=1'; + + list($req, $uId) = $this->getAuthRequest('?unittestMode=1'); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->setUrl($reqUrl); + $req->setCookieJar($cookies); + $req->addPostParameter('submitted', '1'); + $response = $req->send(); + $response_body = $response->getBody(); + + $x = simplexml_load_string($response_body); + $ns = $x->getDocNamespaces(); + $x->registerXPathNamespace('ns', reset($ns)); + + $elements = $x->xpath('//ns:select[@name="status"]/ns:option[@selected="selected"]'); + $this->assertEquals(1, count($elements), 'No selected status option found'); + $this->assertEquals(2, (string)$elements[0]['value']); + }//end testDefaultPrivacyBookmarksAddMissingTitleMissingPrivacy + + + /** + * Test that the default privacy setting is selected in the Privacy + * drop-down list when a new bookmark is being created. + */ + public function testDefaultPrivacyBookmarksAdd() + { + $this->setUnittestConfig( + array('defaults' => array('privacy' => 1)) + ); + list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1'); + + $user = $this->us->getUser($uId); + $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' + . $user['username'] . '?action=add' . '&unittestMode=1'; + $req->setUrl($reqUrl); + $req->setMethod(HTTP_Request2::METHOD_GET); + $response = $req->send(); + $response_body = $response->getBody(); + $this->assertNotEquals('', $response_body, 'Response is empty'); + + $x = simplexml_load_string($response_body); + $ns = $x->getDocNamespaces(); + $x->registerXPathNamespace('ns', reset($ns)); + + $elements = $x->xpath('//ns:select[@name="status"]/ns:option[@selected="selected"]'); + $this->assertEquals(1, count($elements), 'No selected status option found'); + $this->assertEquals(1, (string)$elements[0]['value']); + }//end testDefaultPrivacyBookmarksAdd + +}//end class www_bookmarksTest +?> diff --git a/tests/www/editTest.php b/tests/www/editTest.php new file mode 100755 index 0000000..1e0fbd5 --- /dev/null +++ b/tests/www/editTest.php @@ -0,0 +1,48 @@ +setUnittestConfig( + array('defaults' => array('privacy' => 2)) + ); + + list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1'); + $cookies = $req->getCookieJar(); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_edit'); + $req->addPostParameter('description', 'Test bookmark 2 for default privacy.'); + $req->addPostParameter('status', '0'); + $res = $req->send(); + $this->assertEquals( + 200, $res->getStatus(), + 'Adding bookmark failed: ' . $res->getBody()); + $bms = $this->bs->getBookmarks(0, null, $uId); + $bm = reset($bms['bookmarks']); + $bmId = $bm['bId']; + + $reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1'; + $req2 = new HTTP_Request2($reqUrl, HTTP_Request2::METHOD_POST); + $req2->setCookieJar($cookies); + $req2->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit'); + $req2->addPostParameter('title', 'Test bookmark 2 for default privacy.'); + $req2->addPostParameter('submitted', '1'); + $res = $req2->send(); + + $this->assertEquals(302, $res->getStatus(), 'Editing bookmark failed'); + + $bm = $this->bs->getBookmark($bmId); + $this->assertEquals('2', $bm['bStatus']); + }//end testDefaultPrivacyEdit + +}//end class www_editTest +?> diff --git a/tests/www/importNetscapeTest.php b/tests/www/importNetscapeTest.php new file mode 100755 index 0000000..9d4cacd --- /dev/null +++ b/tests/www/importNetscapeTest.php @@ -0,0 +1,33 @@ +setUnittestConfig( + array('defaults' => array('privacy' => 1)) + ); + list($req, $uId) = $this->getLoggedInRequest(); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->setUrl($GLOBALS['unittestUrl'] . 'importNetscape.php' . '?unittestMode=1'); + $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_netscapebookmarks.html'); + $res = $req->send(); + $this->assertEquals(200, $res->getStatus(), 'Bookmark import failed'); + + $this->us->setCurrentUserId($uId); + $bms = $this->bs->getBookmarks(0, null, $uId); + $this->assertEquals(3, count($bms['bookmarks'])); + $bm = reset($bms['bookmarks']); + $this->assertEquals('1', $bm['bStatus']); + }//end testDefaultPrivacyImportNetscape + +}//end class www_importNetscapeTest +?> diff --git a/tests/www/importTest.php b/tests/www/importTest.php new file mode 100755 index 0000000..895a320 --- /dev/null +++ b/tests/www/importTest.php @@ -0,0 +1,33 @@ +setUnittestConfig( + array('defaults' => array('privacy' => 2)) + ); + list($req, $uId) = $this->getLoggedInRequest(); + $req->setMethod(HTTP_Request2::METHOD_POST); + $req->setUrl($GLOBALS['unittestUrl'] . 'import.php' . '?unittestMode=1'); + $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_deliciousbookmarks.xml'); + $res = $req->send(); + $this->assertEquals(302, $res->getStatus(), 'Bookmark import failed'); + + $this->us->setCurrentUserId($uId); + $bms = $this->bs->getBookmarks(0, null, $uId); + $this->assertEquals(3, count($bms['bookmarks'])); + $bm = reset($bms['bookmarks']); + $this->assertEquals('2', $bm['bStatus']); + }//end testDefaultPrivacyImport + +}//end class www_importTest +?> -- cgit v1.2.3