make the private tests really test something
This commit is contained in:
parent
d2aecd8a76
commit
6ec3b102aa
4 changed files with 43 additions and 72 deletions
|
@ -23,6 +23,23 @@
|
||||||
*/
|
*/
|
||||||
class SemanticScuttle_Model_Bookmark
|
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
|
* Checks if the given URL is valid and may be used with this
|
||||||
* SemanticScuttle installation.
|
* SemanticScuttle installation.
|
||||||
|
|
|
@ -76,8 +76,8 @@ class TestBase extends PHPUnit_Framework_TestCase
|
||||||
/**
|
/**
|
||||||
* Creates a new user in the database.
|
* Creates a new user in the database.
|
||||||
*
|
*
|
||||||
* @param string $username Username
|
* @param string $username Username, may be null
|
||||||
* @param string $password Password
|
* @param string $password Password, may be null
|
||||||
* @param mixed $privateKey String private key or boolean true to generate one
|
* @param mixed $privateKey String private key or boolean true to generate one
|
||||||
*
|
*
|
||||||
* @return integer ID of user
|
* @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.
|
* Creates a new user in the database and returns id, username and password.
|
||||||
*
|
*
|
||||||
* @param string $username Username
|
* @param string $username Username, may be null
|
||||||
* @param string $password Password
|
* @param string $password Password, may be null
|
||||||
* @param mixed $privateKey String private key or boolean true to generate one
|
* @param mixed $privateKey String private key or boolean true to generate one
|
||||||
*
|
*
|
||||||
* @return array ID of user, Name of user, password of user, privatekey
|
* @return array ID of user, Name of user, password of user, privatekey
|
||||||
|
|
|
@ -187,8 +187,7 @@ class TestBaseApi extends TestBase
|
||||||
* @uses getRequest()
|
* @uses getRequest()
|
||||||
*/
|
*/
|
||||||
protected function getLoggedInRequest(
|
protected function getLoggedInRequest(
|
||||||
$urlSuffix = null, $auth = true, $privateKey = false,
|
$urlSuffix = null, $auth = true, $privateKey = null
|
||||||
$setCookie = true
|
|
||||||
) {
|
) {
|
||||||
if (is_array($auth)) {
|
if (is_array($auth)) {
|
||||||
list($username, $password) = $auth;
|
list($username, $password) = $auth;
|
||||||
|
@ -196,13 +195,7 @@ class TestBaseApi extends TestBase
|
||||||
$username = 'testuser';
|
$username = 'testuser';
|
||||||
$password = 'testpassword';
|
$password = 'testpassword';
|
||||||
}
|
}
|
||||||
//include privatekey if requested
|
$uid = $this->addUser($username, $password, $privateKey);
|
||||||
if ($privateKey) {
|
|
||||||
$pKey = $this->us->getNewPrivateKey();
|
|
||||||
} else {
|
|
||||||
$pKey = null;
|
|
||||||
}
|
|
||||||
$uid = $this->addUser($username, $password, $pKey);
|
|
||||||
|
|
||||||
$req = new HTTP_Request2(
|
$req = new HTTP_Request2(
|
||||||
$GLOBALS['unittestUrl'] . '/login.php?unittestMode=1',
|
$GLOBALS['unittestUrl'] . '/login.php?unittestMode=1',
|
||||||
|
@ -218,9 +211,7 @@ class TestBaseApi extends TestBase
|
||||||
$this->assertEquals(302, $res->getStatus(), 'Login failure');
|
$this->assertEquals(302, $res->getStatus(), 'Login failure');
|
||||||
|
|
||||||
$req = $this->getRequest($urlSuffix);
|
$req = $this->getRequest($urlSuffix);
|
||||||
if ($setCookie) {
|
|
||||||
$req->setCookieJar($cookies);
|
$req->setCookieJar($cookies);
|
||||||
}
|
|
||||||
|
|
||||||
return array($req, $uid);
|
return array($req, $uid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,44 +7,23 @@ class www_rssTest extends TestBaseApi
|
||||||
protected $urlPart = 'rss.php';
|
protected $urlPart = 'rss.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test a user who does not have RSS private key enabled
|
* A private bookmark should not show up in an rss feed if the
|
||||||
* and with a private bookmark.
|
* user is not logged in nor passes the private key
|
||||||
*/
|
*/
|
||||||
public function testNoRSSPrivateKeyEnabled()
|
public function testPrivateNotLoggedIn()
|
||||||
{
|
{
|
||||||
$this->setUnittestConfig(
|
list($uId, $username) = $this->addUserData();
|
||||||
array('defaults' => array('privacy' => 2))
|
$this->addBookmark(
|
||||||
|
$uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE
|
||||||
);
|
);
|
||||||
|
|
||||||
/* create user without RSS private Key */
|
$req = $this->getRequest('/' . $username);
|
||||||
list($req, $uId) = $this->getLoggedInRequest(null, true, false, false);
|
$response_body = $req->send()->getBody();
|
||||||
|
|
||||||
/* 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();
|
|
||||||
|
|
||||||
$rss = simplexml_load_string($response_body);
|
$rss = simplexml_load_string($response_body);
|
||||||
$items = $rss->channel->item;
|
$items = $rss->channel->item;
|
||||||
|
|
||||||
$this->assertEquals(1, count($items), 'Incorrect Number of RSS Items');
|
$this->assertEquals(0, count($items), 'I see a private bookmark');
|
||||||
$this->assertEquals('title', (string)$items[0]->title);
|
|
||||||
}//end testNoRSSPrivateKeyEnabled
|
}//end testNoRSSPrivateKeyEnabled
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,38 +33,22 @@ class www_rssTest extends TestBaseApi
|
||||||
*/
|
*/
|
||||||
public function testRSSPrivateKeyEnabled()
|
public function testRSSPrivateKeyEnabled()
|
||||||
{
|
{
|
||||||
$this->setUnittestConfig(
|
list($uId, $username, $password, $privateKey) = $this->addUserData(
|
||||||
array('defaults' => array('privacy' => 2))
|
null, null, true
|
||||||
|
);
|
||||||
|
$this->addBookmark(
|
||||||
|
$uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE,
|
||||||
|
null, 'private bookmark'
|
||||||
);
|
);
|
||||||
|
|
||||||
/* create user with RSS private Key */
|
$req = $this->getRequest('/' . $username . '?privatekey=' . $privateKey);
|
||||||
list($req, $uId) = $this->getLoggedInRequest(null, true, false, true);
|
$response_body = $req->send()->getBody();
|
||||||
|
|
||||||
/* 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();
|
|
||||||
|
|
||||||
$rss = simplexml_load_string($response_body);
|
$rss = simplexml_load_string($response_body);
|
||||||
$items = $rss->channel->item;
|
$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
|
}//end testRSSPrivateKeyEnabled
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue