Completed
Pull Request — master (#466)
by
unknown
03:34
created

testConstructCorrectInterfaceWithoutCustomUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace OAuthTest\Unit\OAuth2\Service;
4
5
use OAuth\Common\Token\TokenInterface;
6
use OAuth\OAuth2\Service\Wrike;
7
8
class WrikeTest extends \PHPUnit_Framework_TestCase
9
{
10
    /**
11
     * @covers OAuth\OAuth2\Service\Wrike::__construct
12
     */
13
    public function testConstructCorrectInterfaceWithoutCustomUri()
14
    {
15
        $service = new Wrike(
16
            $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
17
            $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
18
            $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
19
        );
20
21
        $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service);
22
    }
23
24
    /**
25
     * @covers OAuth\OAuth2\Service\Wrike::__construct
26
     */
27
    public function testConstructCorrectInstanceWithoutCustomUri()
28
    {
29
        $service = new Wrike(
30
            $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
31
            $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
32
            $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
33
        );
34
35
        $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service);
36
    }
37
38
    /**
39
     * @covers OAuth\OAuth2\Service\Wrike::__construct
40
     */
41
    public function testConstructCorrectInstanceWithCustomUri()
42
    {
43
        $service = new Wrike(
44
            $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
45
            $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
46
            $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),
47
            array(),
48
            $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface')
49
        );
50
51
        $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service);
52
    }
53
54
    /**
55
     * @covers OAuth\OAuth2\Service\Wrike::__construct
56
     * @covers OAuth\OAuth2\Service\Wrike::getAuthorizationEndpoint
57
     */
58
    public function testGetAuthorizationEndpoint()
59
    {
60
        $service = new Wrike(
61
            $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
62
            $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
63
            $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
64
        );
65
66
        $this->assertSame(
67
            'https://www.wrike.com/oauth2/authorize',
68
            $service->getAuthorizationEndpoint()->getAbsoluteUri()
69
        );
70
    }
71
72
    /**
73
     * @covers OAuth\OAuth2\Service\Wrike::__construct
74
     * @covers OAuth\OAuth2\Service\Wrike::getAccessTokenEndpoint
75
     */
76
    public function testGetAccessTokenEndpoint()
77
    {
78
        $service = new Wrike(
79
            $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
80
            $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),
81
            $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
82
        );
83
84
        $this->assertSame(
85
            'https://www.wrike.com/oauth2/token',
86
            $service->getAccessTokenEndpoint()->getAbsoluteUri()
87
        );
88
    }
89
90
	/**
91
	 * @covers OAuth\OAuth2\Service\Wrike::__construct
92
	 * @covers OAuth\OAuth2\Service\Wrike::parseAccessTokenResponse
93
	 */
94
	public function testParseAccessTokenResponseThrowsExceptionOnError()
95
	{
96
		$client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
97
		$client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"error":"errorcode"}'));
98
99
		$service = new Wrike(
100
			$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
101
			$client,
102
			$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
103
		);
104
105
		$this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException');
106
107
		$service->requestAccessToken('foo');
108
	}
109
110
	/**
111
	 * @covers OAuth\OAuth2\Service\Wrike::__construct
112
	 * @covers OAuth\OAuth2\Service\Wrike::parseAccessTokenResponse
113
	 */
114
	public function testParseAccessTokenResponseValidWithoutRefreshToken()
115
	{
116
		$client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
117
		$client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}'));
118
119
		$service = new Wrike(
120
			$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
121
			$client,
122
			$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
123
		);
124
125
		$this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo'));
126
	}
127
128
	/**
129
	 * @covers OAuth\OAuth2\Service\Wrike::__construct
130
	 * @covers OAuth\OAuth2\Service\Wrike::parseAccessTokenResponse
131
	 */
132
	public function testParseAccessTokenResponseValidWithRefreshToken()
133
	{
134
		$client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface');
135
		$client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}'));
136
137
		$service = new Wrike(
138
			$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),
139
			$client,
140
			$this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface')
141
		);
142
143
		$this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo'));
144
	}
145
}
146