Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
776a9250
Commit
776a9250
authored
Dec 16, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
"yii\authclient" structure refactored.
parent
1ef606da
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
120 additions
and
433 deletions
+120
-433
AuthAction.php
extensions/yii/authclient/AuthAction.php
+2
-9
ClientInterface.php
extensions/yii/authclient/ClientInterface.php
+5
-25
ClientTrait.php
extensions/yii/authclient/ClientTrait.php
+19
-94
Collection.php
extensions/yii/authclient/Collection.php
+37
-35
OpenId.php
extensions/yii/authclient/OpenId.php
+7
-4
OAuth1.php
extensions/yii/authclient/provider/OAuth1.php
+0
-52
OAuth2.php
extensions/yii/authclient/provider/OAuth2.php
+0
-59
OpenId.php
extensions/yii/authclient/provider/OpenId.php
+0
-75
redirect.php
extensions/yii/authclient/views/redirect.php
+0
-0
ClientTraitTest.php
tests/unit/extensions/authclient/ClientTraitTest.php
+16
-47
CollectionTest.php
tests/unit/extensions/authclient/CollectionTest.php
+34
-33
No files found.
extensions/yii/authclient/AuthAction.php
View file @
776a9250
...
...
@@ -159,7 +159,7 @@ class AuthAction extends Action
'url'
=>
$url
,
'enforceRedirect'
=>
$enforceRedirect
,
];
$viewFile
=
__DIR__
.
DIRECTORY_SEPARATOR
.
'
provider'
.
DIRECTORY_SEPARATOR
.
'
views'
.
DIRECTORY_SEPARATOR
.
'redirect.php'
;
$viewFile
=
__DIR__
.
DIRECTORY_SEPARATOR
.
'views'
.
DIRECTORY_SEPARATOR
.
'redirect.php'
;
$response
=
Yii
::
$app
->
getResponse
();
$response
->
content
=
Yii
::
$app
->
getView
()
->
renderFile
(
$viewFile
,
$viewData
);
...
...
@@ -208,7 +208,7 @@ class AuthAction extends Action
'id'
=>
$provider
->
identity
);
$rawAttributes
=
$provider
->
getAttributes
();
foreach
(
$provider
->
getRequiredAttributes
()
as
$openIdAttributeName
)
{
foreach
(
$provider
->
requiredAttributes
as
$openIdAttributeName
)
{
if
(
isset
(
$rawAttributes
[
$openIdAttributeName
]))
{
$attributes
[
$openIdAttributeName
]
=
$rawAttributes
[
$openIdAttributeName
];
}
else
{
...
...
@@ -216,7 +216,6 @@ class AuthAction extends Action
}
}
$provider
->
setAttributes
(
$attributes
);
$provider
->
isAuthenticated
=
true
;
return
$this
->
authenticateSuccess
(
$provider
);
}
else
{
throw
new
Exception
(
'Unable to complete the authentication because the required data was not received.'
);
...
...
@@ -231,10 +230,6 @@ class AuthAction extends Action
}
}
else
{
$provider
->
identity
=
$provider
->
authUrl
;
// Setting identifier
$provider
->
required
=
[];
// Try to get info from openid provider
foreach
(
$provider
->
getRequiredAttributes
()
as
$openIdAttributeName
)
{
$this
->
required
[]
=
$openIdAttributeName
;
}
$request
=
Yii
::
$app
->
getRequest
();
$provider
->
realm
=
$request
->
getHostInfo
();
$provider
->
returnUrl
=
$provider
->
realm
.
$request
->
getUrl
();
// getting return URL
...
...
@@ -270,7 +265,6 @@ class AuthAction extends Action
}
else
{
// Upgrade to access token.
$accessToken
=
$provider
->
fetchAccessToken
();
$provider
->
isAuthenticated
=
true
;
return
$this
->
authenticateSuccess
(
$provider
);
}
}
...
...
@@ -304,7 +298,6 @@ class AuthAction extends Action
$code
=
$_GET
[
'code'
];
$token
=
$provider
->
fetchAccessToken
(
$code
);
if
(
!
empty
(
$token
))
{
$provider
->
isAuthenticated
=
true
;
return
$this
->
authenticateSuccess
(
$provider
);
}
else
{
return
$this
->
redirectCancel
();
...
...
extensions/yii/authclient/
provider/Provider
Interface.php
→
extensions/yii/authclient/
Client
Interface.php
View file @
776a9250
...
...
@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace
yii\authclient
\provider
;
namespace
yii\authclient
;
/**
* Class ProviderInterface
...
...
@@ -13,7 +13,7 @@ namespace yii\authclient\provider;
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
interface
Provider
Interface
interface
Client
Interface
{
/**
* @param string $id service id.
...
...
@@ -46,28 +46,7 @@ interface ProviderInterface
public
function
setTitle
(
$title
);
/**
* @
param string $url successful URL.
* @
return array list of user attributes
*/
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 \yii\web\Response|boolean response instance or whether user was successfully authenticated.
*/
public
function
authenticate
();
public
function
getUserAttributes
();
}
\ No newline at end of file
extensions/yii/authclient/
provider/Provider
Trait.php
→
extensions/yii/authclient/
Client
Trait.php
View file @
776a9250
...
...
@@ -5,20 +5,21 @@
* @license http://www.yiiframework.com/license/
*/
namespace
yii\authclient
\provider
;
namespace
yii\authclient
;
use
Yii
;
use
yii\base\NotSupportedException
;
use
yii\helpers\StringHelper
;
/**
* Class ProviderTrait
*
* @see
Provider
Interface
* @see
Client
Interface
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
trait
Provider
Trait
trait
Client
Trait
{
/**
* @var string service id.
...
...
@@ -35,13 +36,9 @@ trait ProviderTrait
*/
private
$_title
;
/**
* @var
string the redirect url after successful authorization
.
* @var
array authenticated user attributes
.
*/
private
$_successUrl
=
''
;
/**
* @var string the redirect url after unsuccessful authorization (e.g. user canceled).
*/
private
$_cancelUrl
=
''
;
private
$_userAttributes
;
/**
* @param string $id service id.
...
...
@@ -101,41 +98,22 @@ trait ProviderTrait
}
/**
* @
param string $url successful URL.
* @
return array list of user attributes
*/
public
function
setSuccessUrl
(
$url
)
public
function
getUserAttributes
(
)
{
$this
->
_successUrl
=
$url
;
if
(
$this
->
_userAttributes
===
null
)
{
$this
->
_userAttributes
=
$this
->
initUserAttributes
();
}
/**
* @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
$this
->
_userAttributes
;
}
/**
* @
return string cancel URL.
* @
param array $userAttributes list of user attributes
*/
public
function
getCancelUrl
(
)
public
function
setUserAttributes
(
array
$userAttributes
)
{
if
(
empty
(
$this
->
_cancelUrl
))
{
$this
->
_cancelUrl
=
$this
->
defaultCancelUrl
();
}
return
$this
->
_cancelUrl
;
$this
->
_userAttributes
=
$userAttributes
;
}
/**
...
...
@@ -157,65 +135,11 @@ trait ProviderTrait
}
/**
* 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.
* Initializes authenticated user attributes.
* @return array auth user attributes.
*/
protected
function
defaultCancelUrl
()
protected
function
initUserAttributes
()
{
return
Yii
::
$app
->
getRequest
()
->
getAbsoluteUrl
();
}
/**
* Redirect to the given URL or simply close the popup window.
* @param mixed $url URL to redirect, could be a string or array config to generate a valid URL.
* @param boolean $enforceRedirect indicates if redirect should be performed even in case of popup window.
* @return \yii\web\Response response instance.
*/
public
function
redirect
(
$url
,
$enforceRedirect
=
true
)
{
$viewData
=
[
'url'
=>
$url
,
'enforceRedirect'
=>
$enforceRedirect
,
];
$viewFile
=
__DIR__
.
DIRECTORY_SEPARATOR
.
'views'
.
DIRECTORY_SEPARATOR
.
'redirect.php'
;
$response
=
Yii
::
$app
->
getResponse
();
$response
->
content
=
Yii
::
$app
->
getView
()
->
renderFile
(
$viewFile
,
$viewData
);
return
$response
;
}
/**
* Redirect to the URL. If URL is null, {@link successUrl} will be used.
* @param string $url URL to redirect.
* @return \yii\web\Response response instance.
*/
public
function
redirectSuccess
(
$url
=
null
)
{
if
(
$url
===
null
)
{
$url
=
$this
->
getSuccessUrl
();
}
return
$this
->
redirect
(
$url
);
}
/**
* Redirect to the {@link cancelUrl} or simply close the popup window.
* @param string $url URL to redirect.
* @return \yii\web\Response response instance.
*/
public
function
redirectCancel
(
$url
=
null
)
{
if
(
$url
===
null
)
{
$url
=
$this
->
getCancelUrl
();
}
return
$this
->
redirect
(
$url
,
false
);
throw
new
NotSupportedException
(
'Method "'
.
get_class
(
$this
)
.
'::'
.
__FUNCTION__
.
'" not implemented.'
);
}
}
\ No newline at end of file
extensions/yii/authclient/
provider/
Collection.php
→
extensions/yii/authclient/Collection.php
View file @
776a9250
...
...
@@ -5,27 +5,27 @@
* @license http://www.yiiframework.com/license/
*/
namespace
yii\authclient
\provider
;
namespace
yii\authclient
;
use
yii\base\Component
;
use
yii\base\InvalidParamException
;
use
Yii
;
/**
* Collection is a storage for all auth
provider
s in the application.
* Collection is a storage for all auth
client
s in the application.
*
* Example application configuration:
*
* ~~~
* 'components' => [
* 'auth' => [
* 'class' => 'yii\authclient\
provider\
Collection',
* '
provider
s' => [
* 'class' => 'yii\authclient\Collection',
* '
client
s' => [
* 'google' => [
* 'class' => 'yii\authclient\
provider
\GoogleOpenId'
* 'class' => 'yii\authclient\
clients
\GoogleOpenId'
* ],
* 'facebook' => [
* 'class' => 'yii\authclient\
provider
\Facebook',
* 'class' => 'yii\authclient\
clients
\Facebook',
* 'clientId' => 'facebook_client_id',
* 'clientSecret' => 'facebook_client_secret',
* ],
...
...
@@ -35,69 +35,71 @@ use Yii;
* ]
* ~~~
*
* @property array $clients list of Auth clients with their configuration in format: 'clientId' => [...]
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class
Collection
extends
Component
{
/**
* @var array list of Auth
providers with their configuration in format: 'provider
Id' => [...]
* @var array list of Auth
clients with their configuration in format: 'client
Id' => [...]
*/
private
$_
provider
s
=
[];
private
$_
client
s
=
[];
/**
* @param array $
providers list of auth provider
s
* @param array $
clients list of auth client
s
*/
public
function
set
Providers
(
array
$provider
s
)
public
function
set
Clients
(
array
$client
s
)
{
$this
->
_
providers
=
$provider
s
;
$this
->
_
clients
=
$client
s
;
}
/**
* @return
ProviderInterface[] list of auth provider
s.
* @return
ClientInterface[] list of auth client
s.
*/
public
function
get
Provider
s
()
public
function
get
Client
s
()
{
$
provider
s
=
[];
foreach
(
$this
->
_
providers
as
$id
=>
$provider
)
{
$
providers
[
$id
]
=
$this
->
getProvider
(
$id
);
$
client
s
=
[];
foreach
(
$this
->
_
clients
as
$id
=>
$client
)
{
$
clients
[
$id
]
=
$this
->
getClient
(
$id
);
}
return
$
provider
s
;
return
$
client
s
;
}
/**
* @param string $id service id.
* @return
ProviderInterface auth service
instance.
* @throws InvalidParamException on non existing
provider
request.
* @return
ClientInterface auth client
instance.
* @throws InvalidParamException on non existing
client
request.
*/
public
function
get
Provider
(
$id
)
public
function
get
Client
(
$id
)
{
if
(
!
array_key_exists
(
$id
,
$this
->
_
provider
s
))
{
throw
new
InvalidParamException
(
"Unknown auth
provider
'
{
$id
}
'."
);
if
(
!
array_key_exists
(
$id
,
$this
->
_
client
s
))
{
throw
new
InvalidParamException
(
"Unknown auth
client
'
{
$id
}
'."
);
}
if
(
!
is_object
(
$this
->
_
provider
s
[
$id
]))
{
$this
->
_
providers
[
$id
]
=
$this
->
createProvider
(
$id
,
$this
->
_provider
s
[
$id
]);
if
(
!
is_object
(
$this
->
_
client
s
[
$id
]))
{
$this
->
_
clients
[
$id
]
=
$this
->
createClient
(
$id
,
$this
->
_client
s
[
$id
]);
}
return
$this
->
_
provider
s
[
$id
];
return
$this
->
_
client
s
[
$id
];
}
/**
* Checks if
provider
exists in the hub.
* @param string $id
provider
id.
* @return boolean whether
provider
exist.
* Checks if
client
exists in the hub.
* @param string $id
client
id.
* @return boolean whether
client
exist.
*/
public
function
has
Provider
(
$id
)
public
function
has
Client
(
$id
)
{
return
array_key_exists
(
$id
,
$this
->
_
provider
s
);
return
array_key_exists
(
$id
,
$this
->
_
client
s
);
}
/**
* Creates auth
provider
instance from its array configuration.
* @param string $id auth
provider
id.
* @param array $config auth
provider
instance configuration.
* @return
ProviderInterface auth provider
instance.
* Creates auth
client
instance from its array configuration.
* @param string $id auth
client
id.
* @param array $config auth
client
instance configuration.
* @return
ClientInterface auth client
instance.
*/
protected
function
create
Provider
(
$id
,
$config
)
protected
function
create
Client
(
$id
,
$config
)
{
$config
[
'id'
]
=
$id
;
return
Yii
::
createObject
(
$config
);
...
...
extensions/yii/authclient/OpenId.php
View file @
776a9250
...
...
@@ -27,7 +27,10 @@ use yii\base\NotSupportedException;
*/
class
OpenId
extends
Component
{
public
$required
=
[];
/**
* @var array list of attributes, which should be requested from server.
*/
public
$requiredAttributes
=
[];
public
$optional
=
[];
public
$verify_peer
;
public
$capath
;
...
...
@@ -501,9 +504,9 @@ class OpenId extends Component
# That's because it's fully backwards compatibile with 1.0, and some providers
# advertise 1.0 even if they accept only 1.1. One such provider is myopenid.com
$params
[
'openid.ns.sreg'
]
=
'http://openid.net/extensions/sreg/1.1'
;
if
(
$this
->
required
)
{
if
(
$this
->
required
Attributes
)
{
$params
[
'openid.sreg.required'
]
=
[];
foreach
(
$this
->
required
as
$required
)
{
foreach
(
$this
->
required
Attributes
as
$required
)
{
if
(
!
isset
(
self
::
$axToSregMap
[
$required
]))
{
continue
;
}
...
...
@@ -528,7 +531,7 @@ class OpenId extends Component
protected
function
axParams
()
{
$params
=
[];
if
(
$this
->
required
||
$this
->
optional
)
{
if
(
$this
->
required
Attributes
||
$this
->
optional
)
{
$params
[
'openid.ns.ax'
]
=
'http://openid.net/srv/ax/1.0'
;
$params
[
'openid.ax.mode'
]
=
'fetch_request'
;
$this
->
aliases
=
[];
...
...
extensions/yii/authclient/provider/OAuth1.php
deleted
100644 → 0
View file @
1ef606da
<?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
;
/**
* Class OAuth1
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class
OAuth1
extends
\yii\authclient\OAuth1
implements
ProviderInterface
{
use
ProviderTrait
;
/**
* @inheritdoc
*/
public
function
authenticate
()
{
// user denied error
if
(
isset
(
$_GET
[
'denied'
]))
{
return
$this
->
redirectCancel
();
}
if
(
isset
(
$_REQUEST
[
'oauth_token'
]))
{
$oauthToken
=
$_REQUEST
[
'oauth_token'
];
}
if
(
!
isset
(
$oauthToken
))
{
// Get request token.
$requestToken
=
$this
->
fetchRequestToken
();
// Get authorization URL.
$url
=
$this
->
buildAuthUrl
(
$requestToken
);
// Redirect to authorization URL.
return
Yii
::
$app
->
getResponse
()
->
redirect
(
$url
);
}
else
{
// Upgrade to access token.
$accessToken
=
$this
->
fetchAccessToken
();
$this
->
isAuthenticated
=
true
;
}
return
$this
->
isAuthenticated
;
}
}
\ No newline at end of file
extensions/yii/authclient/provider/OAuth2.php
deleted
100644 → 0
View file @
1ef606da
<?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\base\Exception
;
/**
* Class OAuth2
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class
OAuth2
extends
\yii\authclient\OAuth2
implements
ProviderInterface
{
use
ProviderTrait
;
/**
* @inheritdoc
*/
public
function
authenticate
()
{
if
(
isset
(
$_GET
[
'error'
]))
{
if
(
$_GET
[
'error'
]
==
'access_denied'
)
{
// user denied error
return
$this
->
redirectCancel
();
}
else
{
// request error
if
(
isset
(
$_GET
[
'error_description'
]))
{
$errorMessage
=
$_GET
[
'error_description'
];
}
elseif
(
isset
(
$_GET
[
'error_message'
]))
{
$errorMessage
=
$_GET
[
'error_message'
];
}
else
{
$errorMessage
=
http_build_query
(
$_GET
);
}
throw
new
Exception
(
'Auth error: '
.
$errorMessage
);
}
}
// Get the access_token and save them to the session.
if
(
isset
(
$_GET
[
'code'
]))
{
$code
=
$_GET
[
'code'
];
$token
=
$this
->
fetchAccessToken
(
$code
);
if
(
!
empty
(
$token
))
{
$this
->
isAuthenticated
=
true
;
}
}
else
{
$url
=
$this
->
buildAuthUrl
();
return
Yii
::
$app
->
getResponse
()
->
redirect
(
$url
);
}
return
$this
->
isAuthenticated
;
}
}
\ No newline at end of file
extensions/yii/authclient/provider/OpenId.php
deleted
100644 → 0
View file @
1ef606da
<?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\base\Exception
;
use
yii\web\HttpException
;
/**
* Class OpenId
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class
OpenId
extends
\yii\authclient\OpenId
implements
ProviderInterface
{
use
ProviderTrait
;
/**
* @inheritdoc
*/
public
function
authenticate
()
{
if
(
!
empty
(
$_REQUEST
[
'openid_mode'
]))
{
switch
(
$_REQUEST
[
'openid_mode'
])
{
case
'id_res'
:
if
(
$this
->
validate
())
{
$attributes
=
array
(
'id'
=>
$this
->
identity
);
$rawAttributes
=
$this
->
getAttributes
();
foreach
(
$this
->
getRequiredAttributes
()
as
$openIdAttributeName
)
{
if
(
isset
(
$rawAttributes
[
$openIdAttributeName
]))
{
$attributes
[
$openIdAttributeName
]
=
$rawAttributes
[
$openIdAttributeName
];
}
else
{
throw
new
Exception
(
'Unable to complete the authentication because the required data was not received.'
);
}
}
$this
->
setAttributes
(
$attributes
);
$this
->
isAuthenticated
=
true
;
return
true
;
}
else
{
throw
new
Exception
(
'Unable to complete the authentication because the required data was not received.'
);
}
break
;
case
'cancel'
:
$this
->
redirectCancel
();
break
;
default
:
throw
new
HttpException
(
400
);
break
;
}
}
else
{
$this
->
identity
=
$this
->
authUrl
;
// Setting identifier
$this
->
required
=
[];
// Try to get info from openid provider
foreach
(
$this
->
getRequiredAttributes
()
as
$openIdAttributeName
)
{
$this
->
required
[]
=
$openIdAttributeName
;
}
$request
=
Yii
::
$app
->
getRequest
();
$this
->
realm
=
$request
->
getHostInfo
();
$this
->
returnUrl
=
$this
->
realm
.
$request
->
getUrl
();
// getting return URL
$url
=
$this
->
authUrl
();
return
Yii
::
$app
->
getResponse
()
->
redirect
(
$url
);
}
return
false
;
}
}
\ No newline at end of file
extensions/yii/authclient/
provider/
views/redirect.php
→
extensions/yii/authclient/views/redirect.php
View file @
776a9250
File moved
tests/unit/extensions/authclient/
provider/Provider
TraitTest.php
→
tests/unit/extensions/authclient/
Client
TraitTest.php
View file @
776a9250
<?php
namespace
yiiunit\extensions\authclient
\provider
;
namespace
yiiunit\extensions\authclient
;
use
yii\authclient\provider\ProviderInterface
;
use
yii\authclient\provider\ProviderTrait
;
use
yii\authclient\ClientInterface
;
use
yii\authclient\ClientTrait
;
use
yii\base\Object
;
use
yiiunit\extensions\authclient\TestCase
;
class
Provider
TraitTest
extends
TestCase
class
Client
TraitTest
extends
TestCase
{
protected
function
setUp
()
{
...
...
@@ -28,63 +26,33 @@ class ProviderTraitTest extends TestCase
public
function
testSetGet
()
{
$provider
=
new
Provider
();
$provider
=
new
Client
();
$id
=
'test_
service_
id'
;
$id
=
'test_id'
;
$provider
->
setId
(
$id
);
$this
->
assertEquals
(
$id
,
$provider
->
getId
(),
'Unable to setup id!'
);
$
successUrl
=
'http://test.success.url
'
;
$provider
->
set
SuccessUrl
(
$successUrl
);
$this
->
assertEquals
(
$
successUrl
,
$provider
->
getSuccessUrl
(),
'Unable to setup success URL
!'
);
$
name
=
'test_name
'
;
$provider
->
set
Name
(
$name
);
$this
->
assertEquals
(
$
name
,
$provider
->
getName
(),
'Unable to setup name
!'
);
$
cancelUrl
=
'http://test.cancel.url
'
;
$provider
->
set
CancelUrl
(
$cancelUrl
);
$this
->
assertEquals
(
$
cancelUrl
,
$provider
->
getCancelUrl
(),
'Unable to setup cancel URL
!'
);
$
title
=
'test_title
'
;
$provider
->
set
Title
(
$title
);
$this
->
assertEquals
(
$
title
,
$provider
->
getTitle
(),
'Unable to setup title
!'
);
}
public
function
testGetDescriptiveData
()
{
$provider
=
new
Provider
();
$provider
=
new
Client
();
$this
->
assertNotEmpty
(
$provider
->
getName
(),
'Unable to get name!'
);
$this
->
assertNotEmpty
(
$provider
->
getTitle
(),
'Unable to get title!'
);
}
/**
* @depends testSetGet
*/
public
function
testGetDefaultSuccessUrl
()
{
$provider
=
new
Provider
();
$this
->
assertNotEmpty
(
$provider
->
getSuccessUrl
(),
'Unable to get default success URL!'
);
}
/**
* @depends testSetGet
*/
public
function
testGetDefaultCancelUrl
()
{
$provider
=
new
Provider
();
$this
->
assertNotEmpty
(
$provider
->
getSuccessUrl
(),
'Unable to get default cancel URL!'
);
}
public
function
testRedirect
()
{
$provider
=
new
Provider
();
$url
=
'http://test.url'
;
$response
=
$provider
->
redirect
(
$url
,
true
);
$this
->
assertContains
(
$url
,
$response
->
content
);
}
}
class
Provider
extends
Object
implements
Provider
Interface
class
Client
extends
Object
implements
Client
Interface
{
use
Provider
Trait
;
use
Client
Trait
;
public
function
authenticate
()
{}
}
\ No newline at end of file
tests/unit/extensions/authclient/
provider/
CollectionTest.php
→
tests/unit/extensions/authclient/CollectionTest.php
View file @
776a9250
<?php
namespace
yiiunit\extensions\authclient
\provider
;
namespace
yiiunit\extensions\authclient
;
use
yii\authclient\
provider\
Collection
;
use
yii\authclient\
provider\Provider
Interface
;
use
yii\authclient\
provider\Provider
Trait
;
use
yii\authclient\Collection
;
use
yii\authclient\
Client
Interface
;
use
yii\authclient\
Client
Trait
;
use
yii\base\Object
;
use
yiiunit\extensions\authclient\TestCase
;
...
...
@@ -16,12 +16,12 @@ class CollectionTest extends TestCase
{
$collection
=
new
Collection
();
$
provider
s
=
[
'test
Provider1'
=>
new
TestProvider
(),
'test
Provider2'
=>
new
TestProvider
(),
$
client
s
=
[
'test
Client1'
=>
new
TestClient
(),
'test
Client2'
=>
new
TestClient
(),
];
$collection
->
set
Providers
(
$provider
s
);
$this
->
assertEquals
(
$
providers
,
$collection
->
getProviders
(),
'Unable to setup provider
s!'
);
$collection
->
set
Clients
(
$client
s
);
$this
->
assertEquals
(
$
clients
,
$collection
->
getClients
(),
'Unable to setup client
s!'
);
}
/**
...
...
@@ -31,14 +31,14 @@ class CollectionTest extends TestCase
{
$collection
=
new
Collection
();
$
providerId
=
'testProvider
Id'
;
$
provider
=
new
TestProvider
();
$
provider
s
=
[
$
providerId
=>
$provider
$
clientId
=
'testClient
Id'
;
$
client
=
new
TestClient
();
$
client
s
=
[
$
clientId
=>
$client
];
$collection
->
set
Providers
(
$provider
s
);
$collection
->
set
Clients
(
$client
s
);
$this
->
assertEquals
(
$
provider
,
$collection
->
getProvider
(
$providerId
),
'Unable to get provider
by id!'
);
$this
->
assertEquals
(
$
client
,
$collection
->
getClient
(
$clientId
),
'Unable to get client
by id!'
);
}
/**
...
...
@@ -48,18 +48,18 @@ class CollectionTest extends TestCase
{
$collection
=
new
Collection
();
$
providerId
=
'testProvider
Id'
;
$
providerClassName
=
TestProvider
::
className
();
$
provider
s
=
[
$
provider
Id
=>
[
'class'
=>
$
provider
ClassName
$
clientId
=
'testClient
Id'
;
$
clientClassName
=
TestClient
::
className
();
$
client
s
=
[
$
client
Id
=>
[
'class'
=>
$
client
ClassName
]
];
$collection
->
set
Providers
(
$provider
s
);
$collection
->
set
Clients
(
$client
s
);
$provider
=
$collection
->
get
Provider
(
$provider
Id
);
$this
->
assertTrue
(
is_object
(
$provider
),
'Unable to create
provider
by config!'
);
$this
->
assertTrue
(
is_a
(
$provider
,
$
providerClassName
),
'Provider
has wrong class name!'
);
$provider
=
$collection
->
get
Client
(
$client
Id
);
$this
->
assertTrue
(
is_object
(
$provider
),
'Unable to create
client
by config!'
);
$this
->
assertTrue
(
is_a
(
$provider
,
$
clientClassName
),
'Client
has wrong class name!'
);
}
/**
...
...
@@ -69,22 +69,22 @@ class CollectionTest extends TestCase
{
$collection
=
new
Collection
();
$
providerName
=
'testProvider
Name'
;
$
provider
s
=
[
$
provider
Name
=>
[
'class'
=>
'Test
Provider
1'
$
clientName
=
'testClient
Name'
;
$
client
s
=
[
$
client
Name
=>
[
'class'
=>
'Test
Client
1'
],
];
$collection
->
set
Providers
(
$provider
s
);
$collection
->
set
Clients
(
$client
s
);
$this
->
assertTrue
(
$collection
->
has
Provider
(
$providerName
),
'Existing provider
check fails!'
);
$this
->
assertFalse
(
$collection
->
has
Provider
(
'unExistingProviderName'
),
'Not existing provider
check fails!'
);
$this
->
assertTrue
(
$collection
->
has
Client
(
$clientName
),
'Existing client
check fails!'
);
$this
->
assertFalse
(
$collection
->
has
Client
(
'unExistingClientName'
),
'Not existing client
check fails!'
);
}
}
class
Test
Provider
extends
Object
implements
Provider
Interface
class
Test
Client
extends
Object
implements
Client
Interface
{
use
Provider
Trait
;
use
Client
Trait
;
public
function
authenticate
()
{}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment