Fixed comment preview
This commit is contained in:
parent
410237d678
commit
ea87bab896
3 changed files with 63 additions and 17 deletions
|
@ -5,13 +5,21 @@ class PreviewCommentJob extends AbstractJob
|
||||||
{
|
{
|
||||||
$user = Auth::getCurrentUser();
|
$user = Auth::getCurrentUser();
|
||||||
$text = $this->getArgument(self::TEXT);
|
$text = $this->getArgument(self::TEXT);
|
||||||
$post = PostModel::findById($this->getArgument(self::POST_ID));
|
|
||||||
|
|
||||||
$comment = CommentModel::spawn();
|
if ($this->hasArgument(self::POST_ID))
|
||||||
|
{
|
||||||
|
$post = PostModel::findById($this->getArgument(self::POST_ID));
|
||||||
|
$comment = CommentModel::spawn();
|
||||||
|
$comment->setPost($post);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$comment = CommentModel::findById($this->getArgument(self::COMMENT_ID));
|
||||||
|
}
|
||||||
|
|
||||||
$comment->setCommenter($user);
|
$comment->setCommenter($user);
|
||||||
$comment->setDateTime(time());
|
$comment->setDateTime(time());
|
||||||
$comment->setText($text);
|
$comment->setText($text);
|
||||||
$comment->setPost($post);
|
|
||||||
|
|
||||||
$comment->validate();
|
$comment->validate();
|
||||||
|
|
||||||
|
|
|
@ -14,22 +14,19 @@ class CommentController
|
||||||
$context->transport->paginator = $ret;
|
$context->transport->paginator = $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function previewAction()
|
|
||||||
{
|
|
||||||
$comment = Api::run(
|
|
||||||
new PreviewCommentJob(),
|
|
||||||
[
|
|
||||||
PreviewCommentJob::POST_ID => InputHelper::get('post-id'),
|
|
||||||
PreviewCommentJob::TEXT => InputHelper::get('text')
|
|
||||||
]);
|
|
||||||
|
|
||||||
getContext()->transport->textPreview = $comment->getTextMarkdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addAction()
|
public function addAction()
|
||||||
{
|
{
|
||||||
if (InputHelper::get('sender') == 'preview')
|
if (InputHelper::get('sender') == 'preview')
|
||||||
return $this->previewAction();
|
{
|
||||||
|
$comment = Api::run(
|
||||||
|
new PreviewCommentJob(),
|
||||||
|
[
|
||||||
|
PreviewCommentJob::POST_ID => InputHelper::get('post-id'),
|
||||||
|
PreviewCommentJob::TEXT => InputHelper::get('text')
|
||||||
|
]);
|
||||||
|
|
||||||
|
getContext()->transport->textPreview = $comment->getTextMarkdown();
|
||||||
|
}
|
||||||
|
|
||||||
Api::run(
|
Api::run(
|
||||||
new AddCommentJob(),
|
new AddCommentJob(),
|
||||||
|
@ -47,7 +44,16 @@ class CommentController
|
||||||
public function editAction($id)
|
public function editAction($id)
|
||||||
{
|
{
|
||||||
if (InputHelper::get('sender') == 'preview')
|
if (InputHelper::get('sender') == 'preview')
|
||||||
return $this->previewAction();
|
{
|
||||||
|
$comment = Api::run(
|
||||||
|
new PreviewCommentJob(),
|
||||||
|
[
|
||||||
|
PreviewCommentJob::COMMENT_ID => $id,
|
||||||
|
PreviewCommentJob::TEXT => InputHelper::get('text')
|
||||||
|
]);
|
||||||
|
|
||||||
|
getContext()->transport->textPreview = $comment->getTextMarkdown();
|
||||||
|
}
|
||||||
|
|
||||||
Api::run(
|
Api::run(
|
||||||
new EditCommentJob(),
|
new EditCommentJob(),
|
||||||
|
|
|
@ -57,6 +57,38 @@ class PreviewCommentJobTest extends AbstractTest
|
||||||
}, 'Comment must have at most');
|
}, 'Comment must have at most');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testViaPost()
|
||||||
|
{
|
||||||
|
$this->prepare();
|
||||||
|
$post = $this->mockPost(Auth::getCurrentUser());
|
||||||
|
|
||||||
|
$this->assert->doesNotThrow(function() use ($post)
|
||||||
|
{
|
||||||
|
Api::run(
|
||||||
|
new PreviewCommentJob(),
|
||||||
|
[
|
||||||
|
PreviewCommentJob::POST_ID => $post->getId(),
|
||||||
|
PreviewCommentJob::TEXT => 'alohaaa',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testViaComment()
|
||||||
|
{
|
||||||
|
$this->prepare();
|
||||||
|
$comment = $this->mockComment(Auth::getCurrentUser());
|
||||||
|
|
||||||
|
$this->assert->doesNotThrow(function() use ($comment)
|
||||||
|
{
|
||||||
|
Api::run(
|
||||||
|
new PreviewCommentJob(),
|
||||||
|
[
|
||||||
|
PreviewCommentJob::COMMENT_ID => $comment->getId(),
|
||||||
|
PreviewCommentJob::TEXT => 'alohaaa',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function runApi($text)
|
protected function runApi($text)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue