oauth2-server/tests/Entity/AbstractTokenEntityTest.php

117 lines
4.0 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;
2014-05-03 15:25:25 +05:30
class AbstractTokenTest extends \PHPUnit_Framework_TestCase
2014-01-16 22:21:06 +05:30
{
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-07-11 22:49:10 +05:30
$entity->setId('foobar');
2014-01-16 22:21:06 +05:30
$entity->setExpireTime($time);
2014-05-02 19:42:15 +05:30
$entity->setSession((new SessionEntity($server)));
2014-07-11 22:49:10 +05:30
$entity->associateScope((new ScopeEntity($server))->hydrate(['id' => 'foo']));
2014-01-16 22:21:06 +05:30
2014-07-11 22:49:10 +05:30
$this->assertEquals('foobar', $entity->getId());
2014-01-16 22:21:06 +05:30
$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(
[]
);
2014-06-20 18:59:47 +05:30
$accessTokenStorage''>shouldReceive('setServer');
2014-01-16 22:21:06 +05:30
$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-07-11 22:49:10 +05:30
(new ScopeEntity($server))->hydrate(['id' => 'scope1', 'description' => 'foo']),
(new ScopeEntity($server))->hydrate(['id' => 'scope2', 'description' => '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
}
2014-06-20 18:59:47 +05:30
public function test__toString()
{
$server = M::mock('League\OAuth2\Server\AbstractServer');
$entity = new StubAbstractTokenEntity($server);
$this->assertEquals('', (string) $entity);
2014-07-11 22:49:10 +05:30
$entity->setId('foobar');
2014-06-20 18:59:47 +05:30
$this->assertEquals('foobar', (string) $entity);
}
2014-01-16 22:21:06 +05:30
}