diff options
author | Vitor Mattos <vitor@php.rio> | 2022-06-13 12:22:36 -0300 |
---|---|---|
committer | Vitor Mattos <vitor@php.rio> | 2022-06-15 11:58:29 -0300 |
commit | c59b0c2ff7701916fbab4c5d544f43a49acabc34 (patch) | |
tree | 8d7e2e9bf196d6d39d6e87957791f1e263bab5cd /tests | |
parent | 596ead787ba7f7148fceb04de9d7c08cece936bc (diff) | |
download | nextcloud-server-c59b0c2ff7701916fbab4c5d544f43a49acabc34.tar.gz nextcloud-server-c59b0c2ff7701916fbab4c5d544f43a49acabc34.zip |
Add comments expire date
https://github.com/nextcloud/spreed/pull/7327
Signed-off-by: Vitor Mattos <vitor@php.rio>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Comments/FakeManager.php | 4 | ||||
-rw-r--r-- | tests/lib/Comments/ManagerTest.php | 49 |
2 files changed, 52 insertions, 1 deletions
diff --git a/tests/lib/Comments/FakeManager.php b/tests/lib/Comments/FakeManager.php index 5406df96a96..0d615fd2632 100644 --- a/tests/lib/Comments/FakeManager.php +++ b/tests/lib/Comments/FakeManager.php @@ -141,4 +141,8 @@ class FakeManager implements ICommentsManager { public function getLastCommentDateByActor(string $objectType, string $objectId, string $verb, string $actorType, array $actors): array { return []; } + + public function deleteMessageExpiredAtObject(string $objectType, string $objectId): bool { + return true; + } } diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php index 6bcd0dec8ed..29e08b55e10 100644 --- a/tests/lib/Comments/ManagerTest.php +++ b/tests/lib/Comments/ManagerTest.php @@ -14,6 +14,7 @@ use OCP\IConfig; use OCP\IDBConnection; use OCP\IInitialStateService; use OCP\IUser; +use OCP\Server; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -37,7 +38,7 @@ class ManagerTest extends TestCase { $this->connection->prepare($sql)->execute(); } - protected function addDatabaseEntry($parentId, $topmostParentId, $creationDT = null, $latestChildDT = null, $objectId = null) { + protected function addDatabaseEntry($parentId, $topmostParentId, $creationDT = null, $latestChildDT = null, $objectId = null, $expireDate = null) { if (is_null($creationDT)) { $creationDT = new \DateTime(); } @@ -63,6 +64,7 @@ class ManagerTest extends TestCase { 'latest_child_timestamp' => $qb->createNamedParameter($latestChildDT, 'datetime'), 'object_type' => $qb->createNamedParameter('files'), 'object_id' => $qb->createNamedParameter($objectId), + 'expire_date' => $qb->createNamedParameter($expireDate, 'datetime'), ]) ->execute(); @@ -701,6 +703,51 @@ class ManagerTest extends TestCase { $this->assertTrue($wasSuccessful); } + public function testDeleteMessageExpiredAtObject(): void { + $ids = []; + $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('+2 hours')); + $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('+2 hours')); + $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('+2 hours')); + $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('-2 hours')); + $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('-2 hours')); + $ids[] = $this->addDatabaseEntry(0, 0, null, null, null, new \DateTime('-2 hours')); + + $manager = new Manager( + $this->connection, + $this->createMock(LoggerInterface::class), + $this->createMock(IConfig::class), + Server::get(ITimeFactory::class), + new EmojiHelper($this->connection), + $this->createMock(IInitialStateService::class) + ); + + // just to make sure they are really set, with correct actor data + $comment = $manager->get(strval($ids[1])); + $this->assertSame($comment->getObjectType(), 'files'); + $this->assertSame($comment->getObjectId(), 'file64'); + + $deleted = $manager->deleteMessageExpiredAtObject('files', 'file64'); + $this->assertTrue($deleted); + + $deleted = 0; + $exists = 0; + foreach ($ids as $id) { + try { + $manager->get(strval($id)); + $exists++; + } catch (NotFoundException $e) { + $deleted++; + } + } + $this->assertSame($exists, 3); + $this->assertSame($deleted, 3); + + // actor info is gone from DB, but when database interaction is alright, + // we still expect to get true back + $deleted = $manager->deleteMessageExpiredAtObject('files', 'file64'); + $this->assertFalse($deleted); + } + public function testSetMarkRead() { /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */ $user = $this->createMock(IUser::class); |