nextcloud-shortcuts/tests/unit/Controller/ApiTest.php
Lukas Schaefer c5c1de0108
All checks were successful
PHPUnit SQLite / versions (pull_request) Successful in 4s
PHPUnit SQLite / changes (pull_request) Successful in 1s
Lint info.xml / info.xml lint (pull_request) Successful in 3s
PHP / versions (pull_request) Successful in 5s
Static analysis / versions (pull_request) Successful in 3s
REUSE Compliance Check / reuse-compliance-check (pull_request) Successful in 3s
Node / NPM (pull_request) Successful in 21s
PHP / PHP 8.5 (8.5) (pull_request) Successful in 54s
PHP / PHP 8.2 (8.2) (pull_request) Successful in 2m16s
PHPUnit SQLite / SQLite PHP 8.5 Nextcloud master (8.5, master) (pull_request) Successful in 2m27s
PHPUnit SQLite / phpunit-sqlite-summary (pull_request) Successful in 1s
Static analysis / static-psalm-analysis dev-stable34 (dev-stable34, 8.5) (pull_request) Successful in 1m48s
Static analysis / static-psalm-analysis dev-stable33 (dev-stable33, 8.5) (pull_request) Successful in 2m30s
Static analysis / static-psalm-analysis dev-master (dev-master, 8.5) (pull_request) Successful in 2m49s
Static analysis / static-psalm-analysis-summary (pull_request) Successful in 1s
Create initial version that supports shortcut files
Signed-off-by: Lukas Schaefer <lukas@lschaefer.xyz>
2026-08-01 12:28:04 -04:00

66 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Lukas Schaefer
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Controller;
use OCA\Shortcuts\AppInfo\Application;
use OCA\Shortcuts\Controller\ApiController;
use OCA\Shortcuts\Service\ShortcutService;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
use PHPUnit\Framework\TestCase;
final class ApiTest extends TestCase {
public function testCreate(): void {
$request = $this->createMock(IRequest::class);
$service = $this->createMock(ShortcutService::class);
$userSession = $this->createMock(IUserSession::class);
$user = $this->createMock(IUser::class);
$userSession->method('getUser')->willReturn($user);
$payload = [
'fileId' => 11,
'name' => 'main.tex.nextcloudshortcut',
'path' => '/test/main.tex.nextcloudshortcut',
'targetFileId' => 320,
'targetType' => 'file',
];
$service->expects($this->once())
->method('create')
->with($user, 320, '/test', null)
->willReturn($payload);
$controller = new ApiController(Application::APP_ID, $request, $service, $userSession);
$this->assertSame($payload, $controller->create(320, '/test')->getData());
}
public function testResolve(): void {
$request = $this->createMock(IRequest::class);
$service = $this->createMock(ShortcutService::class);
$userSession = $this->createMock(IUserSession::class);
$user = $this->createMock(IUser::class);
$userSession->method('getUser')->willReturn($user);
$payload = [
'targetFileId' => 320,
'targetType' => 'file',
'name' => 'main.tex',
'path' => '/docs/main.tex',
'dirname' => '/docs',
];
$service->expects($this->once())
->method('resolve')
->with($user, 50)
->willReturn($payload);
$controller = new ApiController(Application::APP_ID, $request, $service, $userSession);
$this->assertSame($payload, $controller->resolve(50)->getData());
}
}