aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/TestBase.php8
-rw-r--r--tests/TestBaseApi.php15
-rw-r--r--tests/www/rssTest.php73
3 files changed, 25 insertions, 71 deletions
diff --git a/tests/TestBase.php b/tests/TestBase.php
index 5ea656c..2180d2d 100644
--- a/tests/TestBase.php
+++ b/tests/TestBase.php
@@ -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
diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php
index f860d10..1052ae7 100644
--- a/tests/TestBaseApi.php
+++ b/tests/TestBaseApi.php
@@ -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);
}
diff --git a/tests/www/rssTest.php b/tests/www/rssTest.php
index 9d4e41b..fc49264 100644
--- a/tests/www/rssTest.php
+++ b/tests/www/rssTest.php
@@ -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
);
-
- /* 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
+ $this->addBookmark(
+ $uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE,
+ null, 'private bookmark'
);
- /* 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