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

70 lines
1.8 KiB
PHP

<?php
class ListCommentJobTest extends AbstractTest
{
public function testNone()
{
$this->grantAccess('listComments');
$this->assert->areEqual(0, CommentModel::getCount());
$ret = $this->runApi(1);
$this->assert->areEqual(0, count($ret->entities));
}
public function testSingle()
{
$this->grantAccess('listComments');
$this->grantAccess('listPosts');
$this->assert->areEqual(0, CommentModel::getCount());
$comment = $this->mockComment($this->mockUser());
$ret = $this->runApi(1);
$this->assert->areEqual(1, count($ret->entities));
$post = $ret->entities[0];
$newComment = $post->getComments()[0];
$this->assert->areEqual($comment->getPostId(), $newComment->getPostId());
$this->assert->areEqual($comment->getPost()->getId(), $newComment->getPost()->getId());
$samePost = $this->assert->doesNotThrow(function() use ($post)
{
return PostModel::getById($post->getId());
});
//posts retrieved via ListCommentsJob should already have cached its comments
$this->assert->areNotEquivalent($post, $samePost);
$post->resetCache();
$samePost->resetCache();
$this->assert->areEquivalent($post, $samePost);
}
public function testPaging()
{
$this->grantAccess('listComments');
$this->grantAccess('listPosts');
getConfig()->comments->commentsPerPage = 2;
$this->assert->areEqual(0, CommentModel::getCount());
$this->mockComment($this->mockUser());
$this->mockComment($this->mockUser());
$this->mockComment($this->mockUser());
$ret = $this->runApi(1);
$this->assert->areEqual(2, count($ret->entities));
$ret = $this->runApi(2);
$this->assert->areEqual(1, count($ret->entities));
}
protected function runApi($page)
{
return Api::run(
new ListCommentsJob(),
[
JobArgs::ARG_PAGE_NUMBER => $page,
]);
}
}