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
diff options
context:
space:
mode:
authorJasper Weyne <jasperweyne@gmail.com>2022-08-11 09:54:08 +0300
committerGitHub <noreply@github.com>2022-08-11 09:54:08 +0300
commit44f6c931e7c9c74ea4f448d3cdfbaa89f3b7c379 (patch)
tree710a8c1bd1c20c685991de146aa9ef149ec1de7a /tests/lib/Comments
parent0633a1d9f5a7ef06d577ae6556d09db9e94f5684 (diff)
parenta61331f4560468e6d433cf32e008b157b06e7ea9 (diff)
Merge branch 'master' into patch-2
Diffstat (limited to 'tests/lib/Comments')
-rw-r--r--tests/lib/Comments/FakeManager.php4
-rw-r--r--tests/lib/Comments/ManagerTest.php89
2 files changed, 92 insertions, 1 deletions
diff --git a/tests/lib/Comments/FakeManager.php b/tests/lib/Comments/FakeManager.php
index 5406df96a96..b524f5a5000 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 deleteCommentsExpiredAtObject(string $objectType, string $objectId = ''): bool {
+ return true;
+ }
}
diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php
index 6bcd0dec8ed..1af460e6f1b 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,91 @@ class ManagerTest extends TestCase {
$this->assertTrue($wasSuccessful);
}
+ public function testDeleteCommentsExpiredAtObjectTypeAndId(): 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->deleteCommentsExpiredAtObject('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->deleteCommentsExpiredAtObject('files', 'file64');
+ $this->assertFalse($deleted);
+ }
+
+ public function testDeleteCommentsExpiredAtObjectType(): void {
+ $ids = [];
+ $ids[] = $this->addDatabaseEntry(0, 0, null, null, 'file1', new \DateTime('-2 hours'));
+ $ids[] = $this->addDatabaseEntry(0, 0, null, null, 'file2', new \DateTime('-2 hours'));
+ $ids[] = $this->addDatabaseEntry(0, 0, null, null, 'file3', new \DateTime('-2 hours'));
+ $ids[] = $this->addDatabaseEntry(0, 0, null, null, 'file3', new \DateTime());
+ $ids[] = $this->addDatabaseEntry(0, 0, null, null, 'file3', new \DateTime());
+ $ids[] = $this->addDatabaseEntry(0, 0, null, null, 'file3', new \DateTime());
+
+ $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)
+ );
+
+ $deleted = $manager->deleteCommentsExpiredAtObject('files');
+ $this->assertTrue($deleted);
+
+ $deleted = 0;
+ $exists = 0;
+ foreach ($ids as $id) {
+ try {
+ $manager->get((string) $id);
+ $exists++;
+ } catch (NotFoundException $e) {
+ $deleted++;
+ }
+ }
+ $this->assertSame($exists, 0);
+ $this->assertSame($deleted, 6);
+
+ // actor info is gone from DB, but when database interaction is alright,
+ // we still expect to get true back
+ $deleted = $manager->deleteCommentsExpiredAtObject('files');
+ $this->assertFalse($deleted);
+ }
+
public function testSetMarkRead() {
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
$user = $this->createMock(IUser::class);