From f50abde7ac99fd6f7563fb60b662ca21ac320f34 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 10 Apr 2018 10:50:57 +0200 Subject: Add proper comment offset support The offset is based on the last known comment instead of limit-offset, so new comments don't mess up requests which get the history of an object- Signed-off-by: Joas Schilling --- tests/lib/Comments/ManagerTest.php | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests') diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php index 671389232e2..28002ff42cc 100644 --- a/tests/lib/Comments/ManagerTest.php +++ b/tests/lib/Comments/ManagerTest.php @@ -354,6 +354,48 @@ class ManagerTest extends TestCase { ], $amount); } + /** + * @dataProvider dataGetForObjectSince + * @param $lastKnown + * @param $order + * @param $limit + * @param $resultFrom + * @param $resultTo + */ + public function testGetForObjectSince($lastKnown, $order, $limit, $resultFrom, $resultTo) { + $ids = []; + $ids[] = $this->addDatabaseEntry(0, 0); + $ids[] = $this->addDatabaseEntry(0, 0); + $ids[] = $this->addDatabaseEntry(0, 0); + $ids[] = $this->addDatabaseEntry(0, 0); + $ids[] = $this->addDatabaseEntry(0, 0); + + $manager = $this->getManager(); + $comments = $manager->getForObjectSince('files', 'file64', ($lastKnown === null ? 0 : $ids[$lastKnown]), $order, $limit); + + $expected = array_slice($ids, $resultFrom, $resultTo - $resultFrom + 1); + if ($order === 'desc') { + $expected = array_reverse($expected); + } + + $this->assertSame($expected, array_map(function(IComment $c) { + return (int) $c->getId(); + }, $comments)); + } + + public function dataGetForObjectSince() { + return [ + [null, 'asc', 20, 0, 4], + [null, 'asc', 2, 0, 1], + [null, 'desc', 20, 0, 4], + [null, 'desc', 2, 3, 4], + [1, 'asc', 20, 2, 4], + [1, 'asc', 2, 2, 3], + [3, 'desc', 20, 0, 2], + [3, 'desc', 2, 1, 2], + ]; + } + public function invalidCreateArgsProvider() { return [ ['', 'aId-1', 'oType-1', 'oId-1'], -- cgit v1.2.3 From cccdfaa6e9e1ac02193ecfb9d253462fc3320d05 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 19 Apr 2018 17:12:07 +0200 Subject: Fix FakeManager Signed-off-by: Joas Schilling --- tests/lib/Comments/FakeManager.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/lib/Comments/FakeManager.php b/tests/lib/Comments/FakeManager.php index d3dd1dfb58a..3ba66e96692 100644 --- a/tests/lib/Comments/FakeManager.php +++ b/tests/lib/Comments/FakeManager.php @@ -22,6 +22,14 @@ class FakeManager implements ICommentsManager { \DateTime $notOlderThan = null ) {} + public function getForObjectSince( + string $objectType, + string $objectId, + int $lastKnownCommentId, + string $sortDirection = 'asc', + int $limit = 30 + ): array { return []; } + public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null) {} public function create($actorType, $actorId, $objectType, $objectId) {} -- cgit v1.2.3