2014-05-05 11:08:03 +02:00
|
|
|
<?php
|
2014-05-06 11:18:04 +02:00
|
|
|
class ListCommentJobTest extends AbstractTest
|
2014-05-05 11:08:03 +02:00
|
|
|
{
|
|
|
|
public function testNone()
|
|
|
|
{
|
2014-05-06 13:07:24 +02:00
|
|
|
$this->grantAccess('listComments');
|
|
|
|
|
2014-05-05 11:08:03 +02:00
|
|
|
$this->assert->areEqual(0, CommentModel::getCount());
|
|
|
|
|
|
|
|
$ret = $this->runApi(1);
|
|
|
|
$this->assert->areEqual(0, count($ret->entities));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSingle()
|
|
|
|
{
|
2014-05-06 13:07:24 +02:00
|
|
|
$this->grantAccess('listComments');
|
|
|
|
$this->grantAccess('listPosts');
|
|
|
|
|
2014-05-05 11:08:03 +02:00
|
|
|
$this->assert->areEqual(0, CommentModel::getCount());
|
|
|
|
|
2014-05-13 21:08:07 +02:00
|
|
|
$comment = $this->commentMocker->mockSingle();
|
2014-05-05 11:08:03 +02:00
|
|
|
|
|
|
|
$ret = $this->runApi(1);
|
|
|
|
$this->assert->areEqual(1, count($ret->entities));
|
|
|
|
|
|
|
|
$post = $ret->entities[0];
|
2014-05-09 17:54:52 +02:00
|
|
|
$newComment = $post->getComments()[0];
|
|
|
|
$this->assert->areEqual($comment->getPostId(), $newComment->getPostId());
|
|
|
|
$this->assert->areEqual($comment->getPost()->getId(), $newComment->getPost()->getId());
|
|
|
|
|
2014-05-05 11:08:03 +02:00
|
|
|
$samePost = $this->assert->doesNotThrow(function() use ($post)
|
|
|
|
{
|
2014-05-08 08:54:08 +02:00
|
|
|
return PostModel::getById($post->getId());
|
2014-05-05 11:08:03 +02:00
|
|
|
});
|
|
|
|
//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()
|
|
|
|
{
|
2014-05-06 13:07:24 +02:00
|
|
|
$this->grantAccess('listComments');
|
|
|
|
$this->grantAccess('listPosts');
|
|
|
|
|
2014-05-15 10:32:53 +02:00
|
|
|
Core::getConfig()->comments->commentsPerPage = 2;
|
2014-05-05 11:08:03 +02:00
|
|
|
|
|
|
|
$this->assert->areEqual(0, CommentModel::getCount());
|
|
|
|
|
2014-05-13 21:08:07 +02:00
|
|
|
$this->commentMocker->mockMultiple(3);
|
2014-05-05 11:08:03 +02:00
|
|
|
|
|
|
|
$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(),
|
|
|
|
[
|
2014-05-12 00:13:18 +02:00
|
|
|
JobArgs::ARG_PAGE_NUMBER => $page,
|
2014-05-05 11:08:03 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|