summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Api/OpenSearchTest.php2
-rw-r--r--tests/BookmarkTest.php15
-rw-r--r--tests/Model/BookmarkTest.php65
-rw-r--r--tests/TestBaseApi.php17
4 files changed, 94 insertions, 5 deletions
diff --git a/tests/Api/OpenSearchTest.php b/tests/Api/OpenSearchTest.php
index 050713b..f438b46 100644
--- a/tests/Api/OpenSearchTest.php
+++ b/tests/Api/OpenSearchTest.php
@@ -27,7 +27,7 @@ class Api_OpenSearchTest extends TestBaseApi
1, count($arElements),
'OpenSearch link in HTML is missing'
);
- $searchDescUrl = (string)$arElements[0]['href'];
+ $searchDescUrl = $this->completeUrl((string)$arElements[0]['href']);
$this->assertNotNull($searchDescUrl, 'Search description URL is empty');
$req = new HTTP_Request2($searchDescUrl);
diff --git a/tests/BookmarkTest.php b/tests/BookmarkTest.php
index e7ce488..b50dab2 100644
--- a/tests/BookmarkTest.php
+++ b/tests/BookmarkTest.php
@@ -50,8 +50,6 @@ class BookmarkTest extends TestBase
/**
* Tests if adding a bookmark with short url name
* saves it in the database.
- *
- * @return void
*/
public function testAddBookmarkShort()
{
@@ -65,7 +63,16 @@ class BookmarkTest extends TestBase
$this->assertEquals('myShortName', $bm['bShort']);
}
- public function testHardCharactersInBookmarks()
+ public function testAddBookmarkInvalidUrl()
+ {
+ $retval = $this->bs->addBookmark(
+ 'javascript:alert(123)', 'title', 'desc', 'priv',
+ 0, array()
+ );
+ $this->assertFalse($retval, 'Bookmark with invalid URL was accepted');
+ }
+
+ public function testAddBookmarkWithSpecialCharacters()
{
$bs = $this->bs;
$title = "title&é\"'(-è_çà)=";
@@ -95,7 +102,7 @@ class BookmarkTest extends TestBase
);
}
- public function testUnificationOfBookmarks()
+ public function testAddBookmarkUnification()
{
$bs = $this->bs;
diff --git a/tests/Model/BookmarkTest.php b/tests/Model/BookmarkTest.php
new file mode 100644
index 0000000..9f55143
--- /dev/null
+++ b/tests/Model/BookmarkTest.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+
+/**
+ * Unit tests for the SemanticScuttle Bookmark model
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+class Model_BookmarkTest extends TestBase
+{
+ public function testIsValidUrlValid()
+ {
+ $this->assertTrue(
+ SemanticScuttle_Model_Bookmark::isValidUrl(
+ 'http://example.org/foo/bar?baz=foorina'
+ )
+ );
+ $this->assertTrue(
+ SemanticScuttle_Model_Bookmark::isValidUrl(
+ 'https://example.org/'
+ )
+ );
+ $this->assertTrue(
+ SemanticScuttle_Model_Bookmark::isValidUrl(
+ 'ftp://user:pass@example.org/'
+ )
+ );
+ $this->assertTrue(
+ SemanticScuttle_Model_Bookmark::isValidUrl(
+ 'mailto:cweiske@example.org'
+ )
+ );
+ }
+
+ public function testIsValidUrlInvalid()
+ {
+ $this->assertFalse(
+ SemanticScuttle_Model_Bookmark::isValidUrl(
+ 'javascript:alert("foo")'
+ )
+ );
+ $this->assertFalse(
+ SemanticScuttle_Model_Bookmark::isValidUrl(
+ 'foo://example.org/foo/bar'
+ )
+ );
+ }
+
+}
+
+?> \ No newline at end of file
diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php
index 23e1812..2caa701 100644
--- a/tests/TestBaseApi.php
+++ b/tests/TestBaseApi.php
@@ -85,6 +85,23 @@ class TestBaseApi extends TestBase
}
+ /**
+ * Completes an URL that's missing the protocol.
+ * Useful when re-using URLs extracted from HTML
+ *
+ * @param string $url Potentially partial URL
+ *
+ * @return string Full URL
+ */
+ protected function completeUrl($url)
+ {
+ if (substr($url, 0, 2) == '//') {
+ $url = 'http:' . $url;
+ }
+ return $url;
+ }
+
+
/**
* Creates a user and a HTTP GET request object and prepares