oauth2-server/tests/Entity/AuthCodeEntityTest.php

74 lines
2.6 KiB
PHP
Raw Normal View History

<?php
2014-05-02 19:42:15 +05:30
namespace LeagueTests\Entity;
2014-05-02 19:42:15 +05:30
use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Entity\AuthCodeEntity;
2014-04-06 23:44:46 +05:30
use League\OAuth2\Server\AuthorizationServer;
use \Mockery as M;
class AuthCodeTest extends \PHPUnit_Framework_TestCase
{
2014-05-03 15:25:25 +05:30
public function testSetGet()
2014-04-06 23:44:46 +05:30
{
2014-05-02 19:42:15 +05:30
$server = M::mock('League\OAuth2\Server\AbstractServer');
2014-04-06 23:44:46 +05:30
2014-05-02 19:42:15 +05:30
$session = M::mock('League\OAuth2\Server\Entity\SessionEntity');
$code = new AuthCodeEntity($server);
2014-04-06 23:44:46 +05:30
$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());
2014-05-02 19:42:15 +05:30
$this->assertTrue($code->getSession() instanceof \League\OAuth2\Server\Entity\SessionEntity);
2014-04-06 23:44:46 +05:30
}
2014-05-03 15:25:25 +05:30
public function testSave()
{
2014-05-02 19:42:15 +05:30
$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([
2014-05-02 19:42:15 +05:30
(new ScopeEntity($server))->setId('foo')
]);
2014-05-02 19:42:15 +05:30
$server->shouldReceive('getStorage')->with('auth_code')->andReturn($authCodeStorage);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('getByAuthCode')->andReturn(
2014-05-02 19:42:15 +05:30
(new SessionEntity($server))
);
$sessionStorage->shouldReceive('setServer');
2014-05-02 19:42:15 +05:30
$server->shouldReceive('getStorage')->with('session')->andReturn($sessionStorage);
$server->setAuthCodeStorage($authCodeStorage);
$server->setSessionStorage($sessionStorage);
2014-05-02 19:42:15 +05:30
$entity = new AuthCodeEntity($server);
$this->assertTrue($entity->save() instanceof AuthCodeEntity);
}
2014-05-03 15:25:25 +05:30
public function testExpire()
{
2014-04-06 23:44:46 +05:30
$server = new AuthorizationServer();
$authCodeStorage = M::mock('League\OAuth2\Server\Storage\AuthCodeInterface');
$authCodeStorage->shouldReceive('delete');
$authCodeStorage->shouldReceive('setServer');
$server->setAuthCodeStorage($authCodeStorage);
2014-05-02 19:42:15 +05:30
$entity = new AuthCodeEntity($server);
$this->assertSame($entity->expire(), null);
}
}