Exemplo n.º 1
0
 if (($method === "DELETE" || $method === "PUT") && (empty($commentId) === true || $commentId < 0)) {
     throw new \InvalidArgumentException("Improper ID", 405);
 }
 //Sanitize and trim the other fields.
 $commentImageId = filter_input(INPUT_GET, "commentImageId", FILTER_VALIDATE_INT);
 $commentProfileId = filter_input(INPUT_GET, "commentProfileId", FILTER_VALIDATE_INT);
 $commentDate = filter_input(INPUT_GET, "commentDate", FILTER_SANITIZE_STRING);
 $commentText = filter_input(INPUT_GET, "commentText", FILTER_SANITIZE_STRING);
 if ($method === "GET") {
     //Set an XSRF cookie on 'get' requests
     setXsrfCookie("/");
     //Get the listing based on the current field
     if (empty($commentId) === false) {
         $reply->data = Comment::getCommentByCommentId($pdo, $commentId);
     } elseif (empty($commentImageId) === false) {
         $reply->data = Comment::getCommentByImageId($pdo, $commentImageId)->toArray();
     } elseif (empty($commentProfileId) === false) {
         $reply->data = Comment::getCommentByProfileId($pdo, $commentProfileId)->toArray();
     } elseif (empty($commentText) === false) {
         $reply->data = Comment::getCommentByCommentContent($pdo, $commentText)->toArray();
     }
 }
 //Verify that the object is not empty
 if (empty($_SESSION["profile"]) === false) {
     if ($method === "PUT" || $method === "POST") {
         verifyXsrf();
         $requestContent = file_get_contents("php://input");
         $requestObject = json_decode($requestContent);
         //Ensure that all fields are present.
         if (empty($requestObject->commentImageId) === true) {
             throw new \InvalidArgumentException("Comment Image must exist", 405);
Exemplo n.º 2
0
 /**
  * @expectedException \PDOException
  **/
 public function testGetInvalidCommentByNegativeImageId()
 {
     $comments = Comment::getCommentByImageId($this->getPDO(), $this->NEGATIVE_ID);
 }