summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2018-04-10 10:50:57 +0200
committerJoas Schilling <coding@schilljs.com>2018-04-18 14:23:15 +0200
commitf50abde7ac99fd6f7563fb60b662ca21ac320f34 (patch)
treec43bb540e701b1bf09522abcce1b22207ac63d81 /tests
parent63dfbb2127ec9a930778dd5d31b640c5f2cc3652 (diff)
downloadnextcloud-server-f50abde7ac99fd6f7563fb60b662ca21ac320f34.tar.gz
nextcloud-server-f50abde7ac99fd6f7563fb60b662ca21ac320f34.zip
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 <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Comments/ManagerTest.php42
1 files changed, 42 insertions, 0 deletions
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'],