} 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"; } } elseif (empty($method) === false && $method !== "GET") { //If a non-admin attempted to access anything other than GET, throw an error at them throw new \RuntimeException("Only administrators are allowed to modify entries", 401); }
/** * @expectedException \PDOException **/ public function testGetInvalidCommentByEmptyComment() { $comments = Comment::getCommentByCommentContent($this->getPDO(), ""); }