Add lang parameter
This commit is contained in:
@@ -12,6 +12,7 @@ class Vkontakte extends AbstractProvider
|
|||||||
protected $baseOAuthUri = 'https://oauth.vk.com';
|
protected $baseOAuthUri = 'https://oauth.vk.com';
|
||||||
protected $baseUri = 'https://api.vk.com/method';
|
protected $baseUri = 'https://api.vk.com/method';
|
||||||
protected $version = '5.52';
|
protected $version = '5.52';
|
||||||
|
protected $language = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type array
|
* @type array
|
||||||
@@ -111,6 +112,16 @@ class Vkontakte extends AbstractProvider
|
|||||||
//'wall_comments',
|
//'wall_comments',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $language
|
||||||
|
*/
|
||||||
|
public function setLanguage($language)
|
||||||
|
{
|
||||||
|
$this->language = (string)$language;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function getBaseAuthorizationUrl()
|
public function getBaseAuthorizationUrl()
|
||||||
{
|
{
|
||||||
return "$this->baseOAuthUri/authorize";
|
return "$this->baseOAuthUri/authorize";
|
||||||
@@ -125,6 +136,7 @@ class Vkontakte extends AbstractProvider
|
|||||||
'fields' => $this->userFields,
|
'fields' => $this->userFields,
|
||||||
'access_token' => $token->getToken(),
|
'access_token' => $token->getToken(),
|
||||||
'v' => $this->version,
|
'v' => $this->version,
|
||||||
|
'lang' => $this->language
|
||||||
];
|
];
|
||||||
$query = $this->buildQueryString($params);
|
$query = $this->buildQueryString($params);
|
||||||
$url = "$this->baseUri/users.get?$query";
|
$url = "$this->baseUri/users.get?$query";
|
||||||
@@ -201,6 +213,7 @@ class Vkontakte extends AbstractProvider
|
|||||||
'fields' => $this->userFields,
|
'fields' => $this->userFields,
|
||||||
'access_token' => $token ? $token->getToken() : null,
|
'access_token' => $token ? $token->getToken() : null,
|
||||||
'v' => $this->version,
|
'v' => $this->version,
|
||||||
|
'lang' => $this->language
|
||||||
];
|
];
|
||||||
$params = array_merge($default, $params);
|
$params = array_merge($default, $params);
|
||||||
$query = $this->buildQueryString($params);
|
$query = $this->buildQueryString($params);
|
||||||
@@ -230,6 +243,7 @@ class Vkontakte extends AbstractProvider
|
|||||||
'fields' => $this->userFields,
|
'fields' => $this->userFields,
|
||||||
'access_token' => $token ? $token->getToken() : null,
|
'access_token' => $token ? $token->getToken() : null,
|
||||||
'v' => $this->version,
|
'v' => $this->version,
|
||||||
|
'lang' => $this->language
|
||||||
];
|
];
|
||||||
$params = array_merge($default, $params);
|
$params = array_merge($default, $params);
|
||||||
$query = $this->buildQueryString($params);
|
$query = $this->buildQueryString($params);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace J4k\OAuth2\Client\Test\Provider;
|
|||||||
use GuzzleHttp\Psr7\Response;
|
use GuzzleHttp\Psr7\Response;
|
||||||
use J4k\OAuth2\Client\Provider\Vkontakte as Provider;
|
use J4k\OAuth2\Client\Provider\Vkontakte as Provider;
|
||||||
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
||||||
|
use League\OAuth2\Client\Token\AccessToken;
|
||||||
use Mockery as m;
|
use Mockery as m;
|
||||||
|
|
||||||
class VkontakteTest extends \PHPUnit_Framework_TestCase
|
class VkontakteTest extends \PHPUnit_Framework_TestCase
|
||||||
@@ -42,6 +43,18 @@ class VkontakteTest extends \PHPUnit_Framework_TestCase
|
|||||||
'urlResourceOwnerDetails' => 'http://example.com/user',
|
'urlResourceOwnerDetails' => 'http://example.com/user',
|
||||||
], $options));
|
], $options));
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @return AccessToken
|
||||||
|
*/
|
||||||
|
protected function getMockAccessTokenObject()
|
||||||
|
{
|
||||||
|
return new AccessToken([
|
||||||
|
'access_token' => 'mock_access_token',
|
||||||
|
'resource_owner_id' => 1,
|
||||||
|
'refresh_token' => 'mock_refresh_token',
|
||||||
|
'expires' => 0
|
||||||
|
]);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @return string JSON
|
* @return string JSON
|
||||||
*/
|
*/
|
||||||
@@ -194,6 +207,24 @@ class VkontakteTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
static::assertEquals('/access_token', $uri['path']);
|
static::assertEquals('/access_token', $uri['path']);
|
||||||
}
|
}
|
||||||
|
public function testResourceOwnerDetailsUrlNotContainLanguage()
|
||||||
|
{
|
||||||
|
$url = $this->provider->getResourceOwnerDetailsUrl($this->getMockAccessTokenObject());
|
||||||
|
$uri = parse_url($url);
|
||||||
|
parse_str($uri['query'], $params);
|
||||||
|
|
||||||
|
static::assertArrayNotHasKey('lang', $params);
|
||||||
|
}
|
||||||
|
public function testResourceOwnerDetailsUrlLanguage()
|
||||||
|
{
|
||||||
|
$this->provider->setLanguage('en');
|
||||||
|
$url = $this->provider->getResourceOwnerDetailsUrl($this->getMockAccessTokenObject());
|
||||||
|
$uri = parse_url($url);
|
||||||
|
parse_str($uri['query'], $params);
|
||||||
|
|
||||||
|
static::assertArrayHasKey('lang', $params);
|
||||||
|
static::assertEquals('en', $params['lang']);
|
||||||
|
}
|
||||||
public function testScopes()
|
public function testScopes()
|
||||||
{
|
{
|
||||||
static::assertEquals($this->defaultScopes, $this->provider->scopes);
|
static::assertEquals($this->defaultScopes, $this->provider->scopes);
|
||||||
|
|||||||
Reference in New Issue
Block a user