Passed
Push — master ( 27dd3a...31fea7 )
by Alex
06:49 queued 02:55
created

OKUnitTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 104
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testDispatchUserInfo() 0 21 1
A getSettings() 0 7 1
A testGetUserInfoUri() 0 8 1
A testGetTokenUri() 0 9 1
A testGetOauthUri() 0 11 1
A testGetTokenParams() 0 14 1
1
<?php
2
namespace Mezon\SocialNetwork\Auth\Tests;
3
4
use PHPUnit\Framework\TestCase;
5
use Mezon\SocialNetwork\Auth\Odnoklassniki;
6
7
class OKUnitTest extends TestCase
8
{
9
10
    /**
11
     * Method returns fake settings
12
     *
13
     * @return array fake settings
14
     */
15
    protected function getSettings(): array
16
    {
17
        return ([
18
            'client_id' => 1,
19
            'client_secret' => 2,
20
            'redirect_uri' => 3,
21
            'client_public' => 4
22
        ]);
23
    }
24
25
    /**
26
     * Testing getUserInfoUri
27
     */
28
    public function testGetUserInfoUri()
29
    {
30
        // setup
31
        $auth = new Odnoklassniki($this->getSettings());
32
33
        // test body and assertions
34
        $this->assertStringContainsString('/api.odnoklassniki.ru/fb.do?application_key=', $auth->getUserInfoUri());
35
        $this->assertStringContainsString('?application_key=4', $auth->getUserInfoUri());
36
    }
37
38
    /**
39
     * Testing getTokenUri
40
     */
41
    public function testGetTokenUri()
42
    {
43
        // setup
44
        $auth = new Odnoklassniki($this->getSettings());
45
46
        // test body and assertions
47
        $this->assertStringContainsString(
48
            '/api.odnoklassniki.ru/oauth/token.do?grant_type=authorization_code&',
49
            $auth->getTokenUri());
50
    }
51
52
    /**
53
     * Testing dispatchUserInfo
54
     */
55
    public function testDispatchUserInfo()
56
    {
57
        // setup
58
        $auth = new Odnoklassniki($this->getSettings());
59
60
        // test body
61
        $result = $auth->dispatchUserInfo(
62
            [
63
                'uid' => '',
64
                'first_name' => '',
65
                'last_name' => '',
66
                'pic190x190' => '',
67
                'email' => ''
68
            ]);
69
70
        // assertions
71
        $this->assertArrayHasKey('id', $result, 'id was not found');
72
        $this->assertArrayHasKey('first_name', $result, 'first_name was not found');
73
        $this->assertArrayHasKey('last_name', $result, 'last_name was not found');
74
        $this->assertArrayHasKey('picture', $result, 'picture was not found');
75
        $this->assertArrayHasKey('email', $result, 'email was not found');
76
    }
77
78
    /**
79
     * Testing getTokenParams method
80
     */
81
    public function testGetTokenParams()
82
    {
83
        // setup
84
        $auth = new Odnoklassniki($this->getSettings());
85
86
        // test body
87
        $params = $auth->getTokenParams(123);
88
89
        // assertions
90
        $this->assertEquals(1, $params['client_id'], 'Invalid "client_id"');
91
        $this->assertEquals(2, $params['client_secret'], 'Invalid "client_secret"');
92
        $this->assertEquals(3, $params['redirect_uri'], 'Invalid "redirect_uri"');
93
        $this->assertEquals('authorization_code', $params['grant_type'], 'Invalid "grant_type"');
94
        $this->assertEquals(123, $params['code'], 'Invalid "code"');
95
    }
96
97
    /**
98
     * Testing method getOauthUri
99
     */
100
    public function testGetOauthUri(): void
101
    {
102
        // setup
103
        $auth = new Odnoklassniki($this->getSettings());
104
105
        // test body
106
        $result = $auth->getOauthUri();
107
108
        // assertions
109
        $this->assertStringContainsString('https://connect.ok.ru/', $result);
110
        $this->assertStringContainsString('?scope=VALUABLE_ACCESS;PHOTO_CONTENT&', $result);
111
    }
112
}
113