Skip to content

Commit

Permalink
fix php failed tests due to changes
Browse files Browse the repository at this point in the history
Signed-off-by: Sagar <sagargurung1001@gmail.com>
  • Loading branch information
SagarGi committed Dec 12, 2024
1 parent 252aa30 commit f3bbd21
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/Reference/WorkPackageReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@ public function matchReference(string $referenceText): bool {
return $this->getWorkPackageIdFromUrl($referenceText) !== null;
}

public function getIsAdminConfigOk(): bool {
return OpenProjectAPIService::isAdminConfigOk($this->config);
}

/**
*/
public function resolveReference(string $referenceText): ?IReference {
if ($this->matchReference($referenceText) && OpenProjectAPIService::isAdminConfigOk($this->config) ) {
if ($this->matchReference($referenceText) && $this->getIsAdminConfigOk() ) {
$wpId = $this->getWorkPackageIdFromUrl($referenceText);
if ($wpId !== null) {
$wpInfo = $this->openProjectAPIService->getWorkPackageInfo($this->userId, $wpId);
Expand Down
85 changes: 84 additions & 1 deletion tests/lib/Controller/OpenProjectAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function setUpMocks(): void {
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'openproject_instance_url'],
)->willReturnOnConsecutiveCalls('http://openproject.org');
)->willReturnOnConsecutiveCalls('https://openproject.org');
}

/**
Expand Down Expand Up @@ -122,6 +122,15 @@ public function testGetNotifications(): void {
* @return void
*/
public function testGetNotificationsNoAccessToken() {
$this->configMock = $this->getMockBuilder(IConfig::class)->getMock();
$this->configMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'openproject_instance_url'],
['integration_openproject', 'authorization_method'],
)->willReturnOnConsecutiveCalls(
'https://openproject.org',
OpenProjectAPIService::AUTH_METHOD_OAUTH);
$this->getUserValueMock('');
$service = $this->createMock(OpenProjectAPIService::class);
$controller = new OpenProjectAPIController(
Expand Down Expand Up @@ -193,6 +202,15 @@ public function testGetNotificationsErrorResponse() {
* @return void
*/
public function testGetOpenProjectAvatar() {
$this->configMock = $this->getMockBuilder(IConfig::class)->getMock();
$this->configMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'openproject_instance_url'],
['integration_openproject', 'authorization_method'],
)->willReturnOnConsecutiveCalls(
'https://openproject.org',
OpenProjectAPIService::AUTH_METHOD_OAUTH);
$this->getUserValueMock();
$service = $this->getMockBuilder(OpenProjectAPIService::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -308,6 +326,15 @@ public function testGetSearchedWorkPackages(?string $searchQuery, ?int $fileId,
* @return void
*/
public function testGetSearchedWorkPackagesNoAccessToken(): void {
$this->configMock = $this->getMockBuilder(IConfig::class)->getMock();
$this->configMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'openproject_instance_url'],
['integration_openproject', 'authorization_method'],
)->willReturnOnConsecutiveCalls(
'https://openproject.org',
OpenProjectAPIService::AUTH_METHOD_OAUTH);
$this->getUserValueMock('');
$service = $this->createMock(OpenProjectAPIService::class);
$controller = new OpenProjectAPIController(
Expand Down Expand Up @@ -411,6 +438,15 @@ public function testGetOpenProjectWorkPackageStatus(): void {
* @return void
*/
public function testGetOpenProjectWorkPackageStatusErrorResponse(): void {
$this->configMock = $this->getMockBuilder(IConfig::class)->getMock();
$this->configMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'openproject_instance_url'],
['integration_openproject', 'authorization_method'],
)->willReturnOnConsecutiveCalls(
'https://openproject.org',
OpenProjectAPIService::AUTH_METHOD_OAUTH);
$this->getUserValueMock('');
$service = $this->createMock(OpenProjectAPIService::class);
$controller = new OpenProjectAPIController(
Expand Down Expand Up @@ -513,6 +549,15 @@ public function testGetOpenProjectWorkPackageType(): void {
* @return void
*/
public function testGetOpenProjectWorkPackageTypeErrorResponse(): void {
$this->configMock = $this->getMockBuilder(IConfig::class)->getMock();
$this->configMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'openproject_instance_url'],
['integration_openproject', 'authorization_method'],
)->willReturnOnConsecutiveCalls(
'https://openproject.org',
OpenProjectAPIService::AUTH_METHOD_OAUTH);
$this->getUserValueMock('');
$service = $this->createMock(OpenProjectAPIService::class);
$controller = new OpenProjectAPIController(
Expand All @@ -532,6 +577,15 @@ public function testGetOpenProjectWorkPackageTypeErrorResponse(): void {
* @return void
*/
public function testGetOpenProjectWorkPackageTypeNoAccessToken(): void {
$this->configMock = $this->getMockBuilder(IConfig::class)->getMock();
$this->configMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'openproject_instance_url'],
['integration_openproject', 'authorization_method'],
)->willReturnOnConsecutiveCalls(
'https://openproject.org',
OpenProjectAPIService::AUTH_METHOD_OAUTH);
$this->getUserValueMock();
$service = $this->getMockBuilder(OpenProjectAPIService::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -625,6 +679,15 @@ public function testGetWorkPackageFileLinks(): void {
* @return void
*/
public function testGetWorkPackageFileLinksErrorResponse(): void {
$this->configMock = $this->getMockBuilder(IConfig::class)->getMock();
$this->configMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'openproject_instance_url'],
['integration_openproject', 'authorization_method'],
)->willReturnOnConsecutiveCalls(
'https://openproject.org',
OpenProjectAPIService::AUTH_METHOD_OAUTH);
$this->getUserValueMock('');
$service = $this->createMock(OpenProjectAPIService::class);
$controller = new OpenProjectAPIController(
Expand Down Expand Up @@ -721,6 +784,15 @@ public function testDeleteFileLink(): void {
* @return void
*/
public function testDeleteFileLinkErrorResponse(): void {
$this->configMock = $this->getMockBuilder(IConfig::class)->getMock();
$this->configMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'openproject_instance_url'],
['integration_openproject', 'authorization_method'],
)->willReturnOnConsecutiveCalls(
'https://openproject.org',
OpenProjectAPIService::AUTH_METHOD_OAUTH);
$this->getUserValueMock('');
$service = $this->createMock(OpenProjectAPIService::class);
$controller = new OpenProjectAPIController(
Expand Down Expand Up @@ -1042,13 +1114,15 @@ public function testGetOpenProjectOauthURLWithStateAndPKCE(): void {
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'openproject_instance_url'],
['integration_openproject', 'authorization_method'],
['integration_openproject', 'openproject_client_id'],
['integration_openproject', 'openproject_client_secret'],
['integration_openproject', 'openproject_instance_url'],
['integration_openproject', 'openproject_client_id'],
['integration_openproject', 'openproject_instance_url'],
)->willReturnOnConsecutiveCalls(
'http://openproject.org',
OpenProjectAPIService::AUTH_METHOD_OAUTH,
'myClientID',
'myClientSecret',
'http://openproject.org',
Expand Down Expand Up @@ -1186,6 +1260,15 @@ public function testLinkWorkPackageToMultipleFiles() {
* @return void
*/
public function testLinkWorkPackageToFileErrorResponse() {
$this->configMock = $this->getMockBuilder(IConfig::class)->getMock();
$this->configMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'openproject_instance_url'],
['integration_openproject', 'authorization_method'],
)->willReturnOnConsecutiveCalls(
'https://openproject.org',
OpenProjectAPIService::AUTH_METHOD_OAUTH);
$this->getUserValueMock('');
$service = $this->createMock(OpenProjectAPIService::class);
$controller = new OpenProjectAPIController(
Expand Down
16 changes: 14 additions & 2 deletions tests/lib/Service/OpenProjectAPIServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,21 +704,27 @@ private function getOpenProjectAPIService(
$this->defaultConfigMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'authorization_method'],
['integration_openproject', 'openproject_client_id'],
['integration_openproject', 'openproject_client_secret'],
['integration_openproject', 'openproject_instance_url'],
['integration_openproject', 'authorization_method'],

// for second request after invalid token reply
['integration_openproject', 'authorization_method'],
['integration_openproject', 'openproject_client_id'],
['integration_openproject', 'openproject_client_secret'],
['integration_openproject', 'openproject_instance_url'],
)
->willReturnOnConsecutiveCalls(
OpenProjectAPIService::AUTH_METHOD_OAUTH,
$this->clientId,
$this->clientSecret,
$this->pactMockServerConfig->getBaseUri()->__toString(),
OpenProjectAPIService::AUTH_METHOD_OAUTH,

// for second request after invalid token reply
OpenProjectAPIService::AUTH_METHOD_OAUTH,
$this->clientId,
$this->clientSecret,
$this->pactMockServerConfig->getBaseUri()->__toString()
Expand Down Expand Up @@ -1589,12 +1595,13 @@ public function testGetOpenProjectOauthURL(string $oauthInstanceUrl) {
$configMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'authorization_method'],
['integration_openproject', 'openproject_client_id'],
['integration_openproject', 'openproject_client_secret'],
['integration_openproject', 'openproject_instance_url'],
['integration_openproject', 'openproject_client_id'],
['integration_openproject', 'openproject_instance_url'],
)->willReturnOnConsecutiveCalls('clientID', 'SECRET', $oauthInstanceUrl, 'clientID', $oauthInstanceUrl);
)->willReturnOnConsecutiveCalls(OpenProjectAPIService::AUTH_METHOD_OAUTH, 'clientID', 'SECRET', $oauthInstanceUrl, 'clientID', $oauthInstanceUrl);

$url = $this->createMock(IURLGenerator::class);
$url->expects($this->once())
Expand Down Expand Up @@ -1651,10 +1658,11 @@ public function testGetOpenProjectOauthURLWithInvalidAdminConfig(
$configMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'authorization_method'],
['integration_openproject', 'openproject_client_id'],
['integration_openproject', 'openproject_client_secret'],
['integration_openproject', 'openproject_instance_url']
)->willReturnOnConsecutiveCalls($clientId, $clientSecret, $oauthInstanceUrl);
)->willReturnOnConsecutiveCalls(OpenProjectAPIService::AUTH_METHOD_OAUTH, $clientId, $clientSecret, $oauthInstanceUrl);

$this->expectException(\Exception::class);
$this->expectExceptionMessage('OpenProject admin config is not valid!');
Expand Down Expand Up @@ -2075,11 +2083,13 @@ public function testRequestConnectException(
$configMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'authorization_method'],
['integration_openproject', 'openproject_client_id'],
['integration_openproject', 'openproject_client_secret'],
['integration_openproject', 'openproject_instance_url'],
)
->willReturnOnConsecutiveCalls(
OpenProjectAPIService::AUTH_METHOD_OAUTH,
$this->clientId,
$this->clientSecret,
'http://openproject.org',
Expand Down Expand Up @@ -2146,11 +2156,13 @@ public function testRequestClientServerException(
$configMock
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'authorization_method'],
['integration_openproject', 'openproject_client_id'],
['integration_openproject', 'openproject_client_secret'],
['integration_openproject', 'openproject_instance_url'],
)
->willReturnOnConsecutiveCalls(
OpenProjectAPIService::AUTH_METHOD_OAUTH,
$this->clientId,
$this->clientSecret,
'http://openproject.org',
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/Settings/PersonalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,20 @@ public function testGetForm(
$this->config
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'authorization_method'],
['integration_openproject', 'default_enable_unified_search'],
['integration_openproject', 'default_enable_navigation'],
['integration_openproject', 'authorization_method'],
['integration_openproject', 'openproject_client_id'],
['integration_openproject', 'openproject_client_secret'],
['integration_openproject', 'openproject_instance_url'],
['integration_openproject', 'openproject_client_id'],
['integration_openproject', 'openproject_instance_url'],
)
->willReturnOnConsecutiveCalls(
OpenProjectAPIService::AUTH_METHOD_OAUTH,
'0', '0',
OpenProjectAPIService::AUTH_METHOD_OAUTH,
$clientId,
$clientSecret,
$oauthInstanceUrl,
Expand All @@ -131,6 +135,7 @@ public function testGetForm(
'search_enabled' => false,
'navigation_enabled' => false,
'admin_config_ok' => $adminConfigStatus,
'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH
]
],
['oauth-connection-result'],
Expand Down Expand Up @@ -162,16 +167,20 @@ public function testNoPersonalSettingsShouldUseValueFromTheDefaults() {
$this->config
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'authorization_method'],
['integration_openproject', 'default_enable_unified_search'],
['integration_openproject', 'default_enable_navigation'],
['integration_openproject', 'authorization_method'],
['integration_openproject', 'openproject_client_id'],
['integration_openproject', 'openproject_client_secret'],
['integration_openproject', 'openproject_instance_url'],
['integration_openproject', 'openproject_client_id'],
['integration_openproject', 'openproject_instance_url'],
)
->willReturnOnConsecutiveCalls(
OpenProjectAPIService::AUTH_METHOD_OAUTH,
'1', '1',
OpenProjectAPIService::AUTH_METHOD_OAUTH,
"some-client-id",
"some-client-secret",
"http://localhost",
Expand All @@ -188,6 +197,7 @@ public function testNoPersonalSettingsShouldUseValueFromTheDefaults() {
'search_enabled' => true,
'navigation_enabled' => true,
'admin_config_ok' => true,
'authorization_method' => OpenProjectAPIService::AUTH_METHOD_OAUTH
]
],
['oauth-connection-result'],
Expand Down

0 comments on commit f3bbd21

Please sign in to comment.