send 400 status code if a parameter is missing
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@775 b3834d28-1941-0410-a4f8-b48e95affb8f
This commit is contained in:
parent
da272b5a20
commit
3ff661c0e0
2 changed files with 124 additions and 9 deletions
|
@ -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') {
|
if (PHPUnit_MAIN_METHOD == 'Api_PostsAddTest::main') {
|
||||||
|
|
|
@ -73,17 +73,25 @@ if (isset($_REQUEST['shared']) && (trim($_REQUEST['shared']) == 'no')) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error out if there's no address or description
|
// Error out if there's no address or description
|
||||||
if (is_null($url) || is_null($description)) {
|
if (is_null($url)) {
|
||||||
$added = false;
|
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 {
|
} else {
|
||||||
// We're good with info; now insert it!
|
// We're good with info; now insert it!
|
||||||
if ($bookmarkservice->bookmarkExists($url, $userservice->getCurrentUserId()))
|
if ($bookmarkservice->bookmarkExists($url, $userservice->getCurrentUserId())) {
|
||||||
$added = false;
|
$msg = 'something went wrong';
|
||||||
else
|
} else {
|
||||||
$added = $bookmarkservice->addBookmark($url, $description, $extended, '', $status, $tags, null, $dt, true);
|
$added = $bookmarkservice->addBookmark(
|
||||||
|
$url, $description, $extended, '', $status, $tags, null, $dt, true
|
||||||
|
);
|
||||||
|
$msg = 'done';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up the XML file and output the result.
|
// Set up the XML file and output the result.
|
||||||
echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
|
echo '<?xml version="1.0" standalone="yes" ?' . ">\r\n";
|
||||||
echo '<result code="'. ($added ? 'done' : 'something went wrong') .'" />';
|
echo '<result code="' . $msg .'" />';
|
||||||
?>
|
?>
|
Loading…
Reference in a new issue