mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-17 10:39:45 +05:30
PSR fixes
This commit is contained in:
parent
0876fd9ad3
commit
0fcbeb8158
@ -2,120 +2,123 @@
|
|||||||
|
|
||||||
class Resource_Server_test extends PHPUnit_Framework_TestCase {
|
class Resource_Server_test extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
function setUp()
|
function setUp()
|
||||||
{
|
{
|
||||||
require_once('database_mock.php');
|
require_once 'src/OAuth2/Resource/Server.php';
|
||||||
$this->server = new Oauth2\Resource\Server();
|
require_once 'src/OAuth2/Resource/Database.php';
|
||||||
$this->db = new ResourceDB();
|
|
||||||
|
|
||||||
$this->assertInstanceOf('Oauth2\Resource\Database', $this->db);
|
require_once('database_mock.php');
|
||||||
$this->server->registerDbAbstractor($this->db);
|
$this->server = new Oauth2\Resource\Server();
|
||||||
}
|
$this->db = new ResourceDB();
|
||||||
|
|
||||||
function test_init_POST()
|
$this->assertInstanceOf('Oauth2\Resource\Database', $this->db);
|
||||||
{
|
$this->server->registerDbAbstractor($this->db);
|
||||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
}
|
||||||
$_POST['oauth_token'] = 'test12345';
|
|
||||||
|
|
||||||
$this->server->init();
|
function test_init_POST()
|
||||||
|
{
|
||||||
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||||
|
$_POST['oauth_token'] = 'test12345';
|
||||||
|
|
||||||
$reflector = new ReflectionClass($this->server);
|
$this->server->init();
|
||||||
|
|
||||||
$_accessToken = $reflector->getProperty('_accessToken');
|
$reflector = new ReflectionClass($this->server);
|
||||||
$_accessToken->setAccessible(true);
|
|
||||||
|
|
||||||
$_type = $reflector->getProperty('_type');
|
$_accessToken = $reflector->getProperty('_accessToken');
|
||||||
$_type->setAccessible(true);
|
$_accessToken->setAccessible(true);
|
||||||
|
|
||||||
$_typeId = $reflector->getProperty('_typeId');
|
$_type = $reflector->getProperty('_type');
|
||||||
$_typeId->setAccessible(true);
|
$_type->setAccessible(true);
|
||||||
|
|
||||||
$_scopes = $reflector->getProperty('_scopes');
|
$_typeId = $reflector->getProperty('_typeId');
|
||||||
$_scopes->setAccessible(true);
|
$_typeId->setAccessible(true);
|
||||||
|
|
||||||
$this->assertEquals($_accessToken->getValue($this->server), $_POST['oauth_token']);
|
$_scopes = $reflector->getProperty('_scopes');
|
||||||
$this->assertEquals($_type->getValue($this->server), 'user');
|
$_scopes->setAccessible(true);
|
||||||
$this->assertEquals($_typeId->getValue($this->server), 123);
|
|
||||||
$this->assertEquals($_scopes->getValue($this->server), array('foo', 'bar'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_init_GET()
|
$this->assertEquals($_accessToken->getValue($this->server), $_POST['oauth_token']);
|
||||||
{
|
$this->assertEquals($_type->getValue($this->server), 'user');
|
||||||
$_GET['oauth_token'] = 'test12345';
|
$this->assertEquals($_typeId->getValue($this->server), 123);
|
||||||
|
$this->assertEquals($_scopes->getValue($this->server), array('foo', 'bar'));
|
||||||
|
}
|
||||||
|
|
||||||
$this->server->init();
|
function test_init_GET()
|
||||||
|
{
|
||||||
|
$_GET['oauth_token'] = 'test12345';
|
||||||
|
|
||||||
$reflector = new ReflectionClass($this->server);
|
$this->server->init();
|
||||||
|
|
||||||
$_accessToken = $reflector->getProperty('_accessToken');
|
$reflector = new ReflectionClass($this->server);
|
||||||
$_accessToken->setAccessible(true);
|
|
||||||
|
|
||||||
$_type = $reflector->getProperty('_type');
|
$_accessToken = $reflector->getProperty('_accessToken');
|
||||||
$_type->setAccessible(true);
|
$_accessToken->setAccessible(true);
|
||||||
|
|
||||||
$_typeId = $reflector->getProperty('_typeId');
|
$_type = $reflector->getProperty('_type');
|
||||||
$_typeId->setAccessible(true);
|
$_type->setAccessible(true);
|
||||||
|
|
||||||
$_scopes = $reflector->getProperty('_scopes');
|
$_typeId = $reflector->getProperty('_typeId');
|
||||||
$_scopes->setAccessible(true);
|
$_typeId->setAccessible(true);
|
||||||
|
|
||||||
$this->assertEquals($_accessToken->getValue($this->server), $_GET['oauth_token']);
|
$_scopes = $reflector->getProperty('_scopes');
|
||||||
$this->assertEquals($_type->getValue($this->server), 'user');
|
$_scopes->setAccessible(true);
|
||||||
$this->assertEquals($_typeId->getValue($this->server), 123);
|
|
||||||
$this->assertEquals($_scopes->getValue($this->server), array('foo', 'bar'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_init_header()
|
$this->assertEquals($_accessToken->getValue($this->server), $_GET['oauth_token']);
|
||||||
{
|
$this->assertEquals($_type->getValue($this->server), 'user');
|
||||||
// Test with authorisation header
|
$this->assertEquals($_typeId->getValue($this->server), 123);
|
||||||
$this->markTestIncomplete('Authorisation header test has not been implemented yet.');
|
$this->assertEquals($_scopes->getValue($this->server), array('foo', 'bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function test_init_header()
|
||||||
* @expectedException \Oauth2\Resource\ClientException
|
{
|
||||||
* @expectedExceptionMessage An access token was not presented with the request
|
// Test with authorisation header
|
||||||
*/
|
$this->markTestIncomplete('Authorisation header test has not been implemented yet.');
|
||||||
function test_init_missingToken()
|
}
|
||||||
{
|
|
||||||
$this->server->init();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Oauth2\Resource\ClientException
|
* @expectedException \Oauth2\Resource\ClientException
|
||||||
* @expectedExceptionMessage The access token is not registered with the resource server
|
* @expectedExceptionMessage An access token was not presented with the request
|
||||||
*/
|
*/
|
||||||
function test_init_wrongToken()
|
function test_init_missingToken()
|
||||||
{
|
{
|
||||||
$_POST['oauth_token'] = 'blah';
|
$this->server->init();
|
||||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
}
|
||||||
|
|
||||||
$this->server->init();
|
/**
|
||||||
}
|
* @expectedException \Oauth2\Resource\ClientException
|
||||||
|
* @expectedExceptionMessage The access token is not registered with the resource server
|
||||||
|
*/
|
||||||
|
function test_init_wrongToken()
|
||||||
|
{
|
||||||
|
$_POST['oauth_token'] = 'blah';
|
||||||
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||||
|
|
||||||
function test_hasScope()
|
$this->server->init();
|
||||||
{
|
}
|
||||||
$_POST['oauth_token'] = 'test12345';
|
|
||||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
||||||
|
|
||||||
$this->server->init();
|
function test_hasScope()
|
||||||
|
{
|
||||||
|
$_POST['oauth_token'] = 'test12345';
|
||||||
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||||
|
|
||||||
$this->assertEquals(true, $this->server->hasScope('foo'));
|
$this->server->init();
|
||||||
$this->assertEquals(true, $this->server->hasScope('bar'));
|
|
||||||
$this->assertEquals(true, $this->server->hasScope(array('foo', 'bar')));
|
|
||||||
|
|
||||||
$this->assertEquals(false, $this->server->hasScope('foobar'));
|
$this->assertEquals(true, $this->server->hasScope('foo'));
|
||||||
$this->assertEquals(false, $this->server->hasScope(array('foobar')));
|
$this->assertEquals(true, $this->server->hasScope('bar'));
|
||||||
}
|
$this->assertEquals(true, $this->server->hasScope(array('foo', 'bar')));
|
||||||
|
|
||||||
function test___call()
|
$this->assertEquals(false, $this->server->hasScope('foobar'));
|
||||||
{
|
$this->assertEquals(false, $this->server->hasScope(array('foobar')));
|
||||||
$_POST['oauth_token'] = 'test12345';
|
}
|
||||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
|
||||||
|
|
||||||
$this->server->init();
|
function test___call()
|
||||||
|
{
|
||||||
|
$_POST['oauth_token'] = 'test12345';
|
||||||
|
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||||
|
|
||||||
$this->assertEquals(123, $this->server->isUser());
|
$this->server->init();
|
||||||
$this->assertEquals(false, $this->server->isMachine());
|
|
||||||
}
|
$this->assertEquals(123, $this->server->isUser());
|
||||||
|
$this->assertEquals(false, $this->server->isMachine());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user