szurubooru/tests/Tests/JobTests/EditCommentJobTest.php

99 lines
2.3 KiB
PHP
Raw Normal View History

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