szurubooru/tests/JobTests/DeleteCommentJobTest.php

99 lines
1.8 KiB
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');
$this->assert->doesNotThrow(function()
{
2014-05-06 13:07:24 +02:00
$this->runApi();
});
$this->assert->areEqual(0, CommentModel::getCount());
}
public function testNoAuth()
{
$this->prepare();
Auth::setCurrentUser(null);
$this->assert->throws(function()
{
2014-05-06 13:07:24 +02:00
$this->runApi();
}, 'Not logged in');
}
public function testOwnAccessDenial()
{
$this->prepare();
$this->assert->throws(function()
{
2014-05-06 13:07:24 +02:00
$this->runApi();
}, 'Insufficient privileges');
}
public function testOtherAccessGrant()
{
$this->prepare();
2014-05-06 13:07:24 +02:00
$this->grantAccess('deleteComment.all');
2014-05-06 13:07:24 +02:00
$comment = $this->mockComment(Auth::getCurrentUser());
//login as someone else
$this->login($this->mockUser());
2014-05-06 13:07:24 +02:00
$this->assert->doesNotThrow(function() use ($comment)
{
2014-05-06 13:07:24 +02:00
$this->runApi($comment);
});
}
public function testOtherAccessDenial()
{
$this->prepare();
2014-05-06 13:07:24 +02:00
$this->grantAccess('deleteComment.own');
$comment = $this->mockComment(Auth::getCurrentUser());
//login as someone else
$this->login($this->mockUser());
$this->assert->throws(function() use ($comment)
{
2014-05-06 13:07:24 +02:00
$this->runApi($comment);
}, 'Insufficient privileges');
}
public function testWrongCommentId()
{
$this->prepare();
$this->assert->throws(function()
{
2014-05-06 13:07:24 +02:00
Api::run(
new DeleteCommentJob(),
[
DeleteCommentJob::COMMENT_ID => 100,
]);
}, 'Invalid comment ID');
}
2014-05-06 13:07:24 +02:00
protected function runApi($comment = null)
{
2014-05-06 13:07:24 +02:00
if ($comment === null)
$comment = $this->mockComment(Auth::getCurrentUser());
return Api::run(
new DeleteCommentJob(),
[
DeleteCommentJob::COMMENT_ID => $comment->getId(),
]);
}
protected function prepare()
{
$this->login($this->mockUser());
}
}