Fixed comment preview

This commit is contained in:
Marcin Kurczewski 2014-05-07 00:33:11 +02:00
parent 410237d678
commit ea87bab896
3 changed files with 63 additions and 17 deletions

View file

@ -5,13 +5,21 @@ class PreviewCommentJob extends AbstractJob
{
$user = Auth::getCurrentUser();
$text = $this->getArgument(self::TEXT);
$post = PostModel::findById($this->getArgument(self::POST_ID));
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->setDateTime(time());
$comment->setText($text);
$comment->setPost($post);
$comment->validate();

View file

@ -14,7 +14,9 @@ class CommentController
$context->transport->paginator = $ret;
}
public function previewAction()
public function addAction()
{
if (InputHelper::get('sender') == 'preview')
{
$comment = Api::run(
new PreviewCommentJob(),
@ -26,11 +28,6 @@ class CommentController
getContext()->transport->textPreview = $comment->getTextMarkdown();
}
public function addAction()
{
if (InputHelper::get('sender') == 'preview')
return $this->previewAction();
Api::run(
new AddCommentJob(),
[
@ -47,7 +44,16 @@ class CommentController
public function editAction($id)
{
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(
new EditCommentJob(),

View file

@ -57,6 +57,38 @@ class PreviewCommentJobTest extends AbstractTest
}, '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)
{