aboutsummaryrefslogtreecommitdiff
path: root/tests/www
diff options
context:
space:
mode:
Diffstat (limited to 'tests/www')
-rwxr-xr-xtests/www/bookmarksTest.php156
-rwxr-xr-xtests/www/editTest.php48
-rwxr-xr-xtests/www/importNetscapeTest.php33
-rwxr-xr-xtests/www/importTest.php33
-rw-r--r--tests/www/indexTest.php58
-rw-r--r--tests/www/rssTest.php151
-rw-r--r--tests/www/searchTest.php70
7 files changed, 549 insertions, 0 deletions
diff --git a/tests/www/bookmarksTest.php b/tests/www/bookmarksTest.php
new file mode 100755
index 0000000..ac549d8
--- /dev/null
+++ b/tests/www/bookmarksTest.php
@@ -0,0 +1,156 @@
+<?php
+require_once dirname(__FILE__) . '/../prepare.php';
+require_once 'HTTP/Request2.php';
+
+class www_bookmarksTest extends TestBaseApi
+{
+ protected $urlPart = 'bookmarks.php';
+
+ /**
+ * Test that the default privacy setting is selected in the Privacy
+ * drop-down list when adding a new bookmark, sending the form and
+ * missing the title and the privacy setting.
+ */
+ public function testDefaultPrivacyBookmarksAddMissingTitleMissingPrivacy()
+ {
+ $this->setUnittestConfig(
+ array('defaults' => array('privacy' => 2))
+ );
+
+ list($req, $uId) = $this->getLoggedInRequest();
+ $user = $this->us->getUser($uId);
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->setUrl($this->getTestUrl('/' . $user['username'] . '?action=get'));
+ $req->addPostParameter('submitted', '1');
+ $response = $req->send();
+ $response_body = $response->getBody();
+
+ $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(2, (string)$elements[0]['value']);
+ }//end testDefaultPrivacyBookmarksAddMissingTitleMissingPrivacy
+
+
+
+ /**
+ * Test that the default privacy setting is selected in the Privacy
+ * drop-down list when a new bookmark is being created.
+ */
+ public function testDefaultPrivacyBookmarksAdd()
+ {
+ $this->setUnittestConfig(
+ array('defaults' => array('privacy' => 1))
+ );
+ list($req, $uId) = $this->getLoggedInRequest();
+
+ $user = $this->us->getUser($uId);
+ $req->setUrl($this->getTestUrl('/' . $user['username'] . '?action=add'));
+ $response = $req->send();
+ $response_body = $response->getBody();
+ $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
+
+
+
+ /**
+ * Test that the private RSS link exists when a user
+ * has a private key and is enabled
+ */
+ public function testVerifyPrivateRSSLinkExists()
+ {
+ list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1', true, true);
+
+ $user = $this->us->getUser($uId);
+ $req->setUrl($this->getTestUrl('/' . $user['username']));
+ $response = $req->send();
+ $response_body = $response->getBody();
+ $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:link[@rel="alternate" and @type="application/rss+xml"]'
+ );
+ $this->assertEquals(
+ 2, count($elements), 'Number of Links in Head not correct'
+ );
+ $this->assertContains('privateKey=', (string)$elements[1]['href']);
+ }//end testVerifyPrivateRSSLinkExists
+
+
+
+ /**
+ * Test that the private RSS link doesn't exists when a user
+ * does not have a private key or is not enabled
+ */
+ public function testVerifyPrivateRSSLinkDoesNotExist()
+ {
+ list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1', true);
+
+ $user = $this->us->getUser($uId);
+ $req->setUrl($this->getTestUrl('/' . $user['username']));
+ $response = $req->send();
+ $response_body = $response->getBody();
+ $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:link[@rel="alternate" and @type="application/rss+xml"]'
+ );
+ $this->assertEquals(
+ 1, count($elements), 'Number of Links in Head not correct'
+ );
+ $this->assertNotContains('privateKey=', (string)$elements[0]['href']);
+ }//end testVerifyPrivateRSSLinkDoesNotExist
+
+
+
+ /**
+ * We once had the bug that URLs with special characters were escaped too
+ * often. & -> &amp;
+ */
+ public function testAddressEncoding()
+ {
+ $this->addBookmark(null, 'http://example.org?foo&bar=baz');
+
+ //get rid of bookmarks.php
+ $this->url = $GLOBALS['unittestUrl'];
+
+ $html = $this->getRequest()->send()->getBody();
+ $x = simplexml_load_string($html);
+ $ns = $x->getDocNamespaces();
+ $x->registerXPathNamespace('ns', reset($ns));
+
+ $elements = $x->xpath('//ns:a[@class="taggedlink"]');
+ $this->assertEquals(
+ 1, count($elements), 'Number of links is not 1'
+ );
+ $this->assertEquals(
+ 'http://example.org?foo&bar=baz',
+ (string)$elements[0]['href']
+ );
+ }
+
+}//end class www_bookmarksTest
+?>
diff --git a/tests/www/editTest.php b/tests/www/editTest.php
new file mode 100755
index 0000000..1e0fbd5
--- /dev/null
+++ b/tests/www/editTest.php
@@ -0,0 +1,48 @@
+<?php
+require_once dirname(__FILE__) . '/../prepare.php';
+require_once 'HTTP/Request2.php';
+
+class www_editTest extends TestBaseApi
+{
+ protected $urlPart = 'api/posts/add';
+
+ /**
+ * Test that the default privacy setting is used when an existing
+ * bookmark is updated with edit.php.
+ */
+ public function testDefaultPrivacyEdit()
+ {
+ $this->setUnittestConfig(
+ array('defaults' => array('privacy' => 2))
+ );
+
+ list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1');
+ $cookies = $req->getCookieJar();
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->addPostParameter('url', 'http://www.example.org/testdefaultprivacyposts_edit');
+ $req->addPostParameter('description', 'Test bookmark 2 for default privacy.');
+ $req->addPostParameter('status', '0');
+ $res = $req->send();
+ $this->assertEquals(
+ 200, $res->getStatus(),
+ 'Adding bookmark failed: ' . $res->getBody());
+ $bms = $this->bs->getBookmarks(0, null, $uId);
+ $bm = reset($bms['bookmarks']);
+ $bmId = $bm['bId'];
+
+ $reqUrl = $GLOBALS['unittestUrl'] . 'edit.php/' . $bmId . '?unittestMode=1';
+ $req2 = new HTTP_Request2($reqUrl, HTTP_Request2::METHOD_POST);
+ $req2->setCookieJar($cookies);
+ $req2->addPostParameter('address', 'http://www.example.org/testdefaultprivacyposts_edit');
+ $req2->addPostParameter('title', 'Test bookmark 2 for default privacy.');
+ $req2->addPostParameter('submitted', '1');
+ $res = $req2->send();
+
+ $this->assertEquals(302, $res->getStatus(), 'Editing bookmark failed');
+
+ $bm = $this->bs->getBookmark($bmId);
+ $this->assertEquals('2', $bm['bStatus']);
+ }//end testDefaultPrivacyEdit
+
+}//end class www_editTest
+?>
diff --git a/tests/www/importNetscapeTest.php b/tests/www/importNetscapeTest.php
new file mode 100755
index 0000000..9d4cacd
--- /dev/null
+++ b/tests/www/importNetscapeTest.php
@@ -0,0 +1,33 @@
+<?php
+require_once dirname(__FILE__) . '/../prepare.php';
+require_once 'HTTP/Request2.php';
+
+class www_importNetscapeTest extends TestBaseApi
+{
+ protected $urlPart = 'importNetscape.php';
+
+ /**
+ * Test that the default privacy setting is used when bookmarks
+ * are imported from an HTML bookmarks file using importNetscape.php.
+ */
+ public function testDefaultPrivacyImportNetscape()
+ {
+ $this->setUnittestConfig(
+ array('defaults' => array('privacy' => 1))
+ );
+ list($req, $uId) = $this->getLoggedInRequest();
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->setUrl($GLOBALS['unittestUrl'] . 'importNetscape.php' . '?unittestMode=1');
+ $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_netscapebookmarks.html');
+ $res = $req->send();
+ $this->assertEquals(200, $res->getStatus(), 'Bookmark import failed');
+
+ $this->us->setCurrentUserId($uId);
+ $bms = $this->bs->getBookmarks(0, null, $uId);
+ $this->assertEquals(3, count($bms['bookmarks']));
+ $bm = reset($bms['bookmarks']);
+ $this->assertEquals('1', $bm['bStatus']);
+ }//end testDefaultPrivacyImportNetscape
+
+}//end class www_importNetscapeTest
+?>
diff --git a/tests/www/importTest.php b/tests/www/importTest.php
new file mode 100755
index 0000000..895a320
--- /dev/null
+++ b/tests/www/importTest.php
@@ -0,0 +1,33 @@
+<?php
+require_once dirname(__FILE__) . '/../prepare.php';
+require_once 'HTTP/Request2.php';
+
+class www_importTest extends TestBaseApi
+{
+ protected $urlPart = 'import.php';
+
+ /**
+ * Test that the default privacy setting is used when bookmarks
+ * are imported from an XML bookmarks file using import.php.
+ */
+ public function testDefaultPrivacyImport()
+ {
+ $this->setUnittestConfig(
+ array('defaults' => array('privacy' => 2))
+ );
+ list($req, $uId) = $this->getLoggedInRequest();
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->setUrl($GLOBALS['unittestUrl'] . 'import.php' . '?unittestMode=1');
+ $req->addUpload('userfile', dirname(__FILE__) . '/../data/BookmarkTest_deliciousbookmarks.xml');
+ $res = $req->send();
+ $this->assertEquals(302, $res->getStatus(), 'Bookmark import failed');
+
+ $this->us->setCurrentUserId($uId);
+ $bms = $this->bs->getBookmarks(0, null, $uId);
+ $this->assertEquals(3, count($bms['bookmarks']));
+ $bm = reset($bms['bookmarks']);
+ $this->assertEquals('2', $bm['bStatus']);
+ }//end testDefaultPrivacyImport
+
+}//end class www_importTest
+?>
diff --git a/tests/www/indexTest.php b/tests/www/indexTest.php
new file mode 100644
index 0000000..503fd1f
--- /dev/null
+++ b/tests/www/indexTest.php
@@ -0,0 +1,58 @@
+<?php
+require_once dirname(__FILE__) . '/../prepare.php';
+require_once 'HTTP/Request2.php';
+
+class www_indexTest extends TestBaseApi
+{
+ protected $urlPart = '';
+
+ /**
+ * Test that the private rss feed exists when user is setup
+ * with a private key and is enabled
+ */
+ public function testVerifyPrivateRSSLinkExists()
+ {
+ list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1', true, true);
+
+ $user = $this->us->getUser($uId);
+ $response = $req->send();
+ $response_body = $response->getBody();
+
+ $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:link[@rel="alternate" and @type="application/rss+xml"]');
+ $this->assertEquals(2, count($elements), 'Number of Links in Head not correct');
+ $this->assertContains('privateKey=', (string)$elements[1]['href']);
+ }//end testVerifyPrivateRSSLinkExists
+
+
+
+ /**
+ * Test that the private RSS link doesn't exists when a user
+ * does not have a private key, or the private key is not enabled
+ */
+ public function testVerifyPrivateRSSLinkDoesNotExist()
+ {
+ list($req, $uId) = $this->getLoggedInRequest('?unittestMode=1', true);
+
+ $user = $this->us->getUser($uId);
+ $response = $req->send();
+ $response_body = $response->getBody();
+ $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:link[@rel="alternate" and @type="application/rss+xml"]');
+ $this->assertEquals(1, count($elements), 'Number of Links in Head not correct');
+ $this->assertNotContains('privateKey=', (string)$elements[0]['href']);
+ }//end testVerifyPrivateRSSLinkDoesNotExist
+
+
+}//end class www_bookmarksTest
+?>
diff --git a/tests/www/rssTest.php b/tests/www/rssTest.php
new file mode 100644
index 0000000..71d0198
--- /dev/null
+++ b/tests/www/rssTest.php
@@ -0,0 +1,151 @@
+<?php
+require_once dirname(__FILE__) . '/../prepare.php';
+require_once 'HTTP/Request2.php';
+
+class www_rssTest extends TestBaseApi
+{
+ protected $urlPart = 'rss.php';
+
+
+ /**
+ * 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);
+ }
+
+
+
+
+ /**
+ * A private bookmark should not show up in the global rss feed if the
+ * user is not logged in nor passes the private key
+ */
+ public function testAllPrivateBookmarkNotLoggedIn()
+ {
+ list($uId, $username) = $this->addUserData();
+ $this->addBookmark(
+ $uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE
+ );
+
+ $req = $this->getRequest();
+ $response_body = $req->send()->getBody();
+
+ $rss = simplexml_load_string($response_body);
+ $this->assertItemCount($rss, 0, 'I see a private bookmark');
+ }
+
+
+
+ /**
+ * A private bookmark should not show up in the user's rss feed if the
+ * user is not logged in nor passes the private key
+ */
+ public function testUserPrivateBookmarkNotLoggedIn()
+ {
+ list($uId, $username) = $this->addUserData();
+ $this->addBookmark(
+ $uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE
+ );
+
+ $req = $this->getRequest('/' . $username);
+ $response_body = $req->send()->getBody();
+
+ $rss = simplexml_load_string($response_body);
+ $this->assertItemCount($rss, 0, 'I see a private bookmark');
+ }
+
+
+
+
+ /**
+ * Test the global feed by passing the private key
+ */
+ public function testAllPrivateBookmarkWithPrivateKey()
+ {
+ list($uId, $username, $password, $privateKey) = $this->addUserData(
+ null, null, true
+ );
+ $this->addBookmark(
+ $uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE,
+ null, 'private bookmark'
+ );
+
+ $req = $this->getRequest('?privateKey=' . $privateKey);
+ $response_body = $req->send()->getBody();
+
+ $rss = simplexml_load_string($response_body);
+ $this->assertItemCount($rss, 1, 'I miss the private bookmark');
+ $this->assertEquals(
+ 'private bookmark', (string)$rss->channel->item[0]->title
+ );
+ }
+
+
+
+ /**
+ * Test the user feed by passing the private key
+ */
+ public function testUserPrivateBookmarkWithPrivateKey()
+ {
+ list($uId, $username, $password, $privateKey) = $this->addUserData(
+ null, null, true
+ );
+ $this->addBookmark(
+ $uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE,
+ null, 'private bookmark'
+ );
+
+ $req = $this->getRequest('/' . $username . '?privateKey=' . $privateKey);
+ $response_body = $req->send()->getBody();
+
+ $rss = simplexml_load_string($response_body);
+ $this->assertItemCount($rss, 1, 'I miss the private bookmark');
+ $this->assertEquals(
+ 'private bookmark', (string)$rss->channel->item[0]->title
+ );
+ }
+
+
+
+ /**
+ * Verify that fetching the feed with a private key
+ * does not keep you logged in
+ */
+ public function testUserPrivateKeyDoesNotKeepLoggedYouIn()
+ {
+ list($uId, $username, $password, $privateKey) = $this->addUserData(
+ null, null, true
+ );
+ $this->addBookmark(
+ $uId, null, SemanticScuttle_Model_Bookmark::SPRIVATE,
+ null, 'private bookmark'
+ );
+
+ $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);
+ $this->assertItemCount($rss, 0, 'I still see the private bookmark');
+ }
+
+}//end class www_rssTest
+?>
diff --git a/tests/www/searchTest.php b/tests/www/searchTest.php
new file mode 100644
index 0000000..89af32d
--- /dev/null
+++ b/tests/www/searchTest.php
@@ -0,0 +1,70 @@
+<?php
+require_once dirname(__FILE__) . '/../prepare.php';
+require_once 'HTTP/Request2.php';
+
+class www_SearchTest extends TestBaseApi
+{
+ protected $urlPart = 'search.php';
+
+
+ /**
+ * Some browsers using opensearch do "urlencode" on the terms,
+ * for example Firefox. Multiple terms separated with space
+ * appear as "foo+bar" in the URL.
+ */
+ public function testMultipleTermsUrlEncoded()
+ {
+ $this->addBookmark(null, null, 0, null, 'unittest foo bar');
+ $res = $this->getRequest('/all/foo+bar')->send();
+ $this->assertSelectCount(
+ '.xfolkentry', true, $res->getBody(),
+ 'No bookmark found', false
+ );
+
+ $res = $this->getRequest('/all/baz+bat')->send();
+ $this->assertSelectCount(
+ '.xfolkentry', false, $res->getBody(),
+ 'Bookmarks found', false
+ );
+ }
+
+
+ /**
+ * Some browsers using opensearch do "rawurlencode" on the terms,
+ * for example Opera. Multiple terms separated with space
+ * appear as "foo%20bar" in the URL.
+ */
+ public function testMultipleTermsRawUrlEncoded()
+ {
+ $this->addBookmark(null, null, 0, null, 'unittest foo bar');
+ $res = $this->getRequest('/all/foo%20bar')->send();
+ $this->assertSelectCount(
+ '.xfolkentry', true, $res->getBody(),
+ 'No bookmark found', false
+ );
+
+ $res = $this->getRequest('/all/baz%20bat')->send();
+ $this->assertSelectCount(
+ '.xfolkentry', false, $res->getBody(),
+ 'Bookmarks found', false
+ );
+ }
+
+
+ public function testMultipleTags()
+ {
+ $this->markTestSkipped(
+ 'FIXME: SemanticScuttle currently does not search multiple tags'
+ );
+
+ $this->addBookmark(null, null, 0, array('foo', 'bar'));
+ $res = $this->getRequest('/all/foo+bar')->send();
+ $this->assertSelectCount(
+ '.xfolkentry', true, $res->getBody(),
+ 'No bookmark found', false
+ );
+ }
+
+}
+
+?>