1
1
<?php
2
2
3
- require_once (__DIR__ . '/../lib/OAuth2.php ' );
4
- require_once (__DIR__ . '/../lib/IOAuth2Storage.php ' );
5
- require_once (__DIR__ . '/../lib/IOAuth2GrantCode.php ' );
3
+ use OAuth2 \OAuth2 ;
4
+ use OAuth2 \OAuth2ServerException ;
6
5
7
6
/**
8
7
* OAuth2 test case.
@@ -24,11 +23,11 @@ class OAuth2Test extends PHPUnit_Framework_TestCase {
24
23
* Tests OAuth2->verifyAccessToken() with a missing token
25
24
*/
26
25
public function testVerifyAccessTokenWithNoParam () {
27
- $ mockStorage = $ this ->getMock ('IOAuth2Storage ' );
26
+ $ mockStorage = $ this ->getMock ('OAuth2\ IOAuth2Storage ' );
28
27
$ this ->fixture = new OAuth2 ($ mockStorage );
29
28
30
29
$ scope = null ;
31
- $ this ->setExpectedException ('OAuth2AuthenticateException ' );
30
+ $ this ->setExpectedException ('OAuth2\ OAuth2AuthenticateException ' );
32
31
$ this ->fixture ->verifyAccessToken ('' , $ scope );
33
32
}
34
33
@@ -38,15 +37,15 @@ public function testVerifyAccessTokenWithNoParam() {
38
37
public function testVerifyAccessTokenInvalidToken () {
39
38
40
39
// Set up the mock storage to say this token does not exist
41
- $ mockStorage = $ this ->getMock ('IOAuth2Storage ' );
40
+ $ mockStorage = $ this ->getMock ('OAuth2\ IOAuth2Storage ' );
42
41
$ mockStorage ->expects ($ this ->once ())
43
42
->method ('getAccessToken ' )
44
43
->will ($ this ->returnValue (false ));
45
44
46
45
$ this ->fixture = new OAuth2 ($ mockStorage );
47
46
48
47
$ scope = null ;
49
- $ this ->setExpectedException ('OAuth2AuthenticateException ' );
48
+ $ this ->setExpectedException ('OAuth2\ OAuth2AuthenticateException ' );
50
49
$ this ->fixture ->verifyAccessToken ($ this ->tokenId , $ scope );
51
50
}
52
51
@@ -58,15 +57,15 @@ public function testVerifyAccessTokenInvalidToken() {
58
57
public function testVerifyAccessTokenMalformedToken ($ token ) {
59
58
60
59
// Set up the mock storage to say this token does not exist
61
- $ mockStorage = $ this ->getMock ('IOAuth2Storage ' );
60
+ $ mockStorage = $ this ->getMock ('OAuth2\ IOAuth2Storage ' );
62
61
$ mockStorage ->expects ($ this ->once ())
63
62
->method ('getAccessToken ' )
64
63
->will ($ this ->returnValue ($ token ));
65
64
66
65
$ this ->fixture = new OAuth2 ($ mockStorage );
67
66
68
67
$ scope = null ;
69
- $ this ->setExpectedException ('OAuth2AuthenticateException ' );
68
+ $ this ->setExpectedException ('OAuth2\ OAuth2AuthenticateException ' );
70
69
$ this ->fixture ->verifyAccessToken ($ this ->tokenId , $ scope );
71
70
}
72
71
@@ -78,7 +77,7 @@ public function testVerifyAccessTokenMalformedToken($token) {
78
77
public function testVerifyAccessTokenCheckExpiry ($ token , $ expectedToPass ) {
79
78
80
79
// Set up the mock storage to say this token does not exist
81
- $ mockStorage = $ this ->getMock ('IOAuth2Storage ' );
80
+ $ mockStorage = $ this ->getMock ('OAuth2\ IOAuth2Storage ' );
82
81
$ mockStorage ->expects ($ this ->once ())
83
82
->method ('getAccessToken ' )
84
83
->will ($ this ->returnValue ($ token ));
@@ -95,7 +94,7 @@ public function testVerifyAccessTokenCheckExpiry($token, $expectedToPass) {
95
94
$ this ->assertInternalType ('array ' , $ actual );
96
95
}
97
96
else {
98
- $ this ->setExpectedException ('OAuth2AuthenticateException ' );
97
+ $ this ->setExpectedException ('OAuth2\ OAuth2AuthenticateException ' );
99
98
$ this ->fixture ->verifyAccessToken ($ this ->tokenId , $ scope );
100
99
}
101
100
}
@@ -108,7 +107,7 @@ public function testVerifyAccessTokenCheckExpiry($token, $expectedToPass) {
108
107
public function testVerifyAccessTokenCheckScope ($ scopeRequired , $ token , $ expectedToPass ) {
109
108
110
109
// Set up the mock storage to say this token does not exist
111
- $ mockStorage = $ this ->getMock ('IOAuth2Storage ' );
110
+ $ mockStorage = $ this ->getMock ('OAuth2\ IOAuth2Storage ' );
112
111
$ mockStorage ->expects ($ this ->once ())
113
112
->method ('getAccessToken ' )
114
113
->will ($ this ->returnValue ($ token ));
@@ -122,7 +121,7 @@ public function testVerifyAccessTokenCheckScope($scopeRequired, $token, $expecte
122
121
$ this ->assertInternalType ('array ' , $ actual );
123
122
}
124
123
else {
125
- $ this ->setExpectedException ('OAuth2AuthenticateException ' );
124
+ $ this ->setExpectedException ('OAuth2\ OAuth2AuthenticateException ' );
126
125
$ this ->fixture ->verifyAccessToken ($ this ->tokenId , $ scopeRequired );
127
126
}
128
127
}
@@ -133,10 +132,10 @@ public function testVerifyAccessTokenCheckScope($scopeRequired, $token, $expecte
133
132
* @dataProvider generateEmptyDataForGrant
134
133
*/
135
134
public function testGrantAccessTokenMissingData ($ inputData , $ authHeaders ) {
136
- $ mockStorage = $ this ->getMock ('IOAuth2Storage ' );
135
+ $ mockStorage = $ this ->getMock ('OAuth2\ IOAuth2Storage ' );
137
136
$ this ->fixture = new OAuth2 ($ mockStorage );
138
137
139
- $ this ->setExpectedException ('OAuth2ServerException ' );
138
+ $ this ->setExpectedException ('OAuth2\ OAuth2ServerException ' );
140
139
$ this ->fixture ->grantAccessToken ($ inputData , $ authHeaders );
141
140
}
142
141
@@ -146,7 +145,7 @@ public function testGrantAccessTokenMissingData($inputData, $authHeaders) {
146
145
* Tests the different ways client credentials can be provided.
147
146
*/
148
147
public function testGrantAccessTokenCheckClientCredentials () {
149
- $ mockStorage = $ this ->getMock ('IOAuth2Storage ' );
148
+ $ mockStorage = $ this ->getMock ('OAuth2\ IOAuth2Storage ' );
150
149
$ mockStorage ->expects ($ this ->any ())
151
150
->method ('checkClientCredentials ' )
152
151
->will ($ this ->returnValue (TRUE )); // Always return true for any combination of user/pass
@@ -189,7 +188,7 @@ public function testGrantAccessTokenCheckClientCredentials() {
189
188
*
190
189
*/
191
190
public function testGrantAccessTokenWithGrantAuthCodeMandatoryParams () {
192
- $ mockStorage = $ this ->createBaseMock ('IOAuth2GrantCode ' );
191
+ $ mockStorage = $ this ->createBaseMock ('OAuth2\ IOAuth2GrantCode ' );
193
192
$ inputData = array ('grant_type ' => OAuth2::GRANT_TYPE_AUTH_CODE , 'client_id ' => 'a ' , 'client_secret ' => 'b ' );
194
193
$ fakeAuthCode = array ('client_id ' => $ inputData ['client_id ' ], 'redirect_uri ' => '/foo ' , 'expires ' => time () + 60 );
195
194
$ fakeAccessToken = array ('access_token ' => 'abcde ' );
@@ -217,7 +216,7 @@ public function testGrantAccessTokenWithGrantAuthCodeMandatoryParams() {
217
216
*
218
217
*/
219
218
public function testGrantAccessTokenWithGrantAuthCodeNoToken () {
220
- $ mockStorage = $ this ->createBaseMock ('IOAuth2GrantCode ' );
219
+ $ mockStorage = $ this ->createBaseMock ('OAuth2\ IOAuth2GrantCode ' );
221
220
$ inputData = array ('grant_type ' => OAuth2::GRANT_TYPE_AUTH_CODE , 'client_id ' => 'a ' , 'client_secret ' => 'b ' , 'redirect_uri ' => 'foo ' , 'code ' => 'foo ' );
222
221
223
222
// Ensure missing auth code raises an error
@@ -239,7 +238,7 @@ public function testGrantAccessTokenWithGrantAuthCodeRedirectChecked() {
239
238
$ inputData = array ('redirect_uri ' => 'http://www.crossdomain.com/my/subdir ' , 'grant_type ' => OAuth2::GRANT_TYPE_AUTH_CODE , 'client_id ' => 'my_little_app ' , 'client_secret ' => 'b ' , 'code ' => 'foo ' );
240
239
$ storedToken = array ('redirect_uri ' => 'http://www.example.com ' , 'client_id ' => 'my_little_app ' , 'expires ' => time () + 60 );
241
240
242
- $ mockStorage = $ this ->createBaseMock ('IOAuth2GrantCode ' );
241
+ $ mockStorage = $ this ->createBaseMock ('Oauth2\ IOAuth2GrantCode ' );
243
242
$ mockStorage ->expects ($ this ->any ())
244
243
->method ('getAuthCode ' )
245
244
->will ($ this ->returnValue ($ storedToken ));
@@ -264,7 +263,7 @@ public function testGrantAccessTokenWithGrantAuthCodeClientIdChecked() {
264
263
$ inputData = array ('client_id ' => 'another_app ' , 'grant_type ' => OAuth2::GRANT_TYPE_AUTH_CODE , 'redirect_uri ' => 'http://www.example.com/my/subdir ' , 'client_secret ' => 'b ' , 'code ' => 'foo ' );
265
264
$ storedToken = array ('client_id ' => 'my_little_app ' , 'redirect_uri ' => 'http://www.example.com ' , 'expires ' => time () + 60 );
266
265
267
- $ mockStorage = $ this ->createBaseMock ('IOAuth2GrantCode ' );
266
+ $ mockStorage = $ this ->createBaseMock ('OAuth2\ IOAuth2GrantCode ' );
268
267
$ mockStorage ->expects ($ this ->any ())
269
268
->method ('getAuthCode ' )
270
269
->will ($ this ->returnValue ($ storedToken ));
0 commit comments