1
|
|
|
<?php
|
2
|
|
|
namespace Mezon\SocialNetwork\Auth\Tests;
|
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase;
|
5
|
|
|
use Mezon\SocialNetwork\Auth\Vkontakte;
|
6
|
|
|
|
7
|
|
|
/**
|
8
|
|
|
*
|
9
|
|
|
* @psalm-suppress PropertyNotSetInConstructor
|
10
|
|
|
*/
|
11
|
|
|
class VKAuthUnitTest extends TestCase
|
12
|
|
|
{
|
13
|
|
|
|
14
|
|
|
/**
|
15
|
|
|
* Method returns fake settings
|
16
|
|
|
*
|
17
|
|
|
* @return array fake settings
|
18
|
|
|
*/
|
19
|
|
|
protected function getSettings(): array
|
20
|
|
|
{
|
21
|
|
|
return ([
|
22
|
|
|
'client_id' => 1,
|
23
|
|
|
'client_secret' => 2,
|
24
|
|
|
'redirect_uri' => 3
|
25
|
|
|
]);
|
26
|
|
|
}
|
27
|
|
|
|
28
|
|
|
/**
|
29
|
|
|
* Testing getUserInfoUri
|
30
|
|
|
*/
|
31
|
|
|
public function testGetUerInfoUri(): void
|
32
|
|
|
{
|
33
|
|
|
// setup
|
34
|
|
|
$auth = new Vkontakte($this->getSettings());
|
35
|
|
|
|
36
|
|
|
// test body and assertions
|
37
|
|
|
$this->assertStringContainsString('/api.vk.com/method/users.get?v=', $auth->getUserInfoUri());
|
38
|
|
|
}
|
39
|
|
|
|
40
|
|
|
/**
|
41
|
|
|
* Testing getTokenUri
|
42
|
|
|
*/
|
43
|
|
|
public function testGetTokenUri(): void
|
44
|
|
|
{
|
45
|
|
|
// setup
|
46
|
|
|
$auth = new Vkontakte($this->getSettings());
|
47
|
|
|
|
48
|
|
|
// test body and assertions
|
49
|
|
|
$this->assertStringContainsString('/oauth.vk.com/access_token?v=', $auth->getTokenUri());
|
50
|
|
|
}
|
51
|
|
|
|
52
|
|
|
/**
|
53
|
|
|
* Testing getDesiredFields
|
54
|
|
|
*/
|
55
|
|
|
public function testGetDesiredFields(): void
|
56
|
|
|
{
|
57
|
|
|
// setup
|
58
|
|
|
$auth = new Vkontakte($this->getSettings());
|
59
|
|
|
|
60
|
|
|
// test body
|
61
|
|
|
$fields = $auth->getDesiredFields();
|
62
|
|
|
|
63
|
|
|
// assertions
|
64
|
|
|
$this->assertStringContainsString('id', $fields);
|
65
|
|
|
$this->assertStringContainsString('first_name', $fields);
|
66
|
|
|
$this->assertStringContainsString('last_name', $fields);
|
67
|
|
|
$this->assertStringContainsString('email', $fields);
|
68
|
|
|
$this->assertStringContainsString('photo_100', $fields);
|
69
|
|
|
}
|
70
|
|
|
|
71
|
|
|
/**
|
72
|
|
|
* Testing dispatchUserInfo
|
73
|
|
|
*/
|
74
|
|
|
public function testDispatchUserInfo(): void
|
75
|
|
|
{
|
76
|
|
|
// setup
|
77
|
|
|
$auth = new Vkontakte($this->getSettings());
|
78
|
|
|
|
79
|
|
|
// test body
|
80
|
|
|
$result = $auth->dispatchUserInfo(
|
81
|
|
|
[
|
82
|
|
|
'response' => [
|
83
|
|
|
[
|
84
|
|
|
'id' => '',
|
85
|
|
|
'first_name' => '',
|
86
|
|
|
'last_name' => '',
|
87
|
|
|
'photo_100' => '',
|
88
|
|
|
'email' => ''
|
89
|
|
|
]
|
90
|
|
|
]
|
91
|
|
|
]);
|
92
|
|
|
|
93
|
|
|
// assertions
|
94
|
|
|
$this->assertArrayHasKey('id', $result, 'id was not found');
|
95
|
|
|
$this->assertArrayHasKey('first_name', $result, 'first_name was not found');
|
96
|
|
|
$this->assertArrayHasKey('last_name', $result, 'last_name was not found');
|
97
|
|
|
$this->assertArrayHasKey('picture', $result, 'picture was not found');
|
98
|
|
|
$this->assertArrayHasKey('email', $result, 'email was not found');
|
99
|
|
|
}
|
100
|
|
|
|
101
|
|
|
/**
|
102
|
|
|
* Testing method getOauthUri
|
103
|
|
|
*/
|
104
|
|
|
public function testGetOauthUri(): void
|
105
|
|
|
{
|
106
|
|
|
// setup
|
107
|
|
|
$auth = new Vkontakte($this->getSettings());
|
108
|
|
|
|
109
|
|
|
// test body and assertions
|
110
|
|
|
$this->assertEquals('https://oauth.vk.com/authorize?v=5.0&', $auth->getOauthUri());
|
111
|
|
|
}
|
112
|
|
|
}
|
113
|
|
|
|