2014-05-05 11:08:03 +02:00
|
|
|
<?php
|
2014-05-06 11:18:04 +02:00
|
|
|
class EditCommentJobTest extends AbstractTest
|
2014-05-05 11:08:03 +02:00
|
|
|
{
|
|
|
|
public function testOwn()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
2014-05-06 13:07:24 +02:00
|
|
|
$this->grantAccess('editComment.own');
|
2014-05-05 11:08:03 +02:00
|
|
|
|
|
|
|
$text = 'alohaaaaaaa';
|
|
|
|
$comment = $this->assert->doesNotThrow(function() use ($text)
|
|
|
|
{
|
|
|
|
return $this->runApi($text);
|
|
|
|
});
|
|
|
|
|
2014-05-06 00:54:15 +02:00
|
|
|
$this->assert->areEqual($text, $comment->getText());
|
2014-05-05 21:20:40 +02:00
|
|
|
$this->assert->areEqual(Auth::getCurrentUser()->getId(), $comment->getCommenter()->getId());
|
|
|
|
$this->assert->areEqual(1, $comment->getPost()->getId());
|
2014-05-07 20:33:52 +02:00
|
|
|
$this->assert->isNotNull($comment->getCreationTime());
|
2014-05-05 11:08:03 +02:00
|
|
|
$this->assert->doesNotThrow(function() use ($comment)
|
|
|
|
{
|
2014-05-08 08:54:08 +02:00
|
|
|
CommentModel::getById($comment->getId());
|
2014-05-05 11:08:03 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOwnAlmostTooShortText()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
2014-05-06 13:07:24 +02:00
|
|
|
$this->grantAccess('editComment.own');
|
2014-05-05 11:08:03 +02:00
|
|
|
$this->assert->doesNotThrow(function()
|
|
|
|
{
|
2014-05-15 10:32:53 +02:00
|
|
|
$this->runApi(str_repeat('b', Core::getConfig()->comments->minLength));
|
2014-05-05 11:08:03 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOwnAlmostTooLongText()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
2014-05-06 13:07:24 +02:00
|
|
|
$this->grantAccess('editComment.own');
|
2014-05-05 11:08:03 +02:00
|
|
|
$this->assert->doesNotThrow(function()
|
|
|
|
{
|
2014-05-15 10:32:53 +02:00
|
|
|
$this->runApi(str_repeat('b', Core::getConfig()->comments->maxLength));
|
2014-05-05 11:08:03 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOwnTooShortText()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
2014-05-06 13:07:24 +02:00
|
|
|
$this->grantAccess('editComment.own');
|
2014-05-05 11:08:03 +02:00
|
|
|
$this->assert->throws(function()
|
|
|
|
{
|
2014-05-15 10:32:53 +02:00
|
|
|
$this->runApi(str_repeat('b', Core::getConfig()->comments->minLength - 1));
|
2014-05-05 11:08:03 +02:00
|
|
|
}, 'Comment must have at least');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOwnTooLongText()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
2014-05-06 13:07:24 +02:00
|
|
|
$this->grantAccess('editComment.own');
|
2014-05-05 11:08:03 +02:00
|
|
|
$this->assert->throws(function()
|
|
|
|
{
|
2014-05-15 10:32:53 +02:00
|
|
|
$this->runApi(str_repeat('b', Core::getConfig()->comments->maxLength + 1));
|
2014-05-05 11:08:03 +02:00
|
|
|
}, 'Comment must have at most');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWrongCommentId()
|
|
|
|
{
|
|
|
|
$this->prepare();
|
|
|
|
$this->assert->throws(function()
|
|
|
|
{
|
2014-05-06 13:07:24 +02:00
|
|
|
Api::run(
|
2014-05-05 11:08:03 +02:00
|
|
|
new EditCommentJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_COMMENT_ID => 100,
|
|
|
|
JobArgs::ARG_NEW_TEXT => 'alohaa',
|
2014-05-05 11:08:03 +02:00
|
|
|
]);
|
|
|
|
}, 'Invalid comment ID');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function runApi($text)
|
|
|
|
{
|
2014-05-13 21:08:07 +02:00
|
|
|
$comment = $this->commentMocker->mockSingle();
|
|
|
|
$comment->setCommenter(Auth::getCurrentUser());
|
|
|
|
CommentModel::save($comment);
|
2014-05-05 11:08:03 +02:00
|
|
|
|
|
|
|
return Api::run(
|
|
|
|
new EditCommentJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_COMMENT_ID => $comment->getId(),
|
|
|
|
JobArgs::ARG_NEW_TEXT => $text,
|
2014-05-05 11:08:03 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function prepare()
|
|
|
|
{
|
2014-05-13 21:08:07 +02:00
|
|
|
$this->login($this->userMocker->mockSingle());
|
2014-05-05 11:08:03 +02:00
|
|
|
}
|
|
|
|
}
|