szurubooru/tests/JobTests/DeleteCommentJobTest.php

47 lines
986 B
PHP
Raw Normal View History

<?php
2014-05-06 11:18:04 +02:00
class DeleteCommentJobTest extends AbstractTest
{
public function testOwn()
{
$this->prepare();
2014-05-06 13:07:24 +02:00
$this->grantAccess('deleteComment');
2014-05-09 21:08:13 +02:00
$comment = $this->mockComment(Auth::getCurrentUser());
$post = $comment->getPost();
$this->assert->areEqual(1, $post->getCommentCount());
$this->assert->doesNotThrow(function() use ($comment)
{
2014-05-09 21:08:13 +02:00
Api::run(
new DeleteCommentJob(),
[
JobArgs::ARG_COMMENT_ID => $comment->getId(),
2014-05-09 21:08:13 +02:00
]);
});
2014-05-09 21:08:13 +02:00
//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()
{
2014-05-06 13:07:24 +02:00
Api::run(
new DeleteCommentJob(),
[
JobArgs::ARG_COMMENT_ID => 100,
]);
}, 'Invalid comment ID');
}
protected function prepare()
{
$this->login($this->mockUser());
}
}