szurubooru/tests/JobTests/EditCommentJobTest.php
Marcin Kurczewski 4ba83e6834 Changed job arguments convention back
Restored JobArgs approach. Previous introduction of hierarchic argument
definitions has backfired: it was confusing what class to take arguments
from, the concept of sharing arguments between different jobs was
unintelligible and one never knew where given argument was actually
defined.

This appraoch makes it easier to maintain the arguments list and
simplifies the code a lot.
2014-05-12 00:13:18 +02:00

96 lines
2.2 KiB
PHP

<?php
class EditCommentJobTest extends AbstractTest
{
public function testOwn()
{
$this->prepare();
$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();
$this->grantAccess('editComment.own');
$this->assert->doesNotThrow(function()
{
$this->runApi(str_repeat('b', getConfig()->comments->minLength));
});
}
public function testOwnAlmostTooLongText()
{
$this->prepare();
$this->grantAccess('editComment.own');
$this->assert->doesNotThrow(function()
{
$this->runApi(str_repeat('b', getConfig()->comments->maxLength));
});
}
public function testOwnTooShortText()
{
$this->prepare();
$this->grantAccess('editComment.own');
$this->assert->throws(function()
{
$this->runApi(str_repeat('b', getConfig()->comments->minLength - 1));
}, 'Comment must have at least');
}
public function testOwnTooLongText()
{
$this->prepare();
$this->grantAccess('editComment.own');
$this->assert->throws(function()
{
$this->runApi(str_repeat('b', getConfig()->comments->maxLength + 1));
}, 'Comment must have at most');
}
public function testWrongCommentId()
{
$this->prepare();
$this->assert->throws(function()
{
Api::run(
new EditCommentJob(),
[
JobArgs::ARG_COMMENT_ID => 100,
JobArgs::ARG_NEW_TEXT => 'alohaa',
]);
}, 'Invalid comment ID');
}
protected function runApi($text)
{
$comment = $this->mockComment(Auth::getCurrentUser());
return Api::run(
new EditCommentJob(),
[
JobArgs::ARG_COMMENT_ID => $comment->getId(),
JobArgs::ARG_NEW_TEXT => $text,
]);
}
protected function prepare()
{
$this->login($this->mockUser());
}
}