Skip to content

Commit

Permalink
Merge pull request #3260 from nextcloud/test/capabilities
Browse files Browse the repository at this point in the history
test: Add tests for Capabilities
  • Loading branch information
come-nc authored Sep 20, 2024
2 parents 7ebc369 + 5992960 commit 9e75473
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions tests/AppInfo/CapabilitiesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\GroupFolders\Tests\AppInfo;

use OCA\GroupFolders\AppInfo\Capabilities;
use OCA\GroupFolders\Folder\FolderManager;
use OCP\App\IAppManager;
use OCP\IUser;
use OCP\IUserSession;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class CapabilitiesTest extends TestCase {
private IUserSession&MockObject $userSession;
private FolderManager&MockObject $folderManager;
private IAppManager&MockObject $appManager;
private Capabilities $capabilities;

public function setUp(): void {
parent::setUp();

$this->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());
}
}

0 comments on commit 9e75473

Please sign in to comment.