Renamed test classes

This commit is contained in:
Alex Bilbie
2014-05-02 15:12:15 +01:00
parent bdd2bc322c
commit 5206d77167
7 changed files with 94 additions and 74 deletions

View File

@@ -0,0 +1,106 @@
<?php
namespace LeagueTests\Entity;
use LeagueTests\Stubs\StubAbstractTokenEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\AuthorizationServer;
use \Mockery as M;
class AbstractTokenTests extends \PHPUnit_Framework_TestCase
{
public function testSetGet()
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
$time = time();
$entity = new StubAbstractTokenEntity($server);
$entity->setToken('foobar');
$entity->setExpireTime($time);
$entity->setSession((new SessionEntity($server)));
$entity->associateScope((new ScopeEntity($server))->setId('foo'));
$this->assertEquals('foobar', $entity->getToken());
$this->assertEquals($time, $entity->getExpireTime());
// $this->assertTrue($entity->getSession() instanceof SessionEntity);
// $this->assertTrue($entity->hasScope('foo'));
// $result = $entity->getScopes();
// $this->assertTrue(isset($result['foo']));
}
/*public function testGetSession()
{
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
$server->shouldReceive('setSessionStorage');
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
(new SessionEntity($server))
);
$sessionStorage->shouldReceive('setServer');
$server->shouldReceive('getStorage')->andReturn($sessionStorage);
$server->setSessionStorage($sessionStorage);
$entity = new StubAbstractTokenEntity($server);
$this->assertTrue($entity->getSession() instanceof SessionEntity);
}*/
/*public function testGetScopes()
{
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
$server->shouldReceive('setAccessTokenStorage');
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('getScopes')->andReturn(
[]
);
$accessTokenStorage->shouldReceive('setServer');
$server->setAccessTokenStorage($accessTokenStorage);
$entity = new StubAbstractTokenEntity($server);
$this->assertEquals($entity->getScopes(), []);
}*/
/*public function testHasScopes()
{
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('getScopes')->andReturn(
[]
);
$accessTokenStorage->shouldReceive('setServer');
$server->setAccessTokenStorage($accessTokenStorage);
$entity = new StubAbstractTokenEntity($server);
$this->assertFalse($entity->hasScope('foo'));
}*/
public function testFormatScopes()
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
$entity = new StubAbstractTokenEntity($server);
$reflectedEntity = new \ReflectionClass('LeagueTests\Stubs\StubAbstractTokenEntity');
$method = $reflectedEntity->getMethod('formatScopes');
$method->setAccessible(true);
$scopes = [
(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 ScopeEntity);
$this->assertTrue($result['scope2'] instanceof ScopeEntity);
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace LeagueTests\Entity;
use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\AuthorizationServer;
use \Mockery as M;
class AccessTokenTests extends \PHPUnit_Framework_TestCase
{
function testSave()
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
$server->shouldReceive('setAccessTokenStorage');
$server->shouldReceive('setSessionStorage');
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('create');
$accessTokenStorage->shouldReceive('associateScope');
$accessTokenStorage->shouldReceive('setServer');
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
(new ScopeEntity($server))->setId('foo')
]);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
(new SessionEntity($server))
);
$sessionStorage->shouldReceive('setServer');
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
$server->setAccessTokenStorage($accessTokenStorage);
$server->setSessionStorage($sessionStorage);
$entity = new AccessTokenEntity($server);
$this->assertTrue($entity->save() instanceof AccessTokenEntity);
}
function testExpire()
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
$server->shouldReceive('setAccessTokenStorage');
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('delete');
$accessTokenStorage->shouldReceive('setServer');
$server->shouldReceive('getStorage')->with('access_token')->andReturn($accessTokenStorage);
$server->setAccessTokenStorage($accessTokenStorage);
$entity = new AccessTokenEntity($server);
$this->assertSame($entity->expire(), null);
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace LeagueTests\Entity;
use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Entity\AuthCodeEntity;
use League\OAuth2\Server\AuthorizationServer;
use \Mockery as M;
class AuthCodeTest extends \PHPUnit_Framework_TestCase
{
function testSetGet()
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
$session = M::mock('League\OAuth2\Server\Entity\SessionEntity');
$code = new AuthCodeEntity($server);
$code->setRedirectUri('http://foo/bar');
$code->setToken('foobar');
$code->setSession($session);
$this->assertEquals('http://foo/bar', $code->getRedirectUri());
$this->assertEquals('http://foo/bar?code=foobar', $code->generateRedirectUri());
$this->assertTrue($code->getSession() instanceof \League\OAuth2\Server\Entity\SessionEntity);
}
function testSave()
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
$server->shouldReceive('setAuthCodeStorage');
$server->shouldReceive('setSessionStorage');
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
$authCodeStorage->shouldReceive('create');
$authCodeStorage->shouldReceive('associateScope');
$authCodeStorage->shouldReceive('setServer');
$authCodeStorage->shouldReceive('getScopes')->andReturn([
(new ScopeEntity($server))->setId('foo')
]);
$server->shouldReceive('getStorage')->with('auth_code')->andReturn($authCodeStorage);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('getByAuthCode')->andReturn(
(new SessionEntity($server))
);
$sessionStorage->shouldReceive('setServer');
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
$server->setAuthCodeStorage($authCodeStorage);
$server->setSessionStorage($sessionStorage);
$entity = new AuthCodeEntity($server);
$this->assertTrue($entity->save() instanceof AuthCodeEntity);
}
function testExpire()
{
$server = new AuthorizationServer();
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
$authCodeStorage->shouldReceive('delete');
$authCodeStorage->shouldReceive('setServer');
$server->setAuthCodeStorage($authCodeStorage);
$entity = new AuthCodeEntity($server);
$this->assertSame($entity->expire(), null);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace LeagueTests\Entity;
use League\OAuth2\Server\Entity\ClientEntity;
use \Mockery as M;
class ClientTest extends \PHPUnit_Framework_TestCase
{
public function testSetGet()
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
$client = new Client($server);
$client->setId('foobar');
$client->setSecret('barfoo');
$client->setName('Test Client');
$client->setRedirectUri('http://foo/bar');
$this->assertEquals('foobar', $client->getId());
$this->assertEquals('barfoo', $client->getSecret());
$this->assertEquals('Test Client', $client->getName());
$this->assertEquals('http://foo/bar', $client->getRedirectUri());
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace LeagueTests\Entity;
use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
use League\OAuth2\Server\AuthorizationServer as Authorization;
use \Mockery as M;
class RefreshTokenTests extends \PHPUnit_Framework_TestCase
{
function testSetAccessToken()
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
$entity = new RefreshToken($server);
$entity->setAccessToken((new AccessToken($server)));
$reflector = new \ReflectionClass($entity);
$accessTokenProperty = $reflector->getProperty('accessToken');
$accessTokenProperty->setAccessible(true);
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessToken);
}
function testSave()
{
$server = new Authorization();
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
$refreshTokenStorage->shouldReceive('create');
$refreshTokenStorage->shouldReceive('setServer');
$refreshTokenStorage->shouldReceive('associateScope');
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('setServer');
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
(new AccessToken($server))->setToken('foobar')
);
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
(new Scope($server))->setId('foo')
]);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
(new Session($server))
);
$sessionStorage->shouldReceive('setServer');
$server->setAccessTokenStorage($accessTokenStorage);
$server->setRefreshTokenStorage($refreshTokenStorage);
$entity = new RefreshToken($server);
$this->assertSame(null, $entity->save());
}
function testExpire()
{
$server = new Authorization();
$refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface');
$refreshTokenStorage->shouldReceive('delete');
$refreshTokenStorage->shouldReceive('setServer');
$server->setRefreshTokenStorage($refreshTokenStorage);
$entity = new RefreshToken($server);
$this->assertSame($entity->expire(), null);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace LeagueTests\Entity;
use League\OAuth2\Server\Entity\ScopeEntity;
use \Mockery as M;
class ScopeTests extends \PHPUnit_Framework_TestCase
{
public function testSetGet()
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
$scope = new Scope($server);
$scope->setId('foobar');
$scope->setDescription('barfoo');
$this->assertEquals('foobar', $scope->getId());
$this->assertEquals('barfoo', $scope->getDescription());
}
}

View File

@@ -0,0 +1,129 @@
<?php
namespace LeagueTests\Entity;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\AuthCodeEntity;
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 \Mockery as M;
class SessionTests extends \PHPUnit_Framework_TestCase
{
public function testSetGet()
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
$entity = new Session($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->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->hasScope('foo'));
$reflector = new \ReflectionClass($entity);
$accessTokenProperty = $reflector->getProperty('accessToken');
$accessTokenProperty->setAccessible(true);
$refreshTokenProperty = $reflector->getProperty('refreshToken');
$refreshTokenProperty->setAccessible(true);
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessToken);
$this->assertTrue($refreshTokenProperty->getValue($entity) instanceof RefreshToken);
// $this->assertTrue($reader($entity, 'authCode') instanceof AuthCode);
}
public function testFormatScopes()
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
$entity = new Session($server);
$reflectedEntity = new \ReflectionClass('League\OAuth2\Server\Entity\Session');
$method = $reflectedEntity->getMethod('formatScopes');
$method->setAccessible(true);
$scopes = [
(new Scope($server))->setId('scope1')->setDescription('foo'),
(new Scope($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);
}
public function testGetScopes()
{
$server = new Authorization();
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('setServer');
$server->setAccessTokenStorage($accessTokenStorage);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('getScopes')->andReturn(
[]
);
$sessionStorage->shouldReceive('setServer');
$server->setSessionStorage($sessionStorage);
$entity = new Session($server);
$this->assertEquals($entity->getScopes(), []);
}
public function testHasScopes()
{
$server = new Authorization();
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('setServer');
$server->setAccessTokenStorage($accessTokenStorage);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('getScopes')->andReturn(
[]
);
$sessionStorage->shouldReceive('setServer');
$server->setSessionStorage($sessionStorage);
$entity = new Session($server);
$this->assertFalse($entity->hasScope('foo'));
}
function testSave()
{
$server = new Authorization();
$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')
]);
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
$clientStorage->shouldReceive('getBySession')->andReturn(
(new Client($server))->setId('foo')
);
$clientStorage->shouldReceive('setServer');
$server->setSessionStorage($sessionStorage);
$server->setClientStorage($clientStorage);
$entity = new Session($server);
$this->assertEquals(null, $entity->save());
}
}