From 5992960eb1456890cd1c6519afbb222e367246c4 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Fri, 20 Sep 2024 12:51:01 +0200 Subject: [PATCH] test: Add tests for Capabilities Signed-off-by: provokateurin --- tests/AppInfo/CapabilitiesTest.php | 105 +++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 tests/AppInfo/CapabilitiesTest.php 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()); + } +}