From 720e58872703bf216b93c80f850a79c3f0b8fcc9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 3 Feb 2026 16:34:08 +0100 Subject: [PATCH] test: add tests for getMountsForUserAndPath Signed-off-by: Robin Appelman --- .../tests/Service/DBConfigServiceTest.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/apps/files_external/tests/Service/DBConfigServiceTest.php b/apps/files_external/tests/Service/DBConfigServiceTest.php index b1730eb10fe..d41c2ee3181 100644 --- a/apps/files_external/tests/Service/DBConfigServiceTest.php +++ b/apps/files_external/tests/Service/DBConfigServiceTest.php @@ -12,6 +12,7 @@ use OCA\Files_External\Service\DBConfigService; use OCP\IDBConnection; use OCP\Security\ICrypto; use OCP\Server; +use PHPUnit\Framework\Attributes\DataProvider; use Test\TestCase; #[\PHPUnit\Framework\Attributes\Group(name: 'DB')] @@ -271,4 +272,32 @@ class DBConfigServiceTest extends TestCase { $this->assertEquals($id1, $mounts[0]['mount_id']); $this->assertEquals($id2, $mounts[1]['mount_id']); } + + public static function mountsForPathProvider(): array { + return [ + ['/test/files/test/', false, ['/test']], + ['/test/files/test/', true, ['/test/more']], + ['/test/files/', false, ['/']], + ['/test/files/', true, ['/test', '/test/more', '/test2']], + ]; + } + + #[DataProvider('mountsForPathProvider')] + public function testGetMountsForUserAndPath(string $path, bool $forChildren, array $expectedMountPoints): void { + sort($expectedMountPoints); + $id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); + $this->dbConfig->addApplicable($id1, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); + $id2 = $this->addMount('/test2', 'foo2', 'bar2', 100, DBConfigService::MOUNT_TYPE_PERSONAL); + $this->dbConfig->addApplicable($id2, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); + $id3 = $this->addMount('/test/more', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); + $this->dbConfig->addApplicable($id3, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); + $id4 = $this->addMount('/', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN); + $this->dbConfig->addApplicable($id4, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); + + $mounts = $this->dbConfig->getMountsForUserAndPath('test', [], $path, $forChildren); + $mountPoints = array_map(fn (array $mountInfo) => $mountInfo['mount_point'], $mounts); + sort($mountPoints); + $this->assertEquals($expectedMountPoints, $mountPoints); + + } }