Skip to content

Commit

Permalink
init tests files for personal setting
Browse files Browse the repository at this point in the history
Signed-off-by: Parajuli Kiran <kiranparajuli589@gmail.com>
Signed-off-by: Kiran Parajuli <kiranparajuli589@gmail.com>
  • Loading branch information
kiranparajuli589 committed Mar 22, 2022
1 parent 32ff8ac commit 987fe93
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 2 deletions.
1 change: 1 addition & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

$classLoader = new ClassLoader();
$classLoader->addPsr4("OCA\\OpenProject\\Service\\", __DIR__ . '/lib/Service', true);
$classLoader->addPsr4("OCA\\OpenProject\\Settings\\", __DIR__ . '/lib/Settings', true);
$classLoader->addPsr4("OCP\\", $serverPath . '/lib/public', true);
$classLoader->addPsr4("OC\\", $serverPath . '/lib/private', true);
$classLoader->addPsr4("OCA\\Files\\Event\\", $serverPath . '/apps/files/lib/Event', true);
Expand Down
18 changes: 16 additions & 2 deletions tests/lib/Service/OpenProjectAPIServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,22 @@ public function getOpenProjectOauthURLDataProvider() {
[
'clientId',
'clientSecret',
'openproject', // invalid oauth instance url
],
[
'clientId',
'clientSecret',
'', // empty oauth instance url
],
[
'clientId',
'', // empty client secret
'https://openproject',
],
[
'', // empty client id
'clientSecret',
'https://openproject',

],
];
}
Expand All @@ -873,7 +887,7 @@ public function testGetOpenProjectOauthURLWithInvalidAdminConfig(
->withConsecutive(
['integration_openproject', 'client_id'],
['integration_openproject', 'client_secret'],
['integration_openproject', 'oauth_instance_url'],
['integration_openproject', 'oauth_instance_url']
)->willReturnOnConsecutiveCalls($clientId, $clientSecret, $oauthInstanceUrl);

$this->expectException(\Exception::class);
Expand Down
140 changes: 140 additions & 0 deletions tests/lib/Settings/PersonalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php
/**
* Nextcloud - OpenProject
*
*
* @author Kiran Parajuli <kiran@jankaritech.com>
* @copyright Kiran Parajuli 2022
*/

namespace OCA\OpenProject\Settings;

use OCP\AppFramework\Services\IInitialState;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IURLGenerator;
use PHPUnit\Framework\TestCase;

class PersonalTest extends TestCase {
/**
* @var Personal
*/
private $setting;

/**
* @var IConfig
*/
private $config;

/**
* @var IInitialState
*/
private $initialState;

/**
* @var IURLGenerator
*/
private $url;

protected function setUp(): void {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
$this->initialState = $this->createMock(IInitialState::class);
$this->url = $this->createMock(IURLGenerator::class);
$this->setting = new Personal($this->config, $this->initialState, $this->url, "testUser");
}

/**
* @return array<mixed>
*/
public function dataTestGetForm(): array {
return [
[
"clientId" => 'some-client-id',
"clientSecret" => 'some-client-secret',
"oauthInstanceUrl" => 'http://some.url',
"expectedRequestUrl" => 'http://some.url/'
. 'oauth/authorize'
. '?client_id=' . 'some-client-id'
.'&redirect_uri=' . urlencode('http://redirect.url/test/')
. '&response_type=code',
],
[
"clientId" => 'some-client-id',
"clientSecret" => '',
"oauthInstanceUrl" => 'http://some.url',
"expectedRequestUrl" => '',
],
[
"clientId" => 'some-client-id',
"clientSecret" => 'some-secret',
"oauthInstanceUrl" => 'http:/',
"expectedRequestUrl" => '',
],
];
}

/**
* @dataProvider dataTestGetForm
*
* @param string $clientId
* @param string $clientSecret
* @param string $oauthInstanceUrl
* @param string $expectedRequestUrl
* @return void
*/
public function testGetForm(
string $clientId, string $clientSecret, string $oauthInstanceUrl, string $expectedRequestUrl
) {
$this->config
->method('getUserValue')
->withConsecutive(
['testUser', 'integration_openproject', 'token'],
['testUser', 'integration_openproject', 'user_name'],
['testUser', 'integration_openproject', 'search_enabled', '0'],
['testUser', 'integration_openproject', 'notification_enabled', '0'],
['testUser', 'integration_openproject', 'navigation_enabled', '0'],
)
->willReturnOnConsecutiveCalls(
'some-token',
'some-username',
'0', '0', '0'
);
$this->config
->method('getAppValue')
->withConsecutive(
['integration_openproject', 'client_id'],
['integration_openproject', 'client_secret'],
['integration_openproject', 'oauth_instance_url'],
['integration_openproject', 'client_id'],
['integration_openproject', 'oauth_instance_url'],
)
->willReturnOnConsecutiveCalls(
$clientId,
$clientSecret,
$oauthInstanceUrl,
$clientId,
$oauthInstanceUrl,
);

$this->url
->method('linkToRouteAbsolute')
->with('integration_openproject.config.oauthRedirect')
->willReturn('http://redirect.url/test/');

$this->initialState
->method('provideInitialState')
->with('user-config', [
'token' => 'some-token',
'user_name' => 'some-username',
'search_enabled' => false,
'notification_enabled' => false,
'navigation_enabled' => false,
'request_url' => $expectedRequestUrl === '' ? false : $expectedRequestUrl,
]);

$form = $this->setting->getForm();
$expected = new TemplateResponse('integration_openproject', 'personalSettings');
$this->assertEquals($expected, $form);
}
}

0 comments on commit 987fe93

Please sign in to comment.