diff options
author | Robin Appelman <robin@icewind.nl> | 2024-03-08 12:28:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-08 12:28:58 +0100 |
commit | 47ebc1119af919ad2248636f82990ccc2bfc36fa (patch) | |
tree | 7e3f4688f266fa696b77f62a0e50acdc0ad055bd /tests | |
parent | 7484ed02f7711329962d8aeafdea0a1f0378768c (diff) | |
parent | eb5832b8fa654f6677f8a81c43300e03e05ca429 (diff) | |
download | nextcloud-server-47ebc1119af919ad2248636f82990ccc2bfc36fa.tar.gz nextcloud-server-47ebc1119af919ad2248636f82990ccc2bfc36fa.zip |
Merge pull request #44064 from nextcloud/deprecate-getNumberOfUnreadCommentsForFolder
refactor: depricate getNumberOfUnreadCommentsForFolder and redo it's …
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Comments/ManagerTest.php | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php index 3ad7a67b296..9dcc24d12a1 100644 --- a/tests/lib/Comments/ManagerTest.php +++ b/tests/lib/Comments/ManagerTest.php @@ -10,6 +10,8 @@ use OCP\Comments\IComment; use OCP\Comments\ICommentsEventHandler; use OCP\Comments\ICommentsManager; use OCP\Comments\NotFoundException; +use OCP\Files\Folder; +use OCP\Files\IRootFolder; use OCP\IConfig; use OCP\IDBConnection; use OCP\IInitialStateService; @@ -26,11 +28,14 @@ use Test\TestCase; class ManagerTest extends TestCase { /** @var IDBConnection */ private $connection; + /** @var \PHPUnit\Framework\MockObject\MockObject|IRootFolder */ + private $rootFolder; protected function setUp(): void { parent::setUp(); $this->connection = \OC::$server->getDatabaseConnection(); + $this->rootFolder = $this->createMock(IRootFolder::class); $sql = $this->connection->getDatabasePlatform()->getTruncateTableSQL('`*PREFIX*comments`'); $this->connection->prepare($sql)->execute(); @@ -80,7 +85,8 @@ class ManagerTest extends TestCase { $this->createMock(IConfig::class), $this->createMock(ITimeFactory::class), new EmojiHelper($this->connection), - $this->createMock(IInitialStateService::class) + $this->createMock(IInitialStateService::class), + $this->rootFolder, ); } @@ -329,23 +335,19 @@ class ManagerTest extends TestCase { } public function testGetNumberOfUnreadCommentsForFolder() { - $query = $this->connection->getQueryBuilder(); - $query->insert('filecache') - ->values([ - 'parent' => $query->createNamedParameter(1000), - 'size' => $query->createNamedParameter(10), - 'mtime' => $query->createNamedParameter(10), - 'storage_mtime' => $query->createNamedParameter(10), - 'path' => $query->createParameter('path'), - 'path_hash' => $query->createParameter('path'), - ]); - - $fileIds = []; - for ($i = 0; $i < 4; $i++) { - $query->setParameter('path', 'path_' . $i); - $query->execute(); - $fileIds[] = $query->getLastInsertId(); - } + $folder = $this->createMock(Folder::class); + $fileIds = range(1111, 1114); + $children = array_map(function (int $id) { + $file = $this->createMock(Folder::class); + $file->method('getId') + ->willReturn($id); + return $file; + }, $fileIds); + $folder->method('getId')->willReturn(1000); + $folder->method('getDirectoryListing')->willReturn($children); + $this->rootFolder->method('getFirstNodeById') + ->with($folder->getId()) + ->willReturn($folder); // 2 comment for 1111 with 1 before read marker // 2 comments for 1112 with no read marker @@ -367,7 +369,7 @@ class ManagerTest extends TestCase { $manager->setReadMark('files', (string) $fileIds[0], (new \DateTime())->modify('-1 days'), $user); $manager->setReadMark('files', (string) $fileIds[2], (new \DateTime()), $user); - $amount = $manager->getNumberOfUnreadCommentsForFolder(1000, $user); + $amount = $manager->getNumberOfUnreadCommentsForFolder($folder->getId(), $user); $this->assertEquals([ $fileIds[0] => 1, $fileIds[1] => 2, @@ -750,7 +752,8 @@ class ManagerTest extends TestCase { $this->createMock(IConfig::class), Server::get(ITimeFactory::class), new EmojiHelper($this->connection), - $this->createMock(IInitialStateService::class) + $this->createMock(IInitialStateService::class), + $this->rootFolder, ); // just to make sure they are really set, with correct actor data @@ -795,7 +798,8 @@ class ManagerTest extends TestCase { $this->createMock(IConfig::class), Server::get(ITimeFactory::class), new EmojiHelper($this->connection), - $this->createMock(IInitialStateService::class) + $this->createMock(IInitialStateService::class), + $this->rootFolder, ); $deleted = $manager->deleteCommentsExpiredAtObject('files'); |