Browse Source

Extension "authclient" recomposed.

tags/2.0.0-beta
Paul Klimov 11 years ago
parent
commit
41eaa2df07
  1. 34
      extensions/yii/authclient/BaseOAuth.php
  2. 30
      extensions/yii/authclient/OAuth1.php
  3. 22
      extensions/yii/authclient/OAuth2.php
  4. 4
      extensions/yii/authclient/OAuthToken.php
  5. 4
      extensions/yii/authclient/OpenId.php
  6. 30
      extensions/yii/authclient/provider/OpenId.php
  7. 73
      extensions/yii/authclient/provider/ProviderInterface.php
  8. 176
      extensions/yii/authclient/provider/ProviderTrait.php
  9. 2
      extensions/yii/authclient/signature/BaseMethod.php
  10. 2
      extensions/yii/authclient/signature/HmacSha1.php
  11. 2
      extensions/yii/authclient/signature/PlainText.php
  12. 2
      extensions/yii/authclient/signature/RsaSha1.php
  13. 22
      tests/unit/extensions/authclient/BaseOAuthTest.php
  14. 18
      tests/unit/extensions/authclient/OAuth1Test.php
  15. 6
      tests/unit/extensions/authclient/OAuth2Test.php
  16. 14
      tests/unit/extensions/authclient/TokenTest.php
  17. 6
      tests/unit/extensions/authclient/signature/BaseMethodTest.php
  18. 4
      tests/unit/extensions/authclient/signature/HmacSha1Test.php
  19. 2
      tests/unit/extensions/authclient/signature/PlainTextTest.php
  20. 2
      tests/unit/extensions/authclient/signature/RsaSha1Test.php

34
extensions/yii/authclient/oauth/BaseClient.php → extensions/yii/authclient/BaseOAuth.php

@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\authclient\oauth;
namespace yii\authclient;
use yii\base\Component;
use yii\base\Exception;
@ -21,7 +21,7 @@ use yii\helpers\Json;
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
abstract class BaseClient extends Component
abstract class BaseOAuth extends Component
{
const CONTENT_TYPE_JSON = 'json'; // JSON format
const CONTENT_TYPE_URLENCODED = 'urlencoded'; // urlencoded query string, like name1=value1&name2=value2
@ -56,7 +56,7 @@ abstract class BaseClient extends Component
*/
private $_curlOptions = [];
/**
* @var Token|array access token instance or its array configuration.
* @var OAuthToken|array access token instance or its array configuration.
*/
private $_accessToken = null;
/**
@ -100,7 +100,7 @@ abstract class BaseClient extends Component
}
/**
* @param array|Token $token
* @param array|OAuthToken $token
*/
public function setAccessToken($token)
{
@ -112,7 +112,7 @@ abstract class BaseClient extends Component
}
/**
* @return Token auth token instance.
* @return OAuthToken auth token instance.
*/
public function getAccessToken()
{
@ -129,7 +129,7 @@ abstract class BaseClient extends Component
public function setSignatureMethod($signatureMethod)
{
if (!is_object($signatureMethod) && !is_array($signatureMethod)) {
throw new InvalidParamException('"'.get_class($this).'::signatureMethod" should be instance of "\yii\autclient\oauth\signature\BaseMethod" or its array configuration. "' . gettype($signatureMethod) . '" has been given.');
throw new InvalidParamException('"' . get_class($this) . '::signatureMethod" should be instance of "\yii\autclient\signature\BaseMethod" or its array configuration. "' . gettype($signatureMethod) . '" has been given.');
}
$this->_signatureMethod = $signatureMethod;
}
@ -224,7 +224,7 @@ abstract class BaseClient extends Component
protected function defaultCurlOptions()
{
return [
CURLOPT_USERAGENT => Yii::$app->name . ' OAuth Client',
CURLOPT_USERAGENT => Yii::$app->name . ' OAuth ' . $this->version . ' Client',
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
@ -350,12 +350,12 @@ abstract class BaseClient extends Component
/**
* Creates token from its configuration.
* @param array $tokenConfig token configuration.
* @return Token token instance.
* @return OAuthToken token instance.
*/
protected function createToken(array $tokenConfig = [])
{
if (!array_key_exists('class', $tokenConfig)) {
$tokenConfig['class'] = Token::className();
$tokenConfig['class'] = OAuthToken::className();
}
return Yii::createObject($tokenConfig);
}
@ -379,23 +379,23 @@ abstract class BaseClient extends Component
/**
* Saves token as persistent state.
* @param Token $token auth token
* @param OAuthToken $token auth token
* @return static self reference.
*/
protected function saveAccessToken(Token $token)
protected function saveAccessToken(OAuthToken $token)
{
return $this->setState('token', $token);
}
/**
* Restores access token.
* @return Token auth token.
* @return OAuthToken auth token.
*/
protected function restoreAccessToken()
{
$token = $this->getState('token');
if (is_object($token)) {
/* @var $token Token */
/* @var $token OAuthToken */
if ($token->getIsExpired()) {
$token = $this->refreshAccessToken($token);
}
@ -486,14 +486,14 @@ abstract class BaseClient extends Component
/**
* Gets new auth token to replace expired one.
* @param Token $token expired auth token.
* @return Token new auth token.
* @param OAuthToken $token expired auth token.
* @return OAuthToken new auth token.
*/
abstract public function refreshAccessToken(Token $token);
abstract public function refreshAccessToken(OAuthToken $token);
/**
* Performs request to the OAuth API.
* @param Token $accessToken actual access token.
* @param OAuthToken $accessToken actual access token.
* @param string $url absolute API URL.
* @param string $method request method.
* @param array $params request parameters.

30
extensions/yii/authclient/oauth/Client1.php → extensions/yii/authclient/OAuth1.php

@ -5,20 +5,20 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\authclient\oauth;
namespace yii\authclient;
use yii\base\Exception;
use Yii;
/**
* Client1 serves as a client for the OAuth 1/1.0a flow.
* OAuth1 serves as a client for the OAuth 1/1.0a flow.
*
* In oder to acquire access token perform following sequence:
*
* ~~~
* use yii\authclient\oauth\Client1;
* use yii\authclient\OAuth1;
*
* $oauthClient = new Client1();
* $oauthClient = new OAuth1();
* $requestToken = $oauthClient->fetchRequestToken(); // Get request token
* $url = $oauthClient->buildAuthUrl($requestToken); // Get authorization URL
* Yii::$app->getResponse()->redirect($url); // Redirect to authorization URL
@ -31,7 +31,7 @@ use Yii;
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class Client1 extends BaseClient
class OAuth1 extends BaseOAuth
{
/**
* @var string protocol version.
@ -65,7 +65,7 @@ class Client1 extends BaseClient
/**
* Fetches the OAuth request token.
* @param array $params additional request params.
* @return Token request token.
* @return OAuthToken request token.
*/
public function fetchRequestToken(array $params = [])
{
@ -88,12 +88,12 @@ class Client1 extends BaseClient
/**
* Composes user authorization URL.
* @param Token $requestToken OAuth request token.
* @param OAuthToken $requestToken OAuth request token.
* @param array $params additional request params.
* @return string authorize URL
* @throws Exception on failure.
*/
public function buildAuthUrl(Token $requestToken = null, array $params = [])
public function buildAuthUrl(OAuthToken $requestToken = null, array $params = [])
{
if (!is_object($requestToken)) {
$requestToken = $this->getState('requestToken');
@ -107,13 +107,13 @@ class Client1 extends BaseClient
/**
* Fetches OAuth access token.
* @param Token $requestToken OAuth request token.
* @param OAuthToken $requestToken OAuth request token.
* @param string $oauthVerifier OAuth verifier.
* @param array $params additional request params.
* @return Token OAuth access token.
* @return OAuthToken OAuth access token.
* @throws Exception on failure.
*/
public function fetchAccessToken(Token $requestToken = null, $oauthVerifier = null, array $params = [])
public function fetchAccessToken(OAuthToken $requestToken = null, $oauthVerifier = null, array $params = [])
{
if (!is_object($requestToken)) {
$requestToken = $this->getState('requestToken');
@ -202,7 +202,7 @@ class Client1 extends BaseClient
/**
* Performs request to the OAuth API.
* @param Token $accessToken actual access token.
* @param OAuthToken $accessToken actual access token.
* @param string $url absolute API URL.
* @param string $method request method.
* @param array $params request parameters.
@ -219,10 +219,10 @@ class Client1 extends BaseClient
/**
* Gets new auth token to replace expired one.
* @param Token $token expired auth token.
* @return Token new auth token.
* @param OAuthToken $token expired auth token.
* @return OAuthToken new auth token.
*/
public function refreshAccessToken(Token $token)
public function refreshAccessToken(OAuthToken $token)
{
// @todo
return null;

22
extensions/yii/authclient/oauth/Client2.php → extensions/yii/authclient/OAuth2.php

@ -5,20 +5,20 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\authclient\oauth;
namespace yii\authclient;
use Yii;
use yii\base\Exception;
/**
* Client2 serves as a client for the OAuth 2 flow.
* OAuth2 serves as a client for the OAuth 2 flow.
*
* In oder to acquire access token perform following sequence:
*
* ~~~
* use yii\authclient\oauth\Client2;
* use yii\authclient\OAuth2;
*
* $oauthClient = new Client2();
* $oauthClient = new OAuth2();
* $url = $oauthClient->buildAuthUrl(); // Build authorization URL
* Yii::$app->getResponse()->redirect($url); // Redirect to authorization URL.
* // After user returns at our site:
@ -31,7 +31,7 @@ use yii\base\Exception;
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class Client2 extends BaseClient
class OAuth2 extends BaseOAuth
{
/**
* @var string protocol version.
@ -73,7 +73,7 @@ class Client2 extends BaseClient
* Fetches access token from authorization code.
* @param string $authCode authorization code, usually comes at $_GET['code'].
* @param array $params additional request params.
* @return Token access token.
* @return OAuthToken access token.
*/
public function fetchAccessToken($authCode, array $params = [])
{
@ -130,7 +130,7 @@ class Client2 extends BaseClient
/**
* Performs request to the OAuth API.
* @param Token $accessToken actual access token.
* @param OAuthToken $accessToken actual access token.
* @param string $url absolute API URL.
* @param string $method request method.
* @param array $params request parameters.
@ -145,10 +145,10 @@ class Client2 extends BaseClient
/**
* Gets new auth token to replace expired one.
* @param Token $token expired auth token.
* @return Token new auth token.
* @param OAuthToken $token expired auth token.
* @return OAuthToken new auth token.
*/
public function refreshAccessToken(Token $token)
public function refreshAccessToken(OAuthToken $token)
{
$params = [
'client_id' => $this->clientId,
@ -174,7 +174,7 @@ class Client2 extends BaseClient
/**
* Creates token from its configuration.
* @param array $tokenConfig token configuration.
* @return Token token instance.
* @return OAuthToken token instance.
*/
protected function createToken(array $tokenConfig = [])
{

4
extensions/yii/authclient/oauth/Token.php → extensions/yii/authclient/OAuthToken.php

@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\authclient\oauth;
namespace yii\authclient;
use yii\base\Object;
@ -19,7 +19,7 @@ use yii\base\Object;
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class Token extends Object
class OAuthToken extends Object
{
/**
* @var string key in {@link _params} array, which stores token key.

4
extensions/yii/authclient/openid/Client.php → extensions/yii/authclient/OpenId.php

@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\authclient\openid;
namespace yii\authclient;
use yii\base\Component;
use yii\base\Exception;
@ -25,7 +25,7 @@ use yii\base\NotSupportedException;
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class Client extends Component
class OpenId extends Component
{
public $required = [];
public $optional = [];

30
extensions/yii/authclient/provider/OpenId.php

@ -0,0 +1,30 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\authclient\provider;
use yii\authclient\openid\Client;
/**
* Class OpenId
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class OpenId extends Client implements ProviderInterface
{
use ProviderTrait;
/**
* Authenticate the user.
* @return boolean whether user was successfully authenticated.
*/
public function authenticate()
{
// TODO: Implement authenticate() method.
}
}

73
extensions/yii/authclient/provider/ProviderInterface.php

@ -0,0 +1,73 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\authclient\provider;
/**
* Class ProviderInterface
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
interface ProviderInterface
{
/**
* @param string $id service id.
*/
public function setId($id);
/**
* @return string service id
*/
public function getId();
/**
* @return string service name.
*/
public function getName();
/**
* @param string $name service name.
*/
public function setName($name);
/**
* @return string service title.
*/
public function getTitle();
/**
* @param string $title service title.
*/
public function setTitle($title);
/**
* @param string $url successful URL.
*/
public function setSuccessUrl($url);
/**
* @return string successful URL.
*/
public function getSuccessUrl();
/**
* @param string $url cancel URL.
*/
public function setCancelUrl($url);
/**
* @return string cancel URL.
*/
public function getCancelUrl();
/**
* Authenticate the user.
* @return boolean whether user was successfully authenticated.
*/
public function authenticate();
}

176
extensions/yii/authclient/provider/ProviderTrait.php

@ -0,0 +1,176 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\authclient\provider;
use Yii;
use yii\helpers\StringHelper;
/**
* Class ProviderTrait
*
* @see ProviderInterface
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
trait ProviderTrait
{
/**
* @var string service id.
* This value mainly used as HTTP request parameter.
*/
private $_id;
/**
* @var string service unique name.
* This value may be used in database records, CSS files and so on.
*/
private $_name;
/**
* @var string service title to display in views.
*/
private $_title;
/**
* @var string the redirect url after successful authorization.
*/
private $_successUrl = '';
/**
* @var string the redirect url after unsuccessful authorization (e.g. user canceled).
*/
private $_cancelUrl = '';
/**
* @param string $id service id.
*/
public function setId($id)
{
$this->_id = $id;
}
/**
* @return string service id
*/
public function getId()
{
if (empty($this->_id)) {
$this->_id = $this->getName();
}
return $this->_id;
}
/**
* @return string service name.
*/
public function getName()
{
if ($this->_name === null) {
$this->_name = $this->defaultName();
}
return $this->_name;
}
/**
* @param string $name service name.
*/
public function setName($name)
{
$this->_name = $name;
}
/**
* @return string service title.
*/
public function getTitle()
{
if ($this->_title === null) {
$this->_title = $this->defaultTitle();
}
return $this->_title;
}
/**
* @param string $title service title.
*/
public function setTitle($title)
{
$this->_title = $title;
}
/**
* @param string $url successful URL.
*/
public function setSuccessUrl($url)
{
$this->_successUrl = $url;
}
/**
* @return string successful URL.
*/
public function getSuccessUrl()
{
if (empty($this->_successUrl)) {
$this->_successUrl = $this->defaultSuccessUrl();
}
return $this->_successUrl;
}
/**
* @param string $url cancel URL.
*/
public function setCancelUrl($url)
{
$this->_cancelUrl = $url;
}
/**
* @return string cancel URL.
*/
public function getCancelUrl()
{
if (empty($this->_cancelUrl)) {
$this->_cancelUrl = $this->defaultCancelUrl();
}
return $this->_cancelUrl;
}
/**
* Generates service name.
* @return string service name.
*/
protected function defaultName()
{
return StringHelper::basename(get_class($this));
}
/**
* Generates service title.
* @return string service title.
*/
protected function defaultTitle()
{
return StringHelper::basename(get_class($this));
}
/**
* Creates default {@link successUrl} value.
* @return string success URL value.
*/
protected function defaultSuccessUrl()
{
return Yii::$app->getUser()->getReturnUrl();
}
/**
* Creates default {@link cancelUrl} value.
* @return string cancel URL value.
*/
protected function defaultCancelUrl()
{
return Yii::$app->getRequest()->getAbsoluteUrl();
}
}

2
extensions/yii/authclient/oauth/signature/BaseMethod.php → extensions/yii/authclient/signature/BaseMethod.php

@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\authclient\oauth\signature;
namespace yii\authclient\signature;
use yii\base\Object;

2
extensions/yii/authclient/oauth/signature/HmacSha1.php → extensions/yii/authclient/signature/HmacSha1.php

@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\authclient\oauth\signature;
namespace yii\authclient\signature;
use yii\base\NotSupportedException;

2
extensions/yii/authclient/oauth/signature/PlainText.php → extensions/yii/authclient/signature/PlainText.php

@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\authclient\oauth\signature;
namespace yii\authclient\signature;
/**
* PlainText represents 'PLAINTEXT' signature method.

2
extensions/yii/authclient/oauth/signature/RsaSha1.php → extensions/yii/authclient/signature/RsaSha1.php

@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace yii\authclient\oauth\signature;
namespace yii\authclient\signature;
use yii\base\InvalidConfigException;
use yii\base\NotSupportedException;

22
tests/unit/extensions/authclient/oauth/BaseClientTest.php → tests/unit/extensions/authclient/BaseOAuthTest.php

@ -1,21 +1,21 @@
<?php
namespace yiiunit\extensions\authclient\oauth;
namespace yiiunit\extensions\authclient;
use yii\authclient\oauth\signature\PlainText;
use yii\authclient\oauth\Token;
use yii\authclient\signature\PlainText;
use yii\authclient\OAuthToken;
use yiiunit\extensions\authclient\TestCase;
use yii\authclient\oauth\BaseClient;
use yii\authclient\BaseOAuth;
class BaseClientTest extends TestCase
class BaseOAuthTest extends TestCase
{
/**
* Creates test OAuth client instance.
* @return BaseClient oauth client.
* @return BaseOAuth oauth client.
*/
protected function createOAuthClient()
{
$oauthClient = $this->getMock(BaseClient::className(), ['setState', 'getState', 'composeRequestCurlOptions', 'refreshAccessToken', 'apiInternal']);
$oauthClient = $this->getMock(BaseOAuth::className(), ['setState', 'getState', 'composeRequestCurlOptions', 'refreshAccessToken', 'apiInternal']);
$oauthClient->expects($this->any())->method('setState')->will($this->returnValue($oauthClient));
$oauthClient->expects($this->any())->method('getState')->will($this->returnValue(null));
return $oauthClient;
@ -23,7 +23,7 @@ class BaseClientTest extends TestCase
/**
* Invokes the OAuth client method even if it is protected.
* @param BaseClient $oauthClient OAuth client instance.
* @param BaseOAuth $oauthClient OAuth client instance.
* @param string $methodName name of the method to be invoked.
* @param array $arguments method arguments.
* @return mixed method invoke result.
@ -60,7 +60,7 @@ class BaseClientTest extends TestCase
{
$oauthClient = $this->createOAuthClient();
$oauthToken = new Token();
$oauthToken = new OAuthToken();
$oauthClient->setAccessToken($oauthToken);
$this->assertEquals($oauthToken, $oauthClient->getAccessToken(), 'Unable to setup token!');
@ -84,7 +84,7 @@ class BaseClientTest extends TestCase
$this->assertEquals($oauthToken['token'], $oauthClient->getAccessToken()->getToken(), 'Unable to setup token as config!');
$oauthSignatureMethod = [
'class' => 'yii\authclient\oauth\signature\PlainText'
'class' => 'yii\authclient\signature\PlainText'
];
$oauthClient->setSignatureMethod($oauthSignatureMethod);
$returnedSignatureMethod = $oauthClient->getSignatureMethod();
@ -239,7 +239,7 @@ class BaseClientTest extends TestCase
$oauthClient = $this->createOAuthClient();
$oauthClient->expects($this->any())->method('apiInternal')->will($this->returnArgument(1));
$accessToken = new Token();
$accessToken = new OAuthToken();
$accessToken->setToken('test_access_token');
$accessToken->setExpireDuration(1000);
$oauthClient->setAccessToken($accessToken);

18
tests/unit/extensions/authclient/oauth/Client1Test.php → tests/unit/extensions/authclient/OAuth1Test.php

@ -2,12 +2,12 @@
namespace yiiunit\extensions\authclient\oauth;
use yii\authclient\oauth\Client1;
use yii\authclient\oauth\signature\PlainText;
use yii\authclient\oauth\Token;
use yii\authclient\OAuth1;
use yii\authclient\signature\PlainText;
use yii\authclient\OAuthToken;
use yiiunit\extensions\authclient\TestCase;
class Client1Test extends TestCase
class OAuth1Test extends TestCase
{
protected function setUp()
{
@ -16,7 +16,7 @@ class Client1Test extends TestCase
/**
* Invokes the OAuth client method even if it is protected.
* @param Client1 $oauthClient OAuth client instance.
* @param OAuth1 $oauthClient OAuth client instance.
* @param string $methodName name of the method to be invoked.
* @param array $arguments method arguments.
* @return mixed method invoke result.
@ -35,7 +35,7 @@ class Client1Test extends TestCase
public function testSignRequest()
{
$oauthClient = new Client1();
$oauthClient = new OAuth1();
$oauthSignatureMethod = new PlainText();
$oauthClient->setSignatureMethod($oauthSignatureMethod);
@ -87,18 +87,18 @@ class Client1Test extends TestCase
*/
public function testComposeAuthorizationHeader($realm, array $params, $expectedAuthorizationHeader)
{
$oauthClient = new Client1();
$oauthClient = new OAuth1();
$authorizationHeader = $this->invokeOAuthClientMethod($oauthClient, 'composeAuthorizationHeader', [$params, $realm]);
$this->assertEquals($expectedAuthorizationHeader, $authorizationHeader);
}
public function testBuildAuthUrl() {
$oauthClient = new Client1();
$oauthClient = new OAuth1();
$authUrl = 'http://test.auth.url';
$oauthClient->authUrl = $authUrl;
$requestTokenToken = 'test_request_token';
$requestToken = new Token();
$requestToken = new OAuthToken();
$requestToken->setToken($requestTokenToken);
$builtAuthUrl = $oauthClient->buildAuthUrl($requestToken);

6
tests/unit/extensions/authclient/oauth/Client2Test.php → tests/unit/extensions/authclient/OAuth2Test.php

@ -2,10 +2,10 @@
namespace yiiunit\extensions\authclient\oauth;
use yii\authclient\oauth\Client2;
use yii\authclient\OAuth2;
use yiiunit\extensions\authclient\TestCase;
class Client2Test extends TestCase
class OAuth2Test extends TestCase
{
protected function setUp()
{
@ -16,7 +16,7 @@ class Client2Test extends TestCase
public function testBuildAuthUrl()
{
$oauthClient = new Client2();
$oauthClient = new OAuth2();
$authUrl = 'http://test.auth.url';
$oauthClient->authUrl = $authUrl;
$clientId = 'test_client_id';

14
tests/unit/extensions/authclient/oauth/TokenTest.php → tests/unit/extensions/authclient/TokenTest.php

@ -2,7 +2,7 @@
namespace yiiunit\extensions\authclient\oauth;
use yii\authclient\oauth\Token;
use yii\authclient\OAuthToken;
use yiiunit\extensions\authclient\TestCase;
class TokenTest extends TestCase
@ -13,7 +13,7 @@ class TokenTest extends TestCase
'tokenParamKey' => 'test_token_param_key',
'tokenSecretParamKey' => 'test_token_secret_param_key',
];
$oauthToken = new Token($config);
$oauthToken = new OAuthToken($config);
$this->assertTrue(is_object($oauthToken), 'Unable to create access token!');
foreach ($config as $name => $value) {
$this->assertEquals($value, $oauthToken->$name, 'Unable to setup attributes by constructor!');
@ -23,7 +23,7 @@ class TokenTest extends TestCase
public function testSetupParams()
{
$oauthToken = new Token();
$oauthToken = new OAuthToken();
$params = [
'name_1' => 'value_1',
@ -43,7 +43,7 @@ class TokenTest extends TestCase
*/
public function testSetupParamsShortcuts()
{
$oauthToken = new Token();
$oauthToken = new OAuthToken();
$token = 'test_token_value';
$oauthToken->setToken($token);
@ -93,7 +93,7 @@ class TokenTest extends TestCase
*/
public function testAutoFetchExpireDuration(array $params, $expectedExpireDuration)
{
$oauthToken = new Token();
$oauthToken = new OAuthToken();
$oauthToken->setParams($params);
$this->assertEquals($expectedExpireDuration, $oauthToken->getExpireDuration());
}
@ -103,7 +103,7 @@ class TokenTest extends TestCase
*/
public function testGetIsExpired()
{
$oauthToken = new Token();
$oauthToken = new OAuthToken();
$expireDuration = 3600;
$oauthToken->setExpireDuration($expireDuration);
@ -118,7 +118,7 @@ class TokenTest extends TestCase
*/
public function testGetIsValid()
{
$oauthToken = new Token();
$oauthToken = new OAuthToken();
$expireDuration = 3600;
$oauthToken->setExpireDuration($expireDuration);

6
tests/unit/extensions/authclient/oauth/signature/BaseMethodTest.php → tests/unit/extensions/authclient/signature/BaseMethodTest.php

@ -1,6 +1,6 @@
<?php
namespace yiiunit\extensions\authclient\oauth\signature;
namespace yiiunit\extensions\authclient\signature;
use yiiunit\extensions\authclient\TestCase;
@ -8,11 +8,11 @@ class BaseMethodTest extends TestCase
{
/**
* Creates test signature method instance.
* @return \yii\authclient\oauth\signature\BaseMethod
* @return \yii\authclient\signature\BaseMethod
*/
protected function createTestSignatureMethod()
{
$signatureMethod = $this->getMock('\yii\authclient\oauth\signature\BaseMethod', ['getName', 'generateSignature']);
$signatureMethod = $this->getMock('\yii\authclient\signature\BaseMethod', ['getName', 'generateSignature']);
$signatureMethod->expects($this->any())->method('getName')->will($this->returnValue('testMethodName'));
$signatureMethod->expects($this->any())->method('generateSignature')->will($this->returnValue('testSignature'));
return $signatureMethod;

4
tests/unit/extensions/authclient/oauth/signature/HmacSha1Test.php → tests/unit/extensions/authclient/signature/HmacSha1Test.php

@ -1,8 +1,8 @@
<?php
namespace yiiunit\extensions\authclient\oauth\signature;
namespace yiiunit\extensions\authclient\signature;
use yii\authclient\oauth\signature\HmacSha1;
use yii\authclient\signature\HmacSha1;
use yiiunit\extensions\authclient\TestCase;
class HmacSha1Test extends TestCase

2
tests/unit/extensions/authclient/oauth/signature/PlainTextTest.php → tests/unit/extensions/authclient/signature/PlainTextTest.php

@ -2,7 +2,7 @@
namespace yiiunit\extensions\authclient\oauth\signature;
use yii\authclient\oauth\signature\PlainText;
use yii\authclient\signature\PlainText;
use yiiunit\extensions\authclient\TestCase;
class PlainTextTest extends TestCase

2
tests/unit/extensions/authclient/oauth/signature/RsaSha1Test.php → tests/unit/extensions/authclient/signature/RsaSha1Test.php

@ -2,7 +2,7 @@
namespace yiiunit\extensions\authclient\oauth\signature;
use yii\authclient\oauth\signature\RsaSha1;
use yii\authclient\signature\RsaSha1;
use yiiunit\extensions\authclient\TestCase;
class RsaSha1Test extends TestCase
Loading…
Cancel
Save