make privacy tests clearer

This commit is contained in:
Christian Weiske 2011-05-02 09:03:35 +02:00
parent 6b02db7920
commit f629d081dd
2 changed files with 31 additions and 47 deletions

View file

@ -423,8 +423,8 @@ TXT;
/** /**
* Test that a default privacy setting of 2 (Private) is used in adding * Test that a default privacy setting of 2 (Private) is used in adding
* a bookmark. * a bookmark.
*/ */
public function testDefaultPrivacyPrivate() public function testDefaultPrivacyPrivate()
{ {
@ -445,8 +445,8 @@ TXT;
/** /**
* Test that a default privacy setting of 0 (Public) is used in adding * Test that a default privacy setting of 0 (Public) is used in adding
* a bookmark. * a bookmark.
*/ */
public function testDefaultPrivacyPublic() public function testDefaultPrivacyPublic()
{ {
@ -490,7 +490,7 @@ TXT;
$bm = reset($bms['bookmarks']); $bm = reset($bms['bookmarks']);
$bmId = $bm['bId']; $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 = new HTTP_Request2($reqUrl, HTTP_Request2::METHOD_POST);
$req2->setCookieJar($cookies); $req2->setCookieJar($cookies);
$req2->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit'); $req2->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit');
@ -502,7 +502,7 @@ TXT;
$bm = $this->bs->getBookmark($bmId); $bm = $this->bs->getBookmark($bmId);
$this->assertEquals('2', $bm['bStatus']); $this->assertEquals('2', $bm['bStatus']);
}//end testDefaultPrivacyEdit }//end testDefaultPrivacyEdit
/** /**
@ -550,15 +550,15 @@ TXT;
$this->assertEquals(3, count($bms['bookmarks'])); $this->assertEquals(3, count($bms['bookmarks']));
$bm = reset($bms['bookmarks']); $bm = reset($bms['bookmarks']);
$this->assertEquals('2', $bm['bStatus']); $this->assertEquals('2', $bm['bStatus']);
}//end testDefaultPrivacyImport }//end testDefaultPrivacyImport
/** /**
* Test that the default privacy setting is selected in the Privacy * Test that the default privacy setting is selected in the Privacy
* drop-down list when an existing bookmark is accessed with bookmarks.php * drop-down list when adding a new bookmark, sending the form and
* and the get action. * missing the title and the privacy setting.
*/ */
public function testDefaultPrivacyBookmarksGet() public function testDefaultPrivacyBookmarksAddMissingTitleMissingPrivacy()
{ {
$this->setUnittestConfig( $this->setUnittestConfig(
array('defaults' => array('privacy' => 2)) array('defaults' => array('privacy' => 2))
@ -574,7 +574,7 @@ TXT;
$bms = $this->bs->getBookmarks(0, null, $uId); $bms = $this->bs->getBookmarks(0, null, $uId);
$this->assertEquals(1, count($bms['bookmarks'])); $this->assertEquals(1, count($bms['bookmarks']));
$user = $this->us->getUser($uId); $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'); list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
$req->setMethod(HTTP_Request2::METHOD_POST); $req->setMethod(HTTP_Request2::METHOD_POST);
@ -595,51 +595,32 @@ TXT;
/** /**
* Test that the default privacy setting is selected in the Privacy * Test that the default privacy setting is selected in the Privacy
* drop-down list when an existing bookmark is accessed with bookmarks.php * drop-down list when a new bookmark is being created.
* and the add action.
*/ */
public function testDefaultPrivacyBookmarksAdd() public function testDefaultPrivacyBookmarksAdd()
{ {
$this->setUnittestConfig( $this->setUnittestConfig(
array('defaults' => array('privacy' => 1)) 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->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); $user = $this->us->getUser($uId);
$userId = $user['username']; $reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/'
$reqUrl = $GLOBALS['unittestUrl'] . 'bookmarks.php/' . $userId . '?action=add' . '&unittestMode=1'; . $user['username'] . '?action=add' . '&unittestMode=1';
list($req, $uId) = $this->getAuthRequest('?unittestMode=1');
$req->setMethod(HTTP_Request2::METHOD_POST);
$req->setUrl($reqUrl); $req->setUrl($reqUrl);
$testcookiekey = md5($GLOBALS['dbname'].$GLOBALS['tableprefix']).'-login'; $req->setMethod(HTTP_Request2::METHOD_GET);
$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 = $req->send();
$response_body = $response->getBody(); $response_body = $response->getBody();
$start = strpos($response_body, 'Privacy'); $this->assertNotEquals('', $response_body, 'Response is empty');
$end = strpos($response_body, 'referrer');
$length = $end - $start; $x = simplexml_load_string($response_body);
$response_body = substr($response_body, $start, $length); $ns = $x->getDocNamespaces();
$start = strpos($response_body, 'selected'); $x->registerXPathNamespace('ns', reset($ns));
$start = $start - 3;
$length = 1; $elements = $x->xpath('//ns:select[@name="status"]/ns:option[@selected="selected"]');
$selected_privacy = substr($response_body, $start, $length); $this->assertEquals(1, count($elements), 'No selected status option found');
$this->assertEquals('1', $selected_privacy); $this->assertEquals(1, (string)$elements[0]['value']);
}//end testDefaultPrivacyBookmarksAdd }//end testDefaultPrivacyBookmarksAdd

View file

@ -89,6 +89,8 @@ class TestBaseApi extends TestBase
* the request object with authentication details, so that * the request object with authentication details, so that
* the user is logged in. * the user is logged in.
* *
* Only usable for API requests, not "normal" HTTP page requests
*
* @param string $urlSuffix Suffix for the URL * @param string $urlSuffix Suffix for the URL
* @param mixed $auth If user authentication is needed (true/false) * @param mixed $auth If user authentication is needed (true/false)
* or array with username and password * 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 * @return array(HTTP_Request2, integer) HTTP request object and user id
* *
* @uses getRequest() * @uses getRequest()
* @see getLoggedInRequest()
*/ */
protected function getAuthRequest($urlSuffix = null, $auth = true) protected function getAuthRequest($urlSuffix = null, $auth = true)
{ {