2011-06-15 06:58:29 +02:00
|
|
|
<?php
|
|
|
|
require_once dirname(__FILE__) . '/../prepare.php';
|
|
|
|
require_once 'HTTP/Request2.php';
|
|
|
|
|
|
|
|
class www_rssTest extends TestBaseApi
|
|
|
|
{
|
|
|
|
protected $urlPart = 'rss.php';
|
|
|
|
|
2011-06-27 20:04:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifies that the given number of feed items exist in the feed
|
|
|
|
* XML tree.
|
|
|
|
*
|
|
|
|
* @var SimpleXMLElement $simpleXml RSS feed root element
|
|
|
|
* @var integer $nCount Number of expected feed items
|
|
|
|
* @var string $msg Error message
|
|
|
|
*/
|
|
|
|
protected function assertItemCount(
|
|
|
|
SimpleXMLElement $simpleXml, $nCount, $msg = null
|
|
|
|
) {
|
|
|
|
$this->assertEquals($nCount, count($simpleXml->channel->item), $msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-15 06:58:29 +02:00
|
|
|
/**
|
2011-06-27 19:39:38 +02:00
|
|
|
* A private bookmark should not show up in an rss feed if the
|
|
|
|
* user is not logged in nor passes the private key
|
2011-06-15 06:58:29 +02:00
|
|
|
*/
|
2011-06-27 21:55:07 +02:00
|
|
|
public function testUserPrivateBookmarkNotLoggedIn()
|
2011-06-15 06:58:29 +02:00
|
|
|
{
|
2011-06-27 19:39:38 +02:00
|
|
|
list($uId, $username) = $this->addUserData();
|
|
|
|
$this->addBookmark(
|
|
|
|
$uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE
|
2011-06-15 06:58:29 +02:00
|
|
|
);
|
|
|
|
|
2011-06-27 19:39:38 +02:00
|
|
|
$req = $this->getRequest('/' . $username);
|
|
|
|
$response_body = $req->send()->getBody();
|
2011-06-15 06:58:29 +02:00
|
|
|
|
|
|
|
$rss = simplexml_load_string($response_body);
|
2011-06-27 20:04:03 +02:00
|
|
|
$this->assertItemCount($rss, 0, 'I see a private bookmark');
|
2011-06-27 19:52:02 +02:00
|
|
|
}
|
|
|
|
|
2011-06-15 06:58:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test a user who has RSS private key setup
|
|
|
|
* with private bookmark.
|
|
|
|
*/
|
2011-06-27 21:55:07 +02:00
|
|
|
public function testUserPrivateBookmarkWithPrivateKey()
|
2011-06-15 06:58:29 +02:00
|
|
|
{
|
2011-06-27 19:39:38 +02:00
|
|
|
list($uId, $username, $password, $privateKey) = $this->addUserData(
|
|
|
|
null, null, true
|
2011-06-15 06:58:29 +02:00
|
|
|
);
|
2011-06-27 19:39:38 +02:00
|
|
|
$this->addBookmark(
|
|
|
|
$uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE,
|
|
|
|
null, 'private bookmark'
|
2011-06-15 06:58:29 +02:00
|
|
|
);
|
|
|
|
|
2011-06-27 19:39:38 +02:00
|
|
|
$req = $this->getRequest('/' . $username . '?privatekey=' . $privateKey);
|
|
|
|
$response_body = $req->send()->getBody();
|
2011-06-15 06:58:29 +02:00
|
|
|
|
|
|
|
$rss = simplexml_load_string($response_body);
|
2011-06-27 20:04:03 +02:00
|
|
|
$this->assertItemCount($rss, 1, 'I miss the private bookmark');
|
|
|
|
$this->assertEquals(
|
|
|
|
'private bookmark', (string)$rss->channel->item[0]->title
|
|
|
|
);
|
2011-06-27 19:52:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify that fetching the feed with a private key
|
|
|
|
* does not keep you logged in
|
|
|
|
*/
|
2011-06-27 21:55:07 +02:00
|
|
|
public function testUserPrivateKeyDoesNotKeepLoggedYouIn()
|
2011-06-27 19:52:02 +02:00
|
|
|
{
|
|
|
|
list($uId, $username, $password, $privateKey) = $this->addUserData(
|
|
|
|
null, null, true
|
|
|
|
);
|
|
|
|
$this->addBookmark(
|
|
|
|
$uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE,
|
|
|
|
null, 'private bookmark'
|
|
|
|
);
|
2011-06-15 06:58:29 +02:00
|
|
|
|
2011-06-27 19:52:02 +02:00
|
|
|
$req = $this->getRequest('/' . $username . '?privatekey=' . $privateKey);
|
|
|
|
$cookies = $req->setCookieJar()->getCookieJar();
|
|
|
|
$response_body = $req->send()->getBody();
|
|
|
|
|
|
|
|
$rss = simplexml_load_string($response_body);
|
|
|
|
$items = $rss->channel->item;
|
|
|
|
|
|
|
|
$this->assertEquals(1, count($items), 'I miss the private bookmark');
|
|
|
|
$this->assertEquals('private bookmark', (string)$items[0]->title);
|
|
|
|
|
|
|
|
//request the feed again, with the same cookies
|
|
|
|
$req = $this->getRequest('/' . $username);
|
|
|
|
$req->setCookieJar($cookies);
|
|
|
|
$response_body = $req->send()->getBody();
|
|
|
|
$rss = simplexml_load_string($response_body);
|
2011-06-27 20:04:03 +02:00
|
|
|
$this->assertItemCount($rss, 0, 'I still see the private bookmark');
|
2011-06-27 19:52:02 +02:00
|
|
|
}
|
2011-06-15 06:58:29 +02:00
|
|
|
|
|
|
|
}//end class www_rssTest
|
|
|
|
?>
|