mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
Updated with new entity names
This commit is contained in:
@@ -10,7 +10,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
public function testSetGet()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$client = new Client($server);
|
||||
$client = new ClientEntity($server);
|
||||
$client->setId('foobar');
|
||||
$client->setSecret('barfoo');
|
||||
$client->setName('Test Client');
|
||||
|
@@ -14,58 +14,69 @@ class RefreshTokenTests extends \PHPUnit_Framework_TestCase
|
||||
function testSetAccessToken()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$entity = new RefreshToken($server);
|
||||
$entity->setAccessToken((new AccessToken($server)));
|
||||
$entity = new RefreshTokenEntity($server);
|
||||
$entity->setAccessToken((new AccessTokenEntity($server)));
|
||||
|
||||
$reflector = new \ReflectionClass($entity);
|
||||
$accessTokenProperty = $reflector->getProperty('accessToken');
|
||||
$accessTokenProperty->setAccessible(true);
|
||||
|
||||
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessToken);
|
||||
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessTokenEntity);
|
||||
}
|
||||
|
||||
function testSave()
|
||||
{
|
||||
$server = new Authorization();
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$server->shouldReceive('setAccessTokenStorage');
|
||||
$server->shouldReceive('setRefreshTokenStorage');
|
||||
|
||||
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
||||
$refreshTokenStorage->shouldReceive('create');
|
||||
$refreshTokenStorage->shouldReceive('setServer');
|
||||
$refreshTokenStorage->shouldReceive('associateScope');
|
||||
|
||||
$server->shouldReceive('getStorage')->with('refresh_token')->andReturn($refreshTokenStorage);
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
||||
(new AccessToken($server))->setToken('foobar')
|
||||
(new AccessTokenEntity($server))->setToken('foobar')
|
||||
);
|
||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
|
||||
(new Session($server))
|
||||
(new SessionEntity($server))
|
||||
);
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
|
||||
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||
|
||||
$server->setAccessTokenStorage($accessTokenStorage);
|
||||
$server->setRefreshTokenStorage($refreshTokenStorage);
|
||||
|
||||
$entity = new RefreshToken($server);
|
||||
$entity = new RefreshTokenEntity($server);
|
||||
$this->assertSame(null, $entity->save());
|
||||
}
|
||||
|
||||
function testExpire()
|
||||
{
|
||||
$server = new Authorization();
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$server->shouldReceive('setRefreshTokenStorage');
|
||||
|
||||
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
|
||||
$refreshTokenStorage->shouldReceive('delete');
|
||||
$refreshTokenStorage->shouldReceive('setServer');
|
||||
|
||||
$server->shouldReceive('getStorage')->with('refresh_token')->andReturn($refreshTokenStorage);
|
||||
|
||||
$server->setRefreshTokenStorage($refreshTokenStorage);
|
||||
|
||||
$entity = new RefreshToken($server);
|
||||
$entity = new RefreshTokenEntity($server);
|
||||
$this->assertSame($entity->expire(), null);
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ class ScopeTests extends \PHPUnit_Framework_TestCase
|
||||
public function testSetGet()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$scope = new Scope($server);
|
||||
$scope = new ScopeEntity($server);
|
||||
$scope->setId('foobar');
|
||||
$scope->setDescription('barfoo');
|
||||
|
||||
|
@@ -8,7 +8,7 @@ use League\OAuth2\Server\Entity\ClientEntity;
|
||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||
use League\OAuth2\Server\Entity\SessionEntity;
|
||||
use League\OAuth2\Server\Entity\ScopeEntity;
|
||||
use League\OAuth2\Server\AuthorizationServer as Authorization;
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use \Mockery as M;
|
||||
|
||||
class SessionTests extends \PHPUnit_Framework_TestCase
|
||||
@@ -16,19 +16,19 @@ class SessionTests extends \PHPUnit_Framework_TestCase
|
||||
public function testSetGet()
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
$entity = new Session($server);
|
||||
$entity = new SessionEntity($server);
|
||||
$entity->setId('foobar');
|
||||
$entity->setOwner('user', 123);
|
||||
$entity->associateAccessToken((new AccessToken($server)));
|
||||
$entity->associateRefreshToken((new RefreshToken($server)));
|
||||
$entity->associateClient((new Client($server)));
|
||||
$entity->associateScope((new Scope($server))->setId('foo'));
|
||||
$entity->associateAccessToken((new AccessTokenEntity($server)));
|
||||
$entity->associateRefreshToken((new RefreshTokenEntity($server)));
|
||||
$entity->associateClient((new ClientEntity($server)));
|
||||
$entity->associateScope((new ScopeEntity($server))->setId('foo'));
|
||||
// $entity->associateAuthCode((new AuthCode($server)));
|
||||
|
||||
$this->assertEquals('foobar', $entity->getId());
|
||||
$this->assertEquals('user', $entity->getOwnerType());
|
||||
$this->assertEquals(123, $entity->getOwnerId());
|
||||
$this->assertTrue($entity->getClient() instanceof Client);
|
||||
$this->assertTrue($entity->getClient() instanceof ClientEntity);
|
||||
$this->assertTrue($entity->hasScope('foo'));
|
||||
|
||||
$reflector = new \ReflectionClass($entity);
|
||||
@@ -37,8 +37,8 @@ class SessionTests extends \PHPUnit_Framework_TestCase
|
||||
$refreshTokenProperty = $reflector->getProperty('refreshToken');
|
||||
$refreshTokenProperty->setAccessible(true);
|
||||
|
||||
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessToken);
|
||||
$this->assertTrue($refreshTokenProperty->getValue($entity) instanceof RefreshToken);
|
||||
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessTokenEntity);
|
||||
$this->assertTrue($refreshTokenProperty->getValue($entity) instanceof RefreshTokenEntity);
|
||||
// $this->assertTrue($reader($entity, 'authCode') instanceof AuthCode);
|
||||
}
|
||||
|
||||
@@ -46,32 +46,36 @@ class SessionTests extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||
|
||||
$entity = new Session($server);
|
||||
$reflectedEntity = new \ReflectionClass('League\OAuth2\Server\Entity\Session');
|
||||
$entity = new SessionEntity($server);
|
||||
$reflectedEntity = new \ReflectionClass('League\OAuth2\Server\Entity\SessionEntity');
|
||||
$method = $reflectedEntity->getMethod('formatScopes');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$scopes = [
|
||||
(new Scope($server))->setId('scope1')->setDescription('foo'),
|
||||
(new Scope($server))->setId('scope2')->setDescription('bar')
|
||||
(new ScopeEntity($server))->setId('scope1')->setDescription('foo'),
|
||||
(new ScopeEntity($server))->setId('scope2')->setDescription('bar')
|
||||
];
|
||||
|
||||
$result = $method->invokeArgs($entity, [$scopes]);
|
||||
|
||||
$this->assertTrue(isset($result['scope1']));
|
||||
$this->assertTrue(isset($result['scope2']));
|
||||
$this->assertTrue($result['scope1'] instanceof Scope);
|
||||
$this->assertTrue($result['scope2'] instanceof Scope);
|
||||
$this->assertTrue($result['scope1'] instanceof ScopeEntity);
|
||||
$this->assertTrue($result['scope2'] instanceof ScopeEntity);
|
||||
}
|
||||
|
||||
public function testGetScopes()
|
||||
{
|
||||
$server = new Authorization();
|
||||
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
|
||||
$server->shouldReceive('setAccessTokenStorage');
|
||||
$server->shouldReceive('setSessionStorage');
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$server->setAccessTokenStorage($accessTokenStorage);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('getScopes')->andReturn(
|
||||
[]
|
||||
@@ -79,18 +83,24 @@ class SessionTests extends \PHPUnit_Framework_TestCase
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$server->setSessionStorage($sessionStorage);
|
||||
|
||||
$entity = new Session($server);
|
||||
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||
|
||||
$entity = new SessionEntity($server);
|
||||
$this->assertEquals($entity->getScopes(), []);
|
||||
}
|
||||
|
||||
public function testHasScopes()
|
||||
{
|
||||
$server = new Authorization();
|
||||
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
|
||||
$server->shouldReceive('setAccessTokenStorage');
|
||||
$server->shouldReceive('setSessionStorage');
|
||||
|
||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||
$accessTokenStorage->shouldReceive('setServer');
|
||||
$server->setAccessTokenStorage($accessTokenStorage);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('getScopes')->andReturn(
|
||||
[]
|
||||
@@ -98,32 +108,40 @@ class SessionTests extends \PHPUnit_Framework_TestCase
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$server->setSessionStorage($sessionStorage);
|
||||
|
||||
$entity = new Session($server);
|
||||
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||
|
||||
$entity = new SessionEntity($server);
|
||||
$this->assertFalse($entity->hasScope('foo'));
|
||||
}
|
||||
|
||||
function testSave()
|
||||
{
|
||||
$server = new Authorization();
|
||||
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
|
||||
$server->shouldReceive('setSessionStorage');
|
||||
$server->shouldReceive('setClientStorage');
|
||||
|
||||
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
|
||||
$sessionStorage->shouldReceive('create');
|
||||
$sessionStorage->shouldReceive('associateScope');
|
||||
$sessionStorage->shouldReceive('setServer');
|
||||
$sessionStorage->shouldReceive('getScopes')->andReturn([
|
||||
(new Scope($server))->setId('foo')
|
||||
(new ScopeEntity($server))->setId('foo')
|
||||
]);
|
||||
|
||||
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
|
||||
|
||||
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
|
||||
$clientStorage->shouldReceive('getBySession')->andReturn(
|
||||
(new Client($server))->setId('foo')
|
||||
(new ClientEntity($server))->setId('foo')
|
||||
);
|
||||
$clientStorage->shouldReceive('setServer');
|
||||
|
||||
$server->shouldReceive('getStorage')->with('client')->andReturn($clientStorage);
|
||||
|
||||
$server->setSessionStorage($sessionStorage);
|
||||
$server->setClientStorage($clientStorage);
|
||||
|
||||
$entity = new Session($server);
|
||||
$entity = new SessionEntity($server);
|
||||
$this->assertEquals(null, $entity->save());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user