make the private tests really test something
This commit is contained in:
parent
d2aecd8a76
commit
6ec3b102aa
@ -23,6 +23,23 @@
|
||||
*/
|
||||
class SemanticScuttle_Model_Bookmark
|
||||
{
|
||||
/**
|
||||
* Status "public" / visible for all
|
||||
*/
|
||||
const SPUBLIC = 0;
|
||||
|
||||
/**
|
||||
* Status "shared" / visible for people on your watchlist
|
||||
*/
|
||||
const SWATCHLIST = 1;
|
||||
|
||||
/**
|
||||
* Status "private" / visible for yourself only
|
||||
*/
|
||||
const SPRIVATE = 2;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the given URL is valid and may be used with this
|
||||
* SemanticScuttle installation.
|
||||
|
@ -76,8 +76,8 @@ class TestBase extends PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Creates a new user in the database.
|
||||
*
|
||||
* @param string $username Username
|
||||
* @param string $password Password
|
||||
* @param string $username Username, may be null
|
||||
* @param string $password Password, may be null
|
||||
* @param mixed $privateKey String private key or boolean true to generate one
|
||||
*
|
||||
* @return integer ID of user
|
||||
@ -95,8 +95,8 @@ class TestBase extends PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* Creates a new user in the database and returns id, username and password.
|
||||
*
|
||||
* @param string $username Username
|
||||
* @param string $password Password
|
||||
* @param string $username Username, may be null
|
||||
* @param string $password Password, may be null
|
||||
* @param mixed $privateKey String private key or boolean true to generate one
|
||||
*
|
||||
* @return array ID of user, Name of user, password of user, privatekey
|
||||
|
@ -187,8 +187,7 @@ class TestBaseApi extends TestBase
|
||||
* @uses getRequest()
|
||||
*/
|
||||
protected function getLoggedInRequest(
|
||||
$urlSuffix = null, $auth = true, $privateKey = false,
|
||||
$setCookie = true
|
||||
$urlSuffix = null, $auth = true, $privateKey = null
|
||||
) {
|
||||
if (is_array($auth)) {
|
||||
list($username, $password) = $auth;
|
||||
@ -196,13 +195,7 @@ class TestBaseApi extends TestBase
|
||||
$username = 'testuser';
|
||||
$password = 'testpassword';
|
||||
}
|
||||
//include privatekey if requested
|
||||
if ($privateKey) {
|
||||
$pKey = $this->us->getNewPrivateKey();
|
||||
} else {
|
||||
$pKey = null;
|
||||
}
|
||||
$uid = $this->addUser($username, $password, $pKey);
|
||||
$uid = $this->addUser($username, $password, $privateKey);
|
||||
|
||||
$req = new HTTP_Request2(
|
||||
$GLOBALS['unittestUrl'] . '/login.php?unittestMode=1',
|
||||
@ -218,9 +211,7 @@ class TestBaseApi extends TestBase
|
||||
$this->assertEquals(302, $res->getStatus(), 'Login failure');
|
||||
|
||||
$req = $this->getRequest($urlSuffix);
|
||||
if ($setCookie) {
|
||||
$req->setCookieJar($cookies);
|
||||
}
|
||||
$req->setCookieJar($cookies);
|
||||
|
||||
return array($req, $uid);
|
||||
}
|
||||
|
@ -7,44 +7,23 @@ class www_rssTest extends TestBaseApi
|
||||
protected $urlPart = 'rss.php';
|
||||
|
||||
/**
|
||||
* Test a user who does not have RSS private key enabled
|
||||
* and with a private bookmark.
|
||||
* A private bookmark should not show up in an rss feed if the
|
||||
* user is not logged in nor passes the private key
|
||||
*/
|
||||
public function testNoRSSPrivateKeyEnabled()
|
||||
public function testPrivateNotLoggedIn()
|
||||
{
|
||||
$this->setUnittestConfig(
|
||||
array('defaults' => array('privacy' => 2))
|
||||
list($uId, $username) = $this->addUserData();
|
||||
$this->addBookmark(
|
||||
$uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE
|
||||
);
|
||||
|
||||
/* create user without RSS private Key */
|
||||
list($req, $uId) = $this->getLoggedInRequest(null, true, false, false);
|
||||
|
||||
/* create private bookmark */
|
||||
$this->bs->addBookmark(
|
||||
'http://test', 'test', 'desc', 'note',
|
||||
2,//private
|
||||
array(), null, null, false, false, $uId
|
||||
);
|
||||
/* create public bookmark */
|
||||
$this->bs->addBookmark(
|
||||
'http://example.org', 'title', 'desc', 'priv',
|
||||
0,//public
|
||||
array(), null, null, false, false, $uId
|
||||
);
|
||||
|
||||
/* get user details */
|
||||
$user = $this->us->getUser($uId);
|
||||
|
||||
$req->setMethod(HTTP_Request2::METHOD_POST);
|
||||
$req->setUrl($this->getTestUrl('/' . $user['username'] . '?sort=date_desc'));
|
||||
$response = $req->send();
|
||||
$response_body = $response->getBody();
|
||||
$req = $this->getRequest('/' . $username);
|
||||
$response_body = $req->send()->getBody();
|
||||
|
||||
$rss = simplexml_load_string($response_body);
|
||||
$items = $rss->channel->item;
|
||||
|
||||
$this->assertEquals(1, count($items), 'Incorrect Number of RSS Items');
|
||||
$this->assertEquals('title', (string)$items[0]->title);
|
||||
$this->assertEquals(0, count($items), 'I see a private bookmark');
|
||||
}//end testNoRSSPrivateKeyEnabled
|
||||
|
||||
|
||||
@ -54,38 +33,22 @@ class www_rssTest extends TestBaseApi
|
||||
*/
|
||||
public function testRSSPrivateKeyEnabled()
|
||||
{
|
||||
$this->setUnittestConfig(
|
||||
array('defaults' => array('privacy' => 2))
|
||||
list($uId, $username, $password, $privateKey) = $this->addUserData(
|
||||
null, null, true
|
||||
);
|
||||
$this->addBookmark(
|
||||
$uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE,
|
||||
null, 'private bookmark'
|
||||
);
|
||||
|
||||
/* create user with RSS private Key */
|
||||
list($req, $uId) = $this->getLoggedInRequest(null, true, false, true);
|
||||
|
||||
/* create private bookmark */
|
||||
$this->bs->addBookmark(
|
||||
'http://test', 'test', 'desc', 'note',
|
||||
2,//private
|
||||
array(), null, null, false, false, $uId
|
||||
);
|
||||
/* create public bookmark */
|
||||
$this->bs->addBookmark(
|
||||
'http://example.org', 'title', 'desc', 'priv',
|
||||
0,//public
|
||||
array(), null, null, false, false, $uId
|
||||
);
|
||||
|
||||
/* get user details */
|
||||
$user = $this->us->getUser($uId);
|
||||
|
||||
$req->setMethod(HTTP_Request2::METHOD_POST);
|
||||
$req->setUrl($this->getTestUrl('/' . $user['username'] . '?sort=date_desc&privatekey=' . $user['privateKey']));
|
||||
$response = $req->send();
|
||||
$response_body = $response->getBody();
|
||||
$req = $this->getRequest('/' . $username . '?privatekey=' . $privateKey);
|
||||
$response_body = $req->send()->getBody();
|
||||
|
||||
$rss = simplexml_load_string($response_body);
|
||||
$items = $rss->channel->item;
|
||||
|
||||
$this->assertEquals(2, count($items), 'Incorrect Number of RSS Items');
|
||||
$this->assertEquals(1, count($items), 'I miss the private bookmark');
|
||||
$this->assertEquals('private bookmark', (string)$items[0]->title);
|
||||
}//end testRSSPrivateKeyEnabled
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user