Fix tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
976f478a98
commit
b6182489be
|
@ -26,6 +26,7 @@ use OCA\OAuth2\Controller\SettingsController;
|
||||||
use OCA\OAuth2\Db\AccessTokenMapper;
|
use OCA\OAuth2\Db\AccessTokenMapper;
|
||||||
use OCA\OAuth2\Db\Client;
|
use OCA\OAuth2\Db\Client;
|
||||||
use OCA\OAuth2\Db\ClientMapper;
|
use OCA\OAuth2\Db\ClientMapper;
|
||||||
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
use OCP\AppFramework\Http\RedirectResponse;
|
use OCP\AppFramework\Http\RedirectResponse;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
|
@ -90,27 +91,39 @@ class SettingsControllerTest extends TestCase {
|
||||||
$this->clientMapper
|
$this->clientMapper
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('insert')
|
->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
|
$result = $this->settingsController->addClient('My Client Name', 'https://example.com/');
|
||||||
->expects($this->once())
|
$this->assertInstanceOf(JSONResponse::class, $result);
|
||||||
->method('getAbsoluteURL')
|
|
||||||
->with('/index.php/settings/admin/security')
|
|
||||||
->willReturn('https://example.com/index.php/settings/admin/security');
|
|
||||||
|
|
||||||
$expected = new RedirectResponse('https://example.com/index.php/settings/admin/security');
|
$data = $result->getData();
|
||||||
$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() {
|
public function testDeleteClient() {
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
|
$client->setId(123);
|
||||||
$client->setName('My Client Name');
|
$client->setName('My Client Name');
|
||||||
$client->setRedirectUri('https://example.com/');
|
$client->setRedirectUri('https://example.com/');
|
||||||
$client->setSecret('MySecret');
|
$client->setSecret('MySecret');
|
||||||
$client->setClientIdentifier('MyClientIdentifier');
|
$client->setClientIdentifier('MyClientIdentifier');
|
||||||
|
|
||||||
$this->clientMapper
|
$this->clientMapper
|
||||||
->expects($this->at(0))
|
|
||||||
->method('getByUid')
|
->method('getByUid')
|
||||||
->with(123)
|
->with(123)
|
||||||
->willReturn($client);
|
->willReturn($client);
|
||||||
|
@ -123,17 +136,52 @@ class SettingsControllerTest extends TestCase {
|
||||||
->method('deleteByName')
|
->method('deleteByName')
|
||||||
->with('My Client Name');
|
->with('My Client Name');
|
||||||
$this->clientMapper
|
$this->clientMapper
|
||||||
->expects($this->at(1))
|
|
||||||
->method('delete')
|
->method('delete')
|
||||||
->with($client);
|
->with($client);
|
||||||
|
|
||||||
$this->urlGenerator
|
$result = $this->settingsController->deleteClient(123);
|
||||||
->expects($this->once())
|
$this->assertInstanceOf(JSONResponse::class, $result);
|
||||||
->method('getAbsoluteURL')
|
$this->assertEquals([], $result->getData());
|
||||||
->with('/index.php/settings/admin/security')
|
}
|
||||||
->willReturn('https://example.com/index.php/settings/admin/security');
|
|
||||||
|
|
||||||
$expected = new RedirectResponse('https://example.com/index.php/settings/admin/security');
|
public function testGetClients() {
|
||||||
$this->assertEquals($expected, $this->settingsController->deleteClient(123));
|
$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();
|
||||||
|
|
||||||
|
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue