if ($method === "PUT") { $comment = Comment::getCommentByCommentId($pdo, $commentId); if ($comment === null) { throw new \RuntimeException("Comment does not exist", 404); } if ($_SESSION["profile"]->getProfileId() !== $comment->getCommentProfileId()) { throw new \RuntimeException("Only the author of the comment can edit it."); } $comment->setCommentText($requestObject->commentText); $comment->setCommentDate($requestObject->commentDate); //Update the Comment table $comment->update($pdo); $reply->message = "Comment updated"; } elseif ($method === "POST") { $comment = new Comment(null, $requestObject->commentImageId, $_SESSION["profile"]->getProfileId(), $requestObject->commentDate, $requestObject->commentText); $comment->insert($pdo); $reply->message = "Comment created"; } } elseif ($method === "DELETE") { $comment = Comment::getCommentByCommentId($pdo, $commentId); if ($comment === null) { throw new \RuntimeException("Comment does not exist", 404); } if ($_SESSION["profile"]->getProfileId() !== $comment->getCommentProfileId()) { throw new \RuntimeException("Only the author of the comment can delete it."); } $comment->delete($pdo); $deletedObject = new stdClass(); $deletedObject->commentId = $commentId; $reply->message = "Listing deleted"; }
/** * @expectedException \RangeException */ public function testInsertInvalidCommentByTooMuchText() { //Create a new Comment and insert it into mySQL $comment = new Comment(null, $this->image->getImageId(), $this->profile->getProfileId(), $this->VALID_COMMENTDATE, $this->INVALID_TEXTLENGTH); $comment->insert($this->getPDO()); }