Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 3 additions & 68 deletions apps/appstore/tests/Controller/ApiControllerTest.php
Original file line number Diff line number Diff line change
@@ -1,99 +1,34 @@
<?php

declare(strict_types=1);

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

namespace OCA\Appstore\Tests\Controller;

use OC\App\AppManager;
use OC\App\AppStore\Bundles\BundleFetcher;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\App\AppStore\Fetcher\CategoryFetcher;
use OC\App\DependencyAnalyzer;
use OC\Installer;
use OCA\Appstore\Controller\ApiController;
use OCP\AppFramework\Http\DataResponse;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\L10N\IFactory;
use OCP\Support\Subscription\IRegistry;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;

#[\PHPUnit\Framework\Attributes\Group(name: 'DB')]
final class ApiControllerTest extends TestCase {
private IRequest&MockObject $request;

private IConfig&MockObject $config;

private IAppConfig&MockObject $appConfig;

private AppManager&MockObject $appManager;

private DependencyAnalyzer&MockObject $dependencyAnalyzer;

private CategoryFetcher&MockObject $categoryFetcher;

private AppFetcher&MockObject $appFetcher;

private IFactory&MockObject $l10nFactory;

private BundleFetcher&MockObject $bundleFetcher;

private Installer&MockObject $installer;

private IRegistry&MockObject $subscriptionRegistry;

private LoggerInterface&MockObject $logger;

private IURLGenerator&MockObject $urlGenerator;

private ApiController $apiController;

#[\Override]
protected function setUp(): void {
parent::setUp();

$this->request = $this->createMock(IRequest::class);
$this->config = $this->createMock(IConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->appManager = $this->createMock(AppManager::class);
$this->dependencyAnalyzer = $this->createMock(DependencyAnalyzer::class);
$this->categoryFetcher = $this->createMock(CategoryFetcher::class);
$this->appFetcher = $this->createMock(AppFetcher::class);
$this->l10nFactory = $this->createMock(IFactory::class);
$this->bundleFetcher = $this->createMock(BundleFetcher::class);
$this->installer = $this->createMock(Installer::class);
$this->subscriptionRegistry = $this->createMock(IRegistry::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);

$this->apiController = new ApiController(
$this->request,
$this->config,
$this->appConfig,
$this->appManager,
$this->dependencyAnalyzer,
$this->categoryFetcher,
$this->appFetcher,
$this->l10nFactory,
$this->bundleFetcher,
$this->installer,
$this->subscriptionRegistry,
$this->logger,
$this->urlGenerator,
);
$this->apiController = $this->createInstanceWithMocks(ApiController::class);
}

public function testListCategories(): void {
$json = file_get_contents(__DIR__ . '/../fixtures/categories.json');
$this->categoryFetcher
$this->mocks[CategoryFetcher::class]
->expects($this->once())
->method('get')
->willReturn(json_decode($json, true)['data']);
Expand Down
59 changes: 9 additions & 50 deletions apps/appstore/tests/Controller/PageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,77 +11,36 @@
use OC\App\AppStore\Bundles\BundleFetcher;
use OC\Installer;
use OCA\Appstore\Controller\PageController;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

#[\PHPUnit\Framework\Attributes\Group(name: 'DB')]
final class PageControllerTest extends TestCase {
private IRequest&MockObject $request;

private IL10N&MockObject $l10n;

private IConfig&MockObject $config;

private IAppManager&MockObject $appManager;

private BundleFetcher&MockObject $bundleFetcher;

private Installer&MockObject $installer;

private IURLGenerator&MockObject $urlGenerator;

private IInitialState&MockObject $initialState;

private PageController $pageController;

#[\Override]
protected function setUp(): void {
parent::setUp();

$this->request = $this->createMock(IRequest::class);
$this->l10n = $this->createMock(IL10N::class);
$this->l10n->expects($this->any())
->method('t')
->willReturnArgument(0);
$this->config = $this->createMock(IConfig::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->bundleFetcher = $this->createMock(BundleFetcher::class);
$this->installer = $this->createMock(Installer::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->initialState = $this->createMock(IInitialState::class);

$this->pageController = new PageController(
$this->request,
$this->l10n,
$this->config,
$this->installer,
$this->appManager,
$this->urlGenerator,
$this->initialState,
$this->bundleFetcher,
);
$this->pageController = $this->createInstanceWithMocks(PageController::class);
}

public function testViewApps(): void {
$this->bundleFetcher->expects($this->once())->method('getBundles')->willReturn([]);
$this->installer->expects($this->any())
$this->mocks[BundleFetcher::class]->expects($this->once())->method('getBundles')->willReturn([]);
$this->mocks[Installer::class]->expects($this->any())
->method('isUpdateAvailable')
->willReturn(false);
$this->config
$this->mocks[IConfig::class]
->expects($this->once())
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(true);

$this->initialState
$this->mocks[IInitialState::class]
->expects($this->exactly(4))
->method('provideInitialState');

Expand All @@ -100,17 +59,17 @@ public function testViewApps(): void {
}

public function testViewAppsAppstoreNotEnabled(): void {
$this->installer->expects($this->any())
$this->mocks[Installer::class]->expects($this->any())
->method('isUpdateAvailable')
->willReturn(false);
$this->bundleFetcher->expects($this->once())->method('getBundles')->willReturn([]);
$this->config
$this->mocks[BundleFetcher::class]->expects($this->once())->method('getBundles')->willReturn([]);
$this->mocks[IConfig::class]
->expects($this->once())
->method('getSystemValueBool')
->with('appstoreenabled', true)
->willReturn(false);

$this->initialState
$this->mocks[IInitialState::class]
->expects($this->exactly(4))
->method('provideInitialState');

Expand Down
36 changes: 8 additions & 28 deletions apps/comments/tests/Unit/Activity/ListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,17 @@
use Test\TestCase;

class ListenerTest extends TestCase {
protected IManager&MockObject $activityManager;
protected IUserSession&MockObject $session;
protected IAppManager&MockObject $appManager;
protected IMountProviderCollection&MockObject $mountProviderCollection;
protected IRootFolder&MockObject $rootFolder;
protected IShareHelper&MockObject $shareHelper;
protected Listener $listener;

#[\Override]
protected function setUp(): void {
parent::setUp();

$this->activityManager = $this->createMock(IManager::class);
$this->session = $this->createMock(IUserSession::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->mountProviderCollection = $this->createMock(IMountProviderCollection::class);
$this->rootFolder = $this->createMock(IRootFolder::class);
$this->shareHelper = $this->createMock(IShareHelper::class);

$this->listener = new Listener(
$this->activityManager,
$this->session,
$this->appManager,
$this->mountProviderCollection,
$this->rootFolder,
$this->shareHelper
);
$this->listener = $this->createInstanceWithMocks(Listener::class);
}

public function testCommentEvent(): void {
$this->appManager->expects($this->any())
$this->mocks[IAppManager::class]->expects($this->any())
->method('isEnabledForAnyone')
->with('activity')
->willReturn(true);
Expand Down Expand Up @@ -89,7 +69,7 @@ public function testCommentEvent(): void {
->method('getMountsForFileId')
->willReturn($mounts);

$this->mountProviderCollection->expects($this->any())
$this->mocks[IMountProviderCollection::class]->expects($this->any())
->method('getMountCache')
->willReturn($userMountCache);

Expand All @@ -100,7 +80,7 @@ public function testCommentEvent(): void {
->method('getFirstNodeById')
->willReturn($node);

$this->rootFolder->expects($this->any())
$this->mocks[IRootFolder::class]->expects($this->any())
->method('getUserFolder')
->willReturn($ownerFolder);

Expand All @@ -109,11 +89,11 @@ public function testCommentEvent(): void {
'254342' => 'there/i/have/it',
'sandra' => 'and/here/i/placed/it'
]];
$this->shareHelper->expects($this->any())
$this->mocks[IShareHelper::class]->expects($this->any())
->method('getPathsForAccessList')
->willReturn($al);

$this->session->expects($this->any())
$this->mocks[IUserSession::class]->expects($this->any())
->method('getUser')
->willReturn($ownerUser);

Expand Down Expand Up @@ -142,10 +122,10 @@ public function testCommentEvent(): void {
->with('add_comment_message', $this->anything())
->willReturnSelf();

$this->activityManager->expects($this->once())
$this->mocks[IManager::class]->expects($this->once())
->method('generateEvent')
->willReturn($activity);
$this->activityManager->expects($this->exactly(count($al['users'])))
$this->mocks[IManager::class]->expects($this->exactly(count($al['users'])))
->method('publish');

$this->listener->commentEvent($event);
Expand Down
Loading
Loading