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

@ -555,10 +555,10 @@ 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 get action.
* 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))
@ -596,50 +596,31 @@ 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.
* 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

View file

@ -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)
{