test: add tests for getMountsForUserAndPath

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2026-02-03 16:34:08 +01:00
parent 522663b9f0
commit 720e588727
No known key found for this signature in database
GPG key ID: 42B69D8A64526EFB

View file

@ -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);
}
}