szurubooru/tests/JobTests/DeleteCommentJobTest.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

46 lines
986 B
PHP

<?php
class DeleteCommentJobTest extends AbstractTest
{
public function testOwn()
{
$this->prepare();
$this->grantAccess('deleteComment');
$comment = $this->mockComment(Auth::getCurrentUser());
$post = $comment->getPost();
$this->assert->areEqual(1, $post->getCommentCount());
$this->assert->doesNotThrow(function() use ($comment)
{
Api::run(
new DeleteCommentJob(),
[
JobArgs::ARG_COMMENT_ID => $comment->getId(),
]);
});
//post needs to be retrieved again from db to refresh cache
$post = PostModel::getById($post->getId());
$this->assert->areEqual(0, $post->getCommentCount());
$this->assert->areEqual(0, CommentModel::getCount());
}
public function testWrongCommentId()
{
$this->prepare();
$this->assert->throws(function()
{
Api::run(
new DeleteCommentJob(),
[
JobArgs::ARG_COMMENT_ID => 100,
]);
}, 'Invalid comment ID');
}
protected function prepare()
{
$this->login($this->mockUser());
}
}