oauth2-server/tests/Entity/AbstractTokenTest.php

107 lines
3.7 KiB
PHP
Raw Normal View History

2014-01-16 22:21:06 +05:30
<?php
2014-05-02 19:42:15 +05:30
namespace LeagueTests\Entity;
2014-01-16 22:21:06 +05:30
2014-05-02 19:42:15 +05:30
use LeagueTests\Stubs\StubAbstractTokenEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\AuthorizationServer;
2014-01-16 22:21:06 +05:30
use \Mockery as M;
class AbstractTokenTests extends \PHPUnit_Framework_TestCase
{
public function testSetGet()
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
$time = time();
2014-05-02 19:42:15 +05:30
$entity = new StubAbstractTokenEntity($server);
2014-01-16 22:21:06 +05:30
$entity->setToken('foobar');
$entity->setExpireTime($time);
2014-05-02 19:42:15 +05:30
$entity->setSession((new SessionEntity($server)));
$entity->associateScope((new ScopeEntity($server))->setId('foo'));
2014-01-16 22:21:06 +05:30
$this->assertEquals('foobar', $entity->getToken());
$this->assertEquals($time, $entity->getExpireTime());
2014-05-02 19:42:15 +05:30
// $this->assertTrue($entity->getSession() instanceof SessionEntity);
// $this->assertTrue($entity->hasScope('foo'));
2014-01-16 22:21:06 +05:30
2014-05-02 19:42:15 +05:30
// $result = $entity->getScopes();
// $this->assertTrue(isset($result['foo']));
2014-01-16 22:21:06 +05:30
}
2014-05-02 19:42:15 +05:30
/*public function testGetSession()
2014-01-16 22:21:06 +05:30
{
2014-05-02 19:42:15 +05:30
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
$server->shouldReceive('setSessionStorage');
2014-01-16 22:21:06 +05:30
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('getByAccessToken')->andReturn(
2014-05-02 19:42:15 +05:30
(new SessionEntity($server))
2014-01-16 22:21:06 +05:30
);
$sessionStorage->shouldReceive('setServer');
2014-05-02 19:42:15 +05:30
$server->shouldReceive('getStorage')->andReturn($sessionStorage);
2014-01-16 22:21:06 +05:30
$server->setSessionStorage($sessionStorage);
2014-05-02 19:42:15 +05:30
$entity = new StubAbstractTokenEntity($server);
$this->assertTrue($entity->getSession() instanceof SessionEntity);
}*/
2014-01-16 22:21:06 +05:30
2014-05-02 19:42:15 +05:30
/*public function testGetScopes()
2014-01-16 22:21:06 +05:30
{
2014-05-02 19:42:15 +05:30
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
$server->shouldReceive('setAccessTokenStorage');
2014-01-16 22:21:06 +05:30
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('getScopes')->andReturn(
[]
);
$accessTokenStorage->shouldReceive('setServer');
$server->setAccessTokenStorage($accessTokenStorage);
2014-05-02 19:42:15 +05:30
$entity = new StubAbstractTokenEntity($server);
2014-01-16 22:21:06 +05:30
$this->assertEquals($entity->getScopes(), []);
2014-05-02 19:42:15 +05:30
}*/
2014-01-16 22:21:06 +05:30
2014-05-02 19:42:15 +05:30
/*public function testHasScopes()
2014-01-16 22:21:06 +05:30
{
2014-05-02 19:42:15 +05:30
$server = M::mock('League\OAuth2\Server\AuthorizationServer');
2014-01-16 22:21:06 +05:30
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('getScopes')->andReturn(
[]
);
$accessTokenStorage->shouldReceive('setServer');
$server->setAccessTokenStorage($accessTokenStorage);
2014-05-02 19:42:15 +05:30
$entity = new StubAbstractTokenEntity($server);
2014-01-16 22:21:06 +05:30
$this->assertFalse($entity->hasScope('foo'));
2014-05-02 19:42:15 +05:30
}*/
2014-01-16 22:21:06 +05:30
public function testFormatScopes()
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
2014-05-02 19:42:15 +05:30
$entity = new StubAbstractTokenEntity($server);
$reflectedEntity = new \ReflectionClass('LeagueTests\Stubs\StubAbstractTokenEntity');
2014-01-16 22:21:06 +05:30
$method = $reflectedEntity->getMethod('formatScopes');
$method->setAccessible(true);
$scopes = [
2014-05-02 19:42:15 +05:30
(new ScopeEntity($server))->setId('scope1')->setDescription('foo'),
(new ScopeEntity($server))->setId('scope2')->setDescription('bar')
2014-01-16 22:21:06 +05:30
];
$result = $method->invokeArgs($entity, [$scopes]);
$this->assertTrue(isset($result['scope1']));
$this->assertTrue(isset($result['scope2']));
2014-05-02 19:42:15 +05:30
$this->assertTrue($result['scope1'] instanceof ScopeEntity);
$this->assertTrue($result['scope2'] instanceof ScopeEntity);
2014-01-16 22:21:06 +05:30
}
}