Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2022-06-24 11:28:13 +0300
committerGitHub <noreply@github.com>2022-06-24 11:28:13 +0300
commit4722baf970ba514f9495257092f9e200fa7c54e3 (patch)
tree3e91258c679071c7f0dc62c491b9abbbd4b99f62 /tests
parente0c6c1582dbea507fe003c63e61ac33b0bdfe3ae (diff)
parent3be1217c046eca725b14348b73d36c7b8d625d44 (diff)
Merge pull request #32863 from nextcloud/feature/add-comments-expire-date
Add comments expire date
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Comments/FakeManager.php4
-rw-r--r--tests/lib/Comments/ManagerTest.php49
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..7c6971476c7 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((string) $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((string) $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);