2014-05-06 00:54:15 +02:00
|
|
|
<?php
|
2014-05-06 11:18:04 +02:00
|
|
|
class PreviewCommentJobTest extends AbstractTest
|
2014-05-06 00:54:15 +02:00
|
|
|
{
|
|
|
|
public function testPreview()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
|
|
|
|
$text = 'alohaaaaaaa';
|
|
|
|
$comment = $this->assert->doesNotThrow(function() use ($text)
|
|
|
|
{
|
|
|
|
return $this->runApi($text);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->assert->areEqual(0, CommentModel::getCount());
|
|
|
|
$this->assert->areEqual($text, $comment->getText());
|
|
|
|
$this->assert->areEqual(Auth::getCurrentUser()->getId(), $comment->getCommenter()->getId());
|
2014-05-07 20:33:52 +02:00
|
|
|
$this->assert->isNotNull($comment->getCreationTime());
|
2014-05-06 00:54:15 +02:00
|
|
|
$this->assert->throws(function() use ($comment)
|
|
|
|
{
|
2014-05-08 08:54:08 +02:00
|
|
|
CommentModel::getById($comment->getId());
|
2014-05-06 00:54:15 +02:00
|
|
|
}, 'Invalid comment ID');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAlmostTooShortText()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
$this->assert->doesNotThrow(function()
|
|
|
|
{
|
|
|
|
return $this->runApi(str_repeat('b', getConfig()->comments->minLength));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAlmostTooLongText()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
$this->assert->doesNotThrow(function()
|
|
|
|
{
|
|
|
|
return $this->runApi(str_repeat('b', getConfig()->comments->maxLength));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTooShortText()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
$this->assert->throws(function()
|
|
|
|
{
|
|
|
|
return $this->runApi(str_repeat('b', getConfig()->comments->minLength - 1));
|
|
|
|
}, 'Comment must have at least');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTooLongText()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
$this->assert->throws(function()
|
|
|
|
{
|
|
|
|
return $this->runApi(str_repeat('b', getConfig()->comments->maxLength + 1));
|
|
|
|
}, 'Comment must have at most');
|
|
|
|
}
|
|
|
|
|
2014-05-07 00:33:11 +02:00
|
|
|
public function testViaPost()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
$post = $this->mockPost(Auth::getCurrentUser());
|
|
|
|
|
|
|
|
$this->assert->doesNotThrow(function() use ($post)
|
|
|
|
{
|
|
|
|
Api::run(
|
|
|
|
new PreviewCommentJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_POST_ID => $post->getId(),
|
|
|
|
JobArgs::ARG_NEW_TEXT => 'alohaaa',
|
2014-05-07 00:33:11 +02:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testViaComment()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
$comment = $this->mockComment(Auth::getCurrentUser());
|
|
|
|
|
|
|
|
$this->assert->doesNotThrow(function() use ($comment)
|
|
|
|
{
|
|
|
|
Api::run(
|
|
|
|
new PreviewCommentJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_COMMENT_ID => $comment->getId(),
|
|
|
|
JobArgs::ARG_NEW_TEXT => 'alohaaa',
|
2014-05-07 00:33:11 +02:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-05-06 00:54:15 +02:00
|
|
|
|
|
|
|
protected function runApi($text)
|
|
|
|
{
|
2014-05-06 11:28:33 +02:00
|
|
|
$post = $this->mockPost(Auth::getCurrentUser());
|
2014-05-06 00:54:15 +02:00
|
|
|
|
|
|
|
return Api::run(
|
|
|
|
new PreviewCommentJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_POST_ID => $post->getId(),
|
|
|
|
JobArgs::ARG_NEW_TEXT => $text,
|
2014-05-06 00:54:15 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function prepare()
|
|
|
|
{
|
2014-05-06 13:07:24 +02:00
|
|
|
getConfig()->registration->needEmailForCommenting = false;
|
|
|
|
$this->grantAccess('addComment');
|
2014-05-06 00:54:15 +02:00
|
|
|
$this->login($this->mockUser());
|
|
|
|
}
|
|
|
|
}
|