mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Implemented desktop application type
This commit is contained in:
@@ -7,7 +7,7 @@ use api\modules\oauth\models\BaseOauthClientType;
|
||||
use api\tests\unit\TestCase;
|
||||
use common\models\OauthClient;
|
||||
|
||||
class BaseOauthClientTypeTest extends TestCase {
|
||||
final class BaseOauthClientTypeTest extends TestCase {
|
||||
|
||||
public function testApplyTyClient(): void {
|
||||
$client = new OauthClient();
|
||||
|
@@ -1,11 +1,13 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace api\tests\unit\modules\oauth\models;
|
||||
|
||||
use api\modules\oauth\models\MinecraftServerType;
|
||||
use api\tests\unit\TestCase;
|
||||
use common\models\OauthClient;
|
||||
|
||||
class MinecraftServerTypeTest extends TestCase {
|
||||
final class MinecraftServerTypeTest extends TestCase {
|
||||
|
||||
public function testApplyToClient(): void {
|
||||
$model = new MinecraftServerType();
|
||||
|
@@ -4,29 +4,46 @@ declare(strict_types=1);
|
||||
namespace api\tests\unit\modules\oauth\models;
|
||||
|
||||
use api\modules\oauth\exceptions\UnsupportedOauthClientType;
|
||||
use api\modules\oauth\models\ApplicationType;
|
||||
use api\modules\oauth\models\DesktopApplicationType;
|
||||
use api\modules\oauth\models\MinecraftServerType;
|
||||
use api\modules\oauth\models\OauthClientFormFactory;
|
||||
use api\modules\oauth\models\WebApplicationType;
|
||||
use api\tests\unit\TestCase;
|
||||
use common\models\OauthClient;
|
||||
|
||||
class OauthClientFormFactoryTest extends TestCase {
|
||||
final class OauthClientFormFactoryTest extends TestCase {
|
||||
|
||||
public function testCreate(): void {
|
||||
public function testCreateWebApplication(): void {
|
||||
$client = new OauthClient();
|
||||
$client->type = OauthClient::TYPE_APPLICATION;
|
||||
$client->type = OauthClient::TYPE_WEB_APPLICATION;
|
||||
$client->name = 'Application name';
|
||||
$client->description = 'Application description.';
|
||||
$client->website_url = 'http://example.com';
|
||||
$client->redirect_uri = 'http://example.com/oauth/ely';
|
||||
/** @var ApplicationType $requestForm */
|
||||
/** @var WebApplicationType $requestForm */
|
||||
$requestForm = OauthClientFormFactory::create($client);
|
||||
$this->assertInstanceOf(ApplicationType::class, $requestForm);
|
||||
$this->assertInstanceOf(WebApplicationType::class, $requestForm);
|
||||
$this->assertSame('Application name', $requestForm->name);
|
||||
$this->assertSame('Application description.', $requestForm->description);
|
||||
$this->assertSame('http://example.com', $requestForm->websiteUrl);
|
||||
$this->assertSame('http://example.com/oauth/ely', $requestForm->redirectUri);
|
||||
}
|
||||
|
||||
public function testCreateDesktopApplication(): void {
|
||||
$client = new OauthClient();
|
||||
$client->type = OauthClient::TYPE_DESKTOP_APPLICATION;
|
||||
$client->name = 'Application name';
|
||||
$client->description = 'Application description.';
|
||||
$client->website_url = 'http://example.com';
|
||||
/** @var \api\modules\oauth\models\DesktopApplicationType $requestForm */
|
||||
$requestForm = OauthClientFormFactory::create($client);
|
||||
$this->assertInstanceOf(DesktopApplicationType::class, $requestForm);
|
||||
$this->assertSame('Application name', $requestForm->name);
|
||||
$this->assertSame('Application description.', $requestForm->description);
|
||||
$this->assertSame('http://example.com', $requestForm->websiteUrl);
|
||||
}
|
||||
|
||||
public function testCreateMinecraftServer(): void {
|
||||
$client = new OauthClient();
|
||||
$client->type = OauthClient::TYPE_MINECRAFT_SERVER;
|
||||
$client->name = 'Server name';
|
||||
@@ -44,7 +61,7 @@ class OauthClientFormFactoryTest extends TestCase {
|
||||
$this->expectException(UnsupportedOauthClientType::class);
|
||||
|
||||
$client = new OauthClient();
|
||||
$client->type = 'unknown-type';
|
||||
$client->type = 'unknown-type'; // @phpstan-ignore assign.propertyType (its alright for tests)
|
||||
OauthClientFormFactory::create($client);
|
||||
}
|
||||
|
||||
|
@@ -9,13 +9,13 @@ use api\tests\unit\TestCase;
|
||||
use common\models\OauthClient;
|
||||
use common\tasks\ClearOauthSessions;
|
||||
|
||||
class OauthClientFormTest extends TestCase {
|
||||
final class OauthClientFormTest extends TestCase {
|
||||
|
||||
public function testSave(): void {
|
||||
$client = $this->createPartialMock(OauthClient::class, ['save']);
|
||||
$client->method('save')->willReturn(true);
|
||||
$client->account_id = 1;
|
||||
$client->type = OauthClient::TYPE_APPLICATION;
|
||||
$client->type = OauthClient::TYPE_WEB_APPLICATION;
|
||||
$client->name = 'Test application';
|
||||
|
||||
$form = $this->createPartialMock(OauthClientForm::class, ['getClient', 'isClientExists']);
|
||||
@@ -39,7 +39,7 @@ class OauthClientFormTest extends TestCase {
|
||||
$client->id = 'application-id';
|
||||
$client->secret = 'application_secret';
|
||||
$client->account_id = 1;
|
||||
$client->type = OauthClient::TYPE_APPLICATION;
|
||||
$client->type = OauthClient::TYPE_WEB_APPLICATION;
|
||||
$client->name = 'Application name';
|
||||
$client->description = 'Application description';
|
||||
$client->redirect_uri = 'http://example.com/oauth/ely';
|
||||
@@ -81,7 +81,7 @@ class OauthClientFormTest extends TestCase {
|
||||
$client = $this->createPartialMock(OauthClient::class, ['save']);
|
||||
$client->method('save')->willReturn(true);
|
||||
$client->id = 'mocked-id';
|
||||
$client->type = OauthClient::TYPE_APPLICATION;
|
||||
$client->type = OauthClient::TYPE_WEB_APPLICATION;
|
||||
|
||||
$form = new OauthClientForm($client);
|
||||
$this->assertTrue($form->delete());
|
||||
@@ -98,7 +98,7 @@ class OauthClientFormTest extends TestCase {
|
||||
$client->method('save')->willReturn(true);
|
||||
$client->id = 'mocked-id';
|
||||
$client->secret = 'initial_secret';
|
||||
$client->type = OauthClient::TYPE_APPLICATION;
|
||||
$client->type = OauthClient::TYPE_WEB_APPLICATION;
|
||||
|
||||
$form = new OauthClientForm($client);
|
||||
$this->assertTrue($form->reset());
|
||||
@@ -115,7 +115,7 @@ class OauthClientFormTest extends TestCase {
|
||||
$client->method('save')->willReturn(true);
|
||||
$client->id = 'mocked-id';
|
||||
$client->secret = 'initial_secret';
|
||||
$client->type = OauthClient::TYPE_APPLICATION;
|
||||
$client->type = OauthClient::TYPE_WEB_APPLICATION;
|
||||
|
||||
$form = new OauthClientForm($client);
|
||||
$this->assertTrue($form->reset(true));
|
||||
|
@@ -1,14 +1,16 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace api\tests\unit\modules\oauth\models;
|
||||
|
||||
use api\modules\oauth\models\ApplicationType;
|
||||
use api\modules\oauth\models\WebApplicationType;
|
||||
use api\tests\unit\TestCase;
|
||||
use common\models\OauthClient;
|
||||
|
||||
class ApplicationTypeTest extends TestCase {
|
||||
final class WebApplicationTypeTest extends TestCase {
|
||||
|
||||
public function testApplyToClient(): void {
|
||||
$model = new ApplicationType();
|
||||
$model = new WebApplicationType();
|
||||
$model->name = 'Application name';
|
||||
$model->websiteUrl = 'http://example.com';
|
||||
$model->redirectUri = 'http://example.com/oauth/ely';
|
Reference in New Issue
Block a user