2014-05-05 11:08:03 +02:00
|
|
|
<?php
|
2014-05-06 11:18:04 +02:00
|
|
|
class DeleteCommentJobTest extends AbstractTest
|
2014-05-05 11:08:03 +02:00
|
|
|
{
|
2014-05-13 00:02:25 +02:00
|
|
|
public function testRemoval()
|
2014-05-05 11:08:03 +02:00
|
|
|
{
|
|
|
|
$this->prepare();
|
2014-05-06 13:07:24 +02:00
|
|
|
$this->grantAccess('deleteComment');
|
2014-05-05 11:08:03 +02:00
|
|
|
|
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-05 11:08:03 +02:00
|
|
|
{
|
2014-05-09 21:08:13 +02:00
|
|
|
Api::run(
|
|
|
|
new DeleteCommentJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_COMMENT_ID => $comment->getId(),
|
2014-05-09 21:08:13 +02:00
|
|
|
]);
|
2014-05-05 11:08:03 +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());
|
2014-05-05 11:08:03 +02:00
|
|
|
$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(
|
2014-05-05 11:08:03 +02:00
|
|
|
new DeleteCommentJob(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_COMMENT_ID => 100,
|
2014-05-05 11:08:03 +02:00
|
|
|
]);
|
|
|
|
}, 'Invalid comment ID');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function prepare()
|
|
|
|
{
|
|
|
|
$this->login($this->mockUser());
|
|
|
|
}
|
|
|
|
}
|