-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init tests files for personal setting
Signed-off-by: Parajuli Kiran <kiranparajuli589@gmail.com> Signed-off-by: Kiran Parajuli <kiranparajuli589@gmail.com>
- Loading branch information
1 parent
32ff8ac
commit 987fe93
Showing
3 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |