|
24 | 24 |
|
25 | 25 | class ApiOAuth2Test extends BaseTest { |
26 | 26 |
|
27 | | - public function testSign() { |
| 27 | + public function testSign() |
| 28 | + { |
28 | 29 | $client = $this->getClient(); |
29 | 30 | $oauth = new Google_Auth_OAuth2($client); |
30 | 31 |
|
@@ -53,7 +54,57 @@ public function testSign() { |
53 | 54 | $this->assertEquals('Bearer ACCESS_TOKEN', $auth); |
54 | 55 | } |
55 | 56 |
|
56 | | - public function testCreateAuthUrl() { |
| 57 | + public function testRevokeAccess() |
| 58 | + { |
| 59 | + $accessToken = "ACCESS_TOKEN"; |
| 60 | + $refreshToken = "REFRESH_TOKEN"; |
| 61 | + $accessToken2 = "ACCESS_TOKEN_2"; |
| 62 | + $token = ""; |
| 63 | + |
| 64 | + $client = $this->getClient(); |
| 65 | + $response = $this->getMock("Google_Http_Request", array(), array('')); |
| 66 | + $response->expects($this->any()) |
| 67 | + ->method('getResponseHttpCode') |
| 68 | + ->will($this->returnValue(200)); |
| 69 | + $io = $this->getMock("Google_IO_Stream", array(), array($client)); |
| 70 | + $io->expects($this->any()) |
| 71 | + ->method('makeRequest') |
| 72 | + ->will($this->returnCallback(function($request) use (&$token, $response) { |
| 73 | + $elements = array(); |
| 74 | + parse_str($request->getPostBody(), $elements); |
| 75 | + $token = isset($elements['token']) ? $elements['token'] : null; |
| 76 | + return $response; |
| 77 | + })); |
| 78 | + $client->setIo($io); |
| 79 | + |
| 80 | + // Test with access token. |
| 81 | + $oauth = new Google_Auth_OAuth2($client); |
| 82 | + $oauth->setAccessToken(json_encode(array( |
| 83 | + 'access_token' => $accessToken, |
| 84 | + 'created' => time(), |
| 85 | + 'expires_in' => '3600' |
| 86 | + ))); |
| 87 | + $this->assertTrue($oauth->revokeToken()); |
| 88 | + $this->assertEquals($accessToken, $token); |
| 89 | + |
| 90 | + // Test with refresh token. |
| 91 | + $oauth = new Google_Auth_OAuth2($client); |
| 92 | + $oauth->setAccessToken(json_encode(array( |
| 93 | + 'access_token' => $accessToken, |
| 94 | + 'refresh_token' => $refreshToken, |
| 95 | + 'created' => time(), |
| 96 | + 'expires_in' => '3600' |
| 97 | + ))); |
| 98 | + $this->assertTrue($oauth->revokeToken()); |
| 99 | + $this->assertEquals($refreshToken, $token); |
| 100 | + |
| 101 | + // Test with passed in token. |
| 102 | + $this->assertTrue($oauth->revokeToken($accessToken2)); |
| 103 | + $this->assertEquals($accessToken2, $token); |
| 104 | + } |
| 105 | + |
| 106 | + public function testCreateAuthUrl() |
| 107 | + { |
57 | 108 | $client = $this->getClient(); |
58 | 109 | $oauth = new Google_Auth_OAuth2($client); |
59 | 110 |
|
@@ -81,7 +132,8 @@ public function testCreateAuthUrl() { |
81 | 132 | * this is just a general check to ensure we verify a valid |
82 | 133 | * id token if one exists. |
83 | 134 | */ |
84 | | - public function testValidateIdToken() { |
| 135 | + public function testValidateIdToken() |
| 136 | + { |
85 | 137 | if (!$this->checkToken()) { |
86 | 138 | return; |
87 | 139 | } |
|
0 commit comments