|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SocialConnect project |
|
4
|
|
|
* @author: Patsura Dmitry https://github.com/ovr <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Test\Providers; |
|
8
|
|
|
|
|
9
|
|
|
use SocialConnect\Auth\Provider\Exception\InvalidAccessToken; |
|
10
|
|
|
use SocialConnect\Auth\Consumer; |
|
11
|
|
|
use SocialConnect\OAuth2\AccessToken; |
|
12
|
|
|
use SocialConnect\Common\Http\Client\ClientInterface; |
|
13
|
|
|
use Test\TestCase; |
|
14
|
|
|
|
|
15
|
|
|
class VkTest extends AbstractProviderTestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @param ClientInterface|null $httpClient |
|
19
|
|
|
* @return \SocialConnect\Auth\Provider\Vk |
|
20
|
|
|
*/ |
|
21
|
4 |
|
protected function getProvider(ClientInterface $httpClient = null) |
|
22
|
|
|
{ |
|
23
|
4 |
|
$service = new \SocialConnect\Auth\Service([]); |
|
24
|
|
|
|
|
25
|
4 |
|
if ($httpClient) { |
|
26
|
1 |
|
$service->setHttpClient($httpClient); |
|
27
|
1 |
|
} |
|
28
|
|
|
|
|
29
|
4 |
|
return new \SocialConnect\Auth\Provider\Vk( |
|
30
|
4 |
|
$service, |
|
31
|
4 |
|
new Consumer( |
|
32
|
4 |
|
'unknown', |
|
33
|
|
|
'unkwown' |
|
34
|
4 |
|
) |
|
35
|
4 |
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
1 |
|
public function testParseTokenSuccess() |
|
39
|
|
|
{ |
|
40
|
1 |
|
$expectedToken = 'XXXXXXXX'; |
|
41
|
1 |
|
$expectedUserId = 123456; |
|
42
|
|
|
|
|
43
|
1 |
|
$accessToken = $this->getProvider()->parseToken( |
|
44
|
1 |
|
json_encode( |
|
45
|
|
|
[ |
|
46
|
1 |
|
'access_token' => $expectedToken, |
|
47
|
|
|
'user_id' => $expectedUserId |
|
48
|
1 |
|
] |
|
49
|
1 |
|
) |
|
50
|
1 |
|
); |
|
51
|
|
|
|
|
52
|
1 |
|
parent::assertInstanceOf(AccessToken::class, $accessToken); |
|
|
|
|
|
|
53
|
1 |
|
parent::assertSame($expectedToken, $accessToken->getToken()); |
|
|
|
|
|
|
54
|
1 |
|
parent::assertSame($expectedUserId, $accessToken->getUserId()); |
|
|
|
|
|
|
55
|
1 |
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
public function testParseTokenNotToken() |
|
58
|
|
|
{ |
|
59
|
1 |
|
$this->setExpectedException(InvalidAccessToken::class); |
|
60
|
|
|
|
|
61
|
1 |
|
$accessToken = $this->getProvider()->parseToken( |
|
|
|
|
|
|
62
|
1 |
|
json_encode([]) |
|
63
|
1 |
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
1 |
|
public function testParseTokenNotValidJSON() |
|
67
|
|
|
{ |
|
68
|
1 |
|
$this->setExpectedException(InvalidAccessToken::class); |
|
69
|
|
|
|
|
70
|
1 |
|
$accessToken = $this->getProvider()->parseToken( |
|
|
|
|
|
|
71
|
|
|
'lelelelel' |
|
72
|
1 |
|
); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
public function testGetIdentitySuccess() |
|
76
|
|
|
{ |
|
77
|
1 |
|
$mockedHttpClient = $this->makeIdentityClientResponse( |
|
78
|
|
|
[ |
|
79
|
|
|
'response' => [ |
|
80
|
|
|
[ |
|
81
|
1 |
|
'id' => $expectedId = 12321312312312, |
|
82
|
1 |
|
'first_name' => $expectedFirstname = 'Dmitry', |
|
83
|
1 |
|
'last_name' => $expectedLastname = 'Patsura', |
|
84
|
|
|
] |
|
85
|
1 |
|
] |
|
86
|
1 |
|
] |
|
87
|
1 |
|
); |
|
88
|
|
|
|
|
89
|
1 |
|
$result = $this->getProvider($mockedHttpClient)->getIdentity( |
|
90
|
1 |
|
new AccessToken( |
|
91
|
|
|
[ |
|
92
|
|
|
'access_token' => '123456789' |
|
93
|
1 |
|
] |
|
94
|
1 |
|
) |
|
95
|
1 |
|
); |
|
96
|
|
|
|
|
97
|
1 |
|
parent::assertInstanceOf(\SocialConnect\Common\Entity\User::class, $result); |
|
|
|
|
|
|
98
|
1 |
|
parent::assertSame($expectedId, $result->id); |
|
|
|
|
|
|
99
|
1 |
|
parent::assertSame($expectedFirstname, $result->firstname); |
|
|
|
|
|
|
100
|
1 |
|
parent::assertSame($expectedLastname, $result->lastname); |
|
|
|
|
|
|
101
|
1 |
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.