Updated tests for custom expires in

This commit is contained in:
Alex Bilbie
2013-05-06 15:36:59 -07:00
parent fdebbac2df
commit 5d7e0d67cc
4 changed files with 174 additions and 0 deletions

View File

@@ -280,6 +280,48 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
$this->assertEquals(time()+$a->getExpiresIn(), $v['expires']);
}
function test_issueAccessToken_clientCredentialsGrant_customExpiresIn()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->client->shouldReceive('validateRefreshToken')->andReturn(1);
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('createSession')->andReturn(1);
$this->session->shouldReceive('deleteSession')->andReturn(null);
$this->session->shouldReceive('associateAccessToken')->andReturn(1);
$a = $this->returnDefault();
$grant = new OAuth2\Grant\ClientCredentials($a);
$grant->setExpiresIn(30);
$a->addGrantType($grant);
$a->requireScopeParam(false);
$_POST['grant_type'] = 'client_credentials';
$_POST['client_id'] = 1234;
$_POST['client_secret'] = 5678;
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken();
$this->assertArrayHasKey('access_token', $v);
$this->assertArrayHasKey('token_type', $v);
$this->assertArrayHasKey('expires', $v);
$this->assertArrayHasKey('expires_in', $v);
$this->assertNotEquals($a->getExpiresIn(), $v['expires_in']);
$this->assertNotEquals(time()+$a->getExpiresIn(), $v['expires']);
$this->assertEquals(30, $v['expires_in']);
$this->assertEquals(time()+30, $v['expires']);
}
function test_issueAccessToken_clientCredentialsGrant_withRefreshToken()
{
$this->client->shouldReceive('getClient')->andReturn(array(