1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuthTest\Unit\OAuth1\Service; |
4
|
|
|
|
5
|
|
|
use OAuth\OAuth1\Service\Xing; |
6
|
|
|
|
7
|
|
|
class XingTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
private $client; |
10
|
|
|
private $storage; |
11
|
|
|
private $xing; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
protected function setUp() |
15
|
|
|
{ |
16
|
|
|
parent::setUp(); |
17
|
|
|
|
18
|
|
|
$this->client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); |
19
|
|
|
$this->storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); |
20
|
|
|
|
21
|
|
|
$this->xing = new Xing( |
22
|
|
|
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
23
|
|
|
$this->client, |
24
|
|
|
$this->storage, |
25
|
|
|
$this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface') |
26
|
|
|
); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @covers OAuth\OAuth1\Service\Xing::__construct |
31
|
|
|
*/ |
32
|
|
|
public function testConstructCorrectInterfaceWithoutCustomUri() |
33
|
|
|
{ |
34
|
|
|
$this->assertInstanceOf( |
35
|
|
|
'\\OAuth\\OAuth1\\Service\\ServiceInterface', $this->xing |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @covers OAuth\OAuth1\Service\Xing::__construct |
41
|
|
|
*/ |
42
|
|
|
public function testConstructCorrectInstanceWithoutCustomUri() |
43
|
|
|
{ |
44
|
|
|
$this->assertInstanceOf( |
45
|
|
|
'\\OAuth\\OAuth1\\Service\\AbstractService', $this->xing |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @covers OAuth\OAuth1\Service\Xing::__construct |
51
|
|
|
*/ |
52
|
|
|
public function testConstructCorrectInstanceWithCustomUri() |
53
|
|
|
{ |
54
|
|
|
$service = new Xing( |
55
|
|
|
$this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), |
56
|
|
|
$this->client, |
57
|
|
|
$this->storage, |
58
|
|
|
$this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'), |
59
|
|
|
$this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$this->assertInstanceOf('\\OAuth\\OAuth1\\Service\\AbstractService', $service); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @covers OAuth\OAuth1\Service\Xing::__construct |
67
|
|
|
* @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint |
68
|
|
|
*/ |
69
|
|
|
public function testGetRequestTokenEndpoint() |
70
|
|
|
{ |
71
|
|
|
$this->assertSame( |
72
|
|
|
'https://api.xing.com/v1/request_token', |
73
|
|
|
$this->xing->getRequestTokenEndpoint()->getAbsoluteUri() |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @covers OAuth\OAuth1\Service\Xing::__construct |
79
|
|
|
* @covers OAuth\OAuth1\Service\Xing::getAuthorizationEndpoint |
80
|
|
|
*/ |
81
|
|
|
public function testGetAuthorizationEndpoint() |
82
|
|
|
{ |
83
|
|
|
$this->assertSame( |
84
|
|
|
'https://api.xing.com/v1/authorize', |
85
|
|
|
$this->xing->getAuthorizationEndpoint()->getAbsoluteUri() |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @covers OAuth\OAuth1\Service\Xing::__construct |
91
|
|
|
* @covers OAuth\OAuth1\Service\Xing::getAccessTokenEndpoint |
92
|
|
|
*/ |
93
|
|
|
public function testGetAccessTokenEndpoint() |
94
|
|
|
{ |
95
|
|
|
$this->assertSame( |
96
|
|
|
'https://api.xing.com/v1/access_token', |
97
|
|
|
$this->xing->getAccessTokenEndpoint()->getAbsoluteUri() |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @covers OAuth\OAuth1\Service\Xing::__construct |
103
|
|
|
* @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint |
104
|
|
|
* @covers OAuth\OAuth1\Service\Xing::parseRequestTokenResponse |
105
|
|
|
*/ |
106
|
|
|
public function testParseRequestTokenResponseThrowsExceptionOnNulledResponse() |
107
|
|
|
{ |
108
|
|
|
$this->client |
109
|
|
|
->expects($this->once()) |
110
|
|
|
->method('retrieveResponse') |
111
|
|
|
->will($this->returnValue(null)); |
112
|
|
|
|
113
|
|
|
$this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); |
114
|
|
|
|
115
|
|
|
$this->xing->requestRequestToken(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @covers OAuth\OAuth1\Service\Xing::__construct |
120
|
|
|
* @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint |
121
|
|
|
* @covers OAuth\OAuth1\Service\Xing::parseRequestTokenResponse |
122
|
|
|
*/ |
123
|
|
|
public function testParseRequestTokenResponseThrowsExceptionOnResponseNotAnArray() |
124
|
|
|
{ |
125
|
|
|
$this->client |
126
|
|
|
->expects($this->once()) |
127
|
|
|
->method('retrieveResponse') |
128
|
|
|
->will($this->returnValue('notanarray')); |
129
|
|
|
|
130
|
|
|
$this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); |
131
|
|
|
|
132
|
|
|
$this->xing->requestRequestToken(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @covers OAuth\OAuth1\Service\Xing::__construct |
137
|
|
|
* @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint |
138
|
|
|
* @covers OAuth\OAuth1\Service\Xing::parseRequestTokenResponse |
139
|
|
|
*/ |
140
|
|
|
public function testParseRequestTokenResponseThrowsExceptionOnResponseCallbackNotSet() |
141
|
|
|
{ |
142
|
|
|
$this->client |
143
|
|
|
->expects($this->once()) |
144
|
|
|
->method('retrieveResponse') |
145
|
|
|
->will($this->returnValue('foo=bar')); |
146
|
|
|
|
147
|
|
|
$this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); |
148
|
|
|
|
149
|
|
|
$this->xing->requestRequestToken(); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @covers OAuth\OAuth1\Service\Xing::__construct |
154
|
|
|
* @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint |
155
|
|
|
* @covers OAuth\OAuth1\Service\Xing::parseRequestTokenResponse |
156
|
|
|
*/ |
157
|
|
|
public function testParseRequestTokenResponseThrowsExceptionOnResponseCallbackNotTrue() |
158
|
|
|
{ |
159
|
|
|
$this->client |
160
|
|
|
->expects($this->once()) |
161
|
|
|
->method('retrieveResponse') |
162
|
|
|
->will($this->returnValue('oauth_callback_confirmed=false')); |
163
|
|
|
|
164
|
|
|
$this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); |
165
|
|
|
|
166
|
|
|
$this->xing->requestRequestToken(); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @covers OAuth\OAuth1\Service\Xing::__construct |
171
|
|
|
* @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint |
172
|
|
|
* @covers OAuth\OAuth1\Service\Xing::parseRequestTokenResponse |
173
|
|
|
* @covers OAuth\OAuth1\Service\Xing::parseAccessTokenResponse |
174
|
|
|
*/ |
175
|
|
|
public function testParseRequestTokenResponseValid() |
176
|
|
|
{ |
177
|
|
|
$this->client |
178
|
|
|
->expects($this->once()) |
179
|
|
|
->method('retrieveResponse') |
180
|
|
|
->will($this->returnValue( |
181
|
|
|
'oauth_callback_confirmed=true&oauth_token=foo&oauth_token_secret=bar' |
182
|
|
|
)); |
183
|
|
|
|
184
|
|
|
$this->assertInstanceOf( |
185
|
|
|
'\\OAuth\\OAuth1\\Token\\StdOAuth1Token', |
186
|
|
|
$this->xing->requestRequestToken() |
187
|
|
|
); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @covers OAuth\OAuth1\Service\Xing::__construct |
192
|
|
|
* @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint |
193
|
|
|
* @covers OAuth\OAuth1\Service\Xing::parseAccessTokenResponse |
194
|
|
|
*/ |
195
|
|
|
public function testParseAccessTokenResponseThrowsExceptionOnError() |
196
|
|
|
{ |
197
|
|
|
$this->client |
198
|
|
|
->expects($this->once()) |
199
|
|
|
->method('retrieveResponse') |
200
|
|
|
->will($this->returnValue('{"message":"Invalid OAuth signature","error_name":"INVALID_OAUTH_SIGNATURE"}')); |
201
|
|
|
|
202
|
|
|
$token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface'); |
203
|
|
|
|
204
|
|
|
$this->storage |
205
|
|
|
->expects($this->any()) |
206
|
|
|
->method('retrieveAccessToken') |
207
|
|
|
->will($this->returnValue($token)); |
208
|
|
|
|
209
|
|
|
$this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); |
210
|
|
|
|
211
|
|
|
$this->xing->requestAccessToken('foo', 'bar', $token); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @covers OAuth\OAuth1\Service\Xing::__construct |
216
|
|
|
* @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint |
217
|
|
|
* @covers OAuth\OAuth1\Service\Xing::parseAccessTokenResponse |
218
|
|
|
*/ |
219
|
|
|
public function testParseAccessTokenResponseValid() |
220
|
|
|
{ |
221
|
|
|
$this->client |
222
|
|
|
->expects($this->once()) |
223
|
|
|
->method('retrieveResponse') |
224
|
|
|
->will($this->returnValue('oauth_token=foo&oauth_token_secret=bar')); |
225
|
|
|
|
226
|
|
|
$token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface'); |
227
|
|
|
|
228
|
|
|
$this->storage |
229
|
|
|
->expects($this->any()) |
230
|
|
|
->method('retrieveAccessToken') |
231
|
|
|
->will($this->returnValue($token)); |
232
|
|
|
|
233
|
|
|
|
234
|
|
|
$this->assertInstanceOf( |
235
|
|
|
'\\OAuth\\OAuth1\\Token\\StdOAuth1Token', |
236
|
|
|
$this->xing->requestAccessToken('foo', 'bar', $token) |
237
|
|
|
); |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|