2014-04-25 23:53:08 +04:00
|
|
|
<?php
|
|
|
|
|
2014-05-04 21:51:12 +04:00
|
|
|
namespace League\OAuth2\Client\Test\Provider;
|
2014-04-25 23:53:08 +04:00
|
|
|
|
|
|
|
|
2014-05-04 21:51:12 +04:00
|
|
|
class AbstractProviderTest extends \PHPUnit_Framework_TestCase
|
2014-04-25 23:53:08 +04:00
|
|
|
{
|
|
|
|
protected $provider;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
2014-11-09 00:30:40 +03:00
|
|
|
$this->provider = new \League\OAuth2\Client\Provider\Google([
|
2014-04-25 23:53:08 +04:00
|
|
|
'clientId' => 'mock_client_id',
|
|
|
|
'clientSecret' => 'mock_secret',
|
|
|
|
'redirectUri' => 'none',
|
2014-11-09 00:30:40 +03:00
|
|
|
]);
|
2014-04-25 23:53:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testInvalidGrantString()
|
|
|
|
{
|
2014-11-09 00:30:40 +03:00
|
|
|
$this->provider->getAccessToken('invalid_grant', ['invalid_parameter' => 'none']);
|
2014-04-25 23:53:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testInvalidGrantObject()
|
|
|
|
{
|
2014-11-09 00:30:40 +03:00
|
|
|
$grant = new \StdClass();
|
|
|
|
$this->provider->getAccessToken($grant, ['invalid_parameter' => 'none']);
|
2014-04-25 23:53:08 +04:00
|
|
|
}
|
2014-11-26 16:57:23 +03:00
|
|
|
|
|
|
|
public function testAuthorizationUrlStateParam()
|
|
|
|
{
|
|
|
|
$this->assertContains('state=XXX', $this->provider->getAuthorizationUrl([
|
|
|
|
'state' => 'XXX'
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
2014-11-29 00:11:26 +03:00
|
|
|
/**
|
|
|
|
* Tests https://github.com/thephpleague/oauth2-client/issues/134
|
|
|
|
*/
|
|
|
|
public function testConstructorSetsProperties()
|
|
|
|
{
|
|
|
|
$options = [
|
|
|
|
'clientId' => '1234',
|
|
|
|
'clientSecret' => '4567',
|
|
|
|
'redirectUri' => 'http://example.org/redirect',
|
|
|
|
'state' => 'foo',
|
|
|
|
'name' => 'bar',
|
|
|
|
'uidKey' => 'mynewuid',
|
|
|
|
'scopes' => ['a', 'b', 'c'],
|
|
|
|
'method' => 'get',
|
|
|
|
'scopeSeparator' => ';',
|
|
|
|
'responseType' => 'csv',
|
|
|
|
'headers' => ['Foo' => 'Bar'],
|
|
|
|
];
|
|
|
|
|
|
|
|
$mockProvider = new MockProvider($options);
|
|
|
|
|
|
|
|
foreach ($options as $key => $value) {
|
|
|
|
$this->assertEquals($value, $mockProvider->{$key});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MockProvider extends \League\OAuth2\Client\Provider\AbstractProvider
|
|
|
|
{
|
|
|
|
public function urlAuthorize()
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function urlAccessToken()
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token)
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token)
|
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
2014-04-25 23:53:08 +04:00
|
|
|
}
|