Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-06-13 22:24:06 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2018-06-19 12:42:41 +0300
commitb6182489be8cc0820b3138e25afda912b9a98d9f (patch)
tree310a38048cc1132ceb6367ad767aef413931f413 /apps/oauth2/tests
parent976f478a9887226820ba0fb452afc01f0e668d32 (diff)
Fix tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/oauth2/tests')
-rw-r--r--apps/oauth2/tests/Controller/SettingsControllerTest.php82
1 files changed, 65 insertions, 17 deletions
diff --git a/apps/oauth2/tests/Controller/SettingsControllerTest.php b/apps/oauth2/tests/Controller/SettingsControllerTest.php
index a6c036949ed..b0c6035cddb 100644
--- a/apps/oauth2/tests/Controller/SettingsControllerTest.php
+++ b/apps/oauth2/tests/Controller/SettingsControllerTest.php
@@ -26,6 +26,7 @@ use OCA\OAuth2\Controller\SettingsController;
use OCA\OAuth2\Db\AccessTokenMapper;
use OCA\OAuth2\Db\Client;
use OCA\OAuth2\Db\ClientMapper;
+use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\IRequest;
use OCP\IURLGenerator;
@@ -90,27 +91,39 @@ class SettingsControllerTest extends TestCase {
$this->clientMapper
->expects($this->once())
->method('insert')
- ->with($client);
+ ->with($this->callback(function (Client $c) {
+ return $c->getName() === 'My Client Name' &&
+ $c->getRedirectUri() === 'https://example.com/' &&
+ $c->getSecret() === 'MySecret' &&
+ $c->getClientIdentifier() === 'MyClientIdentifier';
+ }))->will($this->returnCallback(function (Client $c) {
+ $c->setId(42);
+ return $c;
+ }));
- $this->urlGenerator
- ->expects($this->once())
- ->method('getAbsoluteURL')
- ->with('/index.php/settings/admin/security')
- ->willReturn('https://example.com/index.php/settings/admin/security');
+ $result = $this->settingsController->addClient('My Client Name', 'https://example.com/');
+ $this->assertInstanceOf(JSONResponse::class, $result);
+
+ $data = $result->getData();
- $expected = new RedirectResponse('https://example.com/index.php/settings/admin/security');
- $this->assertEquals($expected, $this->settingsController->addClient('My Client Name', 'https://example.com/'));
+ $this->assertEquals([
+ 'id' => 42,
+ 'name' => 'My Client Name',
+ 'redirectUri' => 'https://example.com/',
+ 'clientId' => 'MyClientIdentifier',
+ 'clientSecret' => 'MySecret',
+ ], $data);
}
public function testDeleteClient() {
$client = new Client();
+ $client->setId(123);
$client->setName('My Client Name');
$client->setRedirectUri('https://example.com/');
$client->setSecret('MySecret');
$client->setClientIdentifier('MyClientIdentifier');
$this->clientMapper
- ->expects($this->at(0))
->method('getByUid')
->with(123)
->willReturn($client);
@@ -123,17 +136,52 @@ class SettingsControllerTest extends TestCase {
->method('deleteByName')
->with('My Client Name');
$this->clientMapper
- ->expects($this->at(1))
->method('delete')
->with($client);
- $this->urlGenerator
- ->expects($this->once())
- ->method('getAbsoluteURL')
- ->with('/index.php/settings/admin/security')
- ->willReturn('https://example.com/index.php/settings/admin/security');
+ $result = $this->settingsController->deleteClient(123);
+ $this->assertInstanceOf(JSONResponse::class, $result);
+ $this->assertEquals([], $result->getData());
+ }
+
+ public function testGetClients() {
+ $client1 = new Client();
+ $client1->setId(123);
+ $client1->setName('My Client Name');
+ $client1->setRedirectUri('https://example.com/');
+ $client1->setSecret('MySecret');
+ $client1->setClientIdentifier('MyClientIdentifier');
+
+ $client2 = new Client();
+ $client2->setId(42);
+ $client2->setName('My Client Name2');
+ $client2->setRedirectUri('https://example.com/2');
+ $client2->setSecret('MySecret2');
+ $client2->setClientIdentifier('MyClientIdentifier2');
+
+ $this->clientMapper->method('getClients')
+ ->willReturn([$client1, $client2]);
+
+ $result = $this->settingsController->getClients();
+ $this->assertInstanceOf(JSONResponse::class, $result);
+
+ $data = $result->getData();
- $expected = new RedirectResponse('https://example.com/index.php/settings/admin/security');
- $this->assertEquals($expected, $this->settingsController->deleteClient(123));
+ $this->assertSame([
+ [
+ 'id' => 123,
+ 'name' => 'My Client Name',
+ 'redirectUri' => 'https://example.com/',
+ 'clientId' => 'MyClientIdentifier',
+ 'clientSecret' => 'MySecret',
+ ],
+ [
+ 'id' => 42,
+ 'name' => 'My Client Name2',
+ 'redirectUri' => 'https://example.com/2',
+ 'clientId' => 'MyClientIdentifier2',
+ 'clientSecret' => 'MySecret2',
+ ],
+ ], $data);
}
}