diff --git a/tests/AppInfo/CapabilitiesTest.php b/tests/AppInfo/CapabilitiesTest.php new file mode 100644 index 000000000..393d9189a --- /dev/null +++ b/tests/AppInfo/CapabilitiesTest.php @@ -0,0 +1,105 @@ +userSession = $this->createMock(IUserSession::class); + $this->folderManager = $this->createMock(FolderManager::class); + $this->appManager = $this->createMock(IAppManager::class); + + $this->capabilities = new Capabilities( + $this->userSession, + $this->folderManager, + $this->appManager, + ); + } + + public function testGetCapabilitiesWithoutUser(): void { + $this->userSession + ->expects($this->once()) + ->method('getUser') + ->willReturn(null); + + $this->assertEquals([], $this->capabilities->getCapabilities()); + } + + public function testGetCapabilitiesWithGroupfolders(): void { + $user = $this->createMock(IUser::class); + + $this->userSession + ->expects($this->once()) + ->method('getUser') + ->willReturn($user); + + $this->appManager + ->expects($this->once()) + ->method('getAppVersion') + ->with('groupfolders') + ->willReturn('1.2.3'); + + $this->folderManager + ->expects($this->once()) + ->method('getFoldersForUser') + ->with($user) + ->willReturn(['key' => 'value']); + + $this->assertEquals([ + 'groupfolders' => [ + 'appVersion' => '1.2.3', + 'hasGroupFolders' => true, + ] + ], $this->capabilities->getCapabilities()); + } + + + public function testGetCapabilitiesWithoutGroupfolders(): void { + $user = $this->createMock(IUser::class); + + $this->userSession + ->expects($this->once()) + ->method('getUser') + ->willReturn($user); + + $this->appManager + ->expects($this->once()) + ->method('getAppVersion') + ->with('groupfolders') + ->willReturn('1.2.3'); + + $this->folderManager + ->expects($this->once()) + ->method('getFoldersForUser') + ->with($user) + ->willReturn([]); + + $this->assertEquals([ + 'groupfolders' => [ + 'appVersion' => '1.2.3', + 'hasGroupFolders' => false, + ] + ], $this->capabilities->getCapabilities()); + } +}