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