Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Selecting an OpenProject work package does not insert the reference in the Smart Picker [#1200](https://github.com/nextcloud/integration_openproject/pull/1200)
- Smart picker does not list OpenProject work packages [#1206](https://github.com/nextcloud/integration_openproject/pull/1206)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion lib/Listener/OpenProjectReferenceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function handle(Event $event): void {
'authMethod' => $this->appConfig->getValueString(Application::APP_ID, 'authorization_method', '')
];
$this->initialStateService->provideInitialState(
'admin-appConfig',
'admin-config',
Comment thread
Ashim-Stha marked this conversation as resolved.
Resolved
$adminConfig
);
$this->initialStateService->provideInitialState(
Expand Down
114 changes: 114 additions & 0 deletions tests/lib/Listener/OpenProjectReferenceListenerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

/**
* SPDX-FileCopyrightText: 2026 Jankari Tech Pvt. Ltd.
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\OpenProject\Listener;

use OCA\OpenProject\AppInfo\Application;
use OCA\OpenProject\Service\OpenProjectAPIService;
use OCP\AppFramework\Services\IInitialState;
use OCP\Collaboration\Reference\RenderReferenceEvent;
use OCP\IAppConfig;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class OpenProjectReferenceListenerTest extends TestCase {
private OpenProjectReferenceListener $listener;
private MockObject|IInitialState $initialState;
private MockObject|IAppConfig $appConfig;
private MockObject|OpenProjectAPIService $openProjectAPIService;

protected function setUp(): void {
parent::setUp();
$this->appConfig = $this->createMock(IAppConfig::class);
$this->initialState = $this->createMock(IInitialState::class);
$this->openProjectAPIService = $this->createMock(OpenProjectAPIService::class);
$this->listener = new OpenProjectReferenceListener(
$this->initialState,
$this->appConfig,
$this->openProjectAPIService,
'testUser'
);
}

/**
* @return array
*/
public function dataTestHandle(): array {
return [
[
'authMethod' => Application::AUTH_METHOD_OAUTH,
'openprojectUrl' => 'http://local.test',
],
[
'authMethod' => Application::AUTH_METHOD_OIDC,
'openprojectUrl' => 'http://local.test',
],
[
'authMethod' => '',
'openprojectUrl' => '',
],
];
}

/**
* @dataProvider dataTestHandle
*
* @param string $authMethod
* @param string $openprojectUrl
*
* @return void
*/
public function testHandle(string $authMethod, string $openprojectUrl) {
$values = [
'authorization_method' => $authMethod,
'openproject_instance_url' => $openprojectUrl,
];
$this->appConfig->method('getValueString')
->willReturnCallback(
fn (string $app, string $key, string $default = ''):string => $values[$key] ?? $default
);
$this->openProjectAPIService->method('getAccessToken')->willReturn('some-token');

$initStateCalls = [];
$this->initialState->method('provideInitialState')
->willReturnCallback(function ($state, $config) use (&$initStateCalls) {
$initStateCalls[] = [$state, $config];
});

$expectedCalls = [
['admin-config', [
'isAdminConfigOk' => false,
'authMethod' => $authMethod,
],],
['openproject-url', $openprojectUrl],
];
$this->listener->handle($this->createMock(RenderReferenceEvent::class));
$this->assertEqualsCanonicalizing($expectedCalls, $initStateCalls);
}

/**
* @return void
*/
public function testHandleOidcWithoutAccessToken() {
$this->appConfig
->method('getValueString')
->willReturnCallback(
fn (string $app, string $key, string $default = ''): string => $key === 'authorization_method'
? Application::AUTH_METHOD_OIDC
: $default
);
$this->openProjectAPIService
->method('getAccessToken')
->willReturn('');

$this->initialState
->expects($this->never())
->method('provideInitialState');

$this->listener->handle($this->createMock(RenderReferenceEvent::class));
}
}
Loading