diff --git a/tests/Api/PostsAddTest.php b/tests/Api/PostsAddTest.php
index 0769bdd..dea002e 100644
--- a/tests/Api/PostsAddTest.php
+++ b/tests/Api/PostsAddTest.php
@@ -199,6 +199,113 @@ TXT;
);
}
+ /**
+ * Verify that the URL and description/title are enough parameters
+ * to add a bookmark.
+ */
+ public function testUrlDescEnough()
+ {
+ $this->bs->deleteAll();
+
+ list($req, $uId) = $this->getAuthRequest();
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->addPostParameter('url', 'http://example.org/tag2');
+ $req->addPostParameter('description', 'foo bar');
+ $res = $req->send();
+
+ //all should be well
+ $this->assertEquals(200, $res->getStatus());
+ //verify MIME content type
+ $this->assertEquals(
+ 'text/xml; charset=utf-8',
+ $res->getHeader('content-type')
+ );
+
+ //verify xml
+ $this->assertTag(
+ array(
+ 'tag' => 'result',
+ 'attributes' => array('code' => 'done')
+ ),
+ $res->getBody(),
+ null, false
+ );
+
+ //user has 1 bookmark now
+ $data = $this->bs->getBookmarks(0, null, $uId);
+ $this->assertEquals(1, $data['total']);
+ }
+
+ /**
+ * Verify that the URL is required
+ */
+ public function testUrlRequired()
+ {
+ $this->bs->deleteAll();
+
+ list($req, $uId) = $this->getAuthRequest();
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ //$req->addPostParameter('url', 'http://example.org/tag2');
+ $req->addPostParameter('description', 'foo bar');
+ $res = $req->send();
+
+ //all should be well
+ $this->assertEquals(400, $res->getStatus());
+ //verify MIME content type
+ $this->assertEquals(
+ 'text/xml; charset=utf-8',
+ $res->getHeader('content-type')
+ );
+
+ //verify xml
+ $this->assertTag(
+ array(
+ 'tag' => 'result',
+ 'attributes' => array('code' => 'URL missing')
+ ),
+ $res->getBody(),
+ null, false
+ );
+
+ //user still has 0 bookmarks
+ $data = $this->bs->getBookmarks(0, null, $uId);
+ $this->assertEquals(0, $data['total']);
+ }
+
+ /**
+ * Verify that the description/title is required
+ */
+ public function testDescriptionRequired()
+ {
+ $this->bs->deleteAll();
+
+ list($req, $uId) = $this->getAuthRequest();
+ $req->setMethod(HTTP_Request2::METHOD_POST);
+ $req->addPostParameter('url', 'http://example.org/tag2');
+ $res = $req->send();
+
+ //all should be well
+ $this->assertEquals(400, $res->getStatus());
+ //verify MIME content type
+ $this->assertEquals(
+ 'text/xml; charset=utf-8',
+ $res->getHeader('content-type')
+ );
+
+ //verify xml
+ $this->assertTag(
+ array(
+ 'tag' => 'result',
+ 'attributes' => array('code' => 'Description missing')
+ ),
+ $res->getBody(),
+ null, false
+ );
+
+ //user still has 0 bookmarks
+ $data = $this->bs->getBookmarks(0, null, $uId);
+ $this->assertEquals(0, $data['total']);
+ }
}
if (PHPUnit_MAIN_METHOD == 'Api_PostsAddTest::main') {
diff --git a/www/api/posts_add.php b/www/api/posts_add.php
index b392a80..8b63a16 100644
--- a/www/api/posts_add.php
+++ b/www/api/posts_add.php
@@ -73,17 +73,25 @@ if (isset($_REQUEST['shared']) && (trim($_REQUEST['shared']) == 'no')) {
}
// Error out if there's no address or description
-if (is_null($url) || is_null($description)) {
- $added = false;
+if (is_null($url)) {
+ header('HTTP/1.0 400 Bad Request');
+ $msg = 'URL missing';
+} else if (is_null($description)) {
+ header('HTTP/1.0 400 Bad Request');
+ $msg = 'Description missing';
} else {
-// We're good with info; now insert it!
- if ($bookmarkservice->bookmarkExists($url, $userservice->getCurrentUserId()))
- $added = false;
- else
- $added = $bookmarkservice->addBookmark($url, $description, $extended, '', $status, $tags, null, $dt, true);
+ // We're good with info; now insert it!
+ if ($bookmarkservice->bookmarkExists($url, $userservice->getCurrentUserId())) {
+ $msg = 'something went wrong';
+ } else {
+ $added = $bookmarkservice->addBookmark(
+ $url, $description, $extended, '', $status, $tags, null, $dt, true
+ );
+ $msg = 'done';
+ }
}
// Set up the XML file and output the result.
-echo '\r\n";
-echo '';
+echo '\r\n";
+echo '';
?>
\ No newline at end of file