OAuthTestUnitOAuth2ServiceDropboxTest

The Gravity Forms Salesforce Add-On OAuthTest Unit OAuth2 Service DropboxTest class.

Defined (1)

The class is defined in the following location(s).

/lib/PHPoAuthLib/tests/Unit/OAuth2/Service/DropboxTest.php  
  1. class DropboxTest extends \PHPUnit_Framework_TestCase 
  2. /** 
  3. * @covers OAuth\OAuth2\Service\Dropbox::__construct 
  4. */ 
  5. public function testConstructCorrectInterfaceWithoutCustomUri() 
  6. $service = new Dropbox( 
  7. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  8. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  9. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  10. ); 
  11.  
  12. $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); 
  13.  
  14. /** 
  15. * @covers OAuth\OAuth2\Service\Dropbox::__construct 
  16. */ 
  17. public function testConstructCorrectInstanceWithoutCustomUri() 
  18. $service = new Dropbox( 
  19. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  20. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  21. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  22. ); 
  23.  
  24. $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); 
  25.  
  26. /** 
  27. * @covers OAuth\OAuth2\Service\Dropbox::__construct 
  28. */ 
  29. public function testConstructCorrectInstanceWithCustomUri() 
  30. $service = new Dropbox( 
  31. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  32. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  33. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  34. array(),  
  35. $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') 
  36. ); 
  37.  
  38. $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); 
  39.  
  40. /** 
  41. * @covers OAuth\OAuth2\Service\Dropbox::__construct 
  42. * @covers OAuth\OAuth2\Service\Dropbox::getAuthorizationUri 
  43. */ 
  44. public function testGetAuthorizationUriWithoutAdditionalParams() 
  45. $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); 
  46. $credentials->expects($this->once())->method('getConsumerId')->will($this->returnValue('foo')); 
  47. $credentials->expects($this->once())->method('getCallbackUrl')->will($this->returnValue('bar')); 
  48.  
  49. $service = new Dropbox( 
  50. $credentials,  
  51. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  52. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  53. ); 
  54.  
  55. $this->assertSame( 
  56. 'https://www.dropbox.com/1/oauth2/authorize?client_id=foo&redirect_uri=bar&response_type=code&scope=',  
  57. $service->getAuthorizationUri()->getAbsoluteUri() 
  58. ); 
  59.  
  60. /** 
  61. * @covers OAuth\OAuth2\Service\Dropbox::__construct 
  62. * @covers OAuth\OAuth2\Service\Dropbox::getAuthorizationUri 
  63. */ 
  64. public function testGetAuthorizationUriWithAdditionalParams() 
  65. $credentials = $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'); 
  66. $credentials->expects($this->once())->method('getConsumerId')->will($this->returnValue('foo')); 
  67. $credentials->expects($this->once())->method('getCallbackUrl')->will($this->returnValue('bar')); 
  68.  
  69. $service = new Dropbox( 
  70. $credentials,  
  71. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  72. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  73. ); 
  74.  
  75. $this->assertSame( 
  76. 'https://www.dropbox.com/1/oauth2/authorize?client_id=foo&redirect_uri=bar&response_type=code&scope=',  
  77. $service->getAuthorizationUri()->getAbsoluteUri() 
  78. ); 
  79.  
  80. /** 
  81. * @covers OAuth\OAuth2\Service\Dropbox::__construct 
  82. * @covers OAuth\OAuth2\Service\Dropbox::getAuthorizationEndpoint 
  83. */ 
  84. public function testGetAuthorizationEndpoint() 
  85. $service = new Dropbox( 
  86. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  87. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  88. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  89. ); 
  90.  
  91. $this->assertSame('https://www.dropbox.com/1/oauth2/authorize', $service->getAuthorizationEndpoint()->getAbsoluteUri()); 
  92.  
  93. /** 
  94. * @covers OAuth\OAuth2\Service\Dropbox::__construct 
  95. * @covers OAuth\OAuth2\Service\Dropbox::getAccessTokenEndpoint 
  96. */ 
  97. public function testGetAccessTokenEndpoint() 
  98. $service = new Dropbox( 
  99. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  100. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  101. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  102. ); 
  103.  
  104. $this->assertSame('https://api.dropbox.com/1/oauth2/token', $service->getAccessTokenEndpoint()->getAbsoluteUri()); 
  105.  
  106. /** 
  107. * @covers OAuth\OAuth2\Service\Dropbox::__construct 
  108. * @covers OAuth\OAuth2\Service\Dropbox::getAuthorizationMethod 
  109. */ 
  110. public function testGetAuthorizationMethod() 
  111. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  112. $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(0)); 
  113.  
  114. $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); 
  115. $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); 
  116. $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); 
  117.  
  118. $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); 
  119. $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); 
  120.  
  121. $service = new Dropbox( 
  122. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  123. $client,  
  124. $storage 
  125. ); 
  126.  
  127. $uri = $service->request('https://pieterhordijk.com/my/awesome/path'); 
  128. $absoluteUri = parse_url($uri->getAbsoluteUri()); 
  129.  
  130. $this->assertSame('access_token=foo', $absoluteUri['query']); 
  131.  
  132. /** 
  133. * @covers OAuth\OAuth2\Service\Dropbox::__construct 
  134. * @covers OAuth\OAuth2\Service\Dropbox::parseAccessTokenResponse 
  135. */ 
  136. public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() 
  137. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  138. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); 
  139.  
  140. $service = new Dropbox( 
  141. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  142. $client,  
  143. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  144. ); 
  145.  
  146. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  147.  
  148. $service->requestAccessToken('foo'); 
  149.  
  150. /** 
  151. * @covers OAuth\OAuth2\Service\Dropbox::__construct 
  152. * @covers OAuth\OAuth2\Service\Dropbox::parseAccessTokenResponse 
  153. */ 
  154. public function testParseAccessTokenResponseThrowsExceptionOnError() 
  155. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  156. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); 
  157.  
  158. $service = new Dropbox( 
  159. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  160. $client,  
  161. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  162. ); 
  163.  
  164. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  165.  
  166. $service->requestAccessToken('foo'); 
  167.  
  168. /** 
  169. * @covers OAuth\OAuth2\Service\Dropbox::__construct 
  170. * @covers OAuth\OAuth2\Service\Dropbox::parseAccessTokenResponse 
  171. */ 
  172. public function testParseAccessTokenResponseValidWithoutRefreshToken() 
  173. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  174. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo", "expires_in":"bar"}')); 
  175.  
  176. $service = new Dropbox( 
  177. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  178. $client,  
  179. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  180. ); 
  181.  
  182. $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); 
  183.  
  184. /** 
  185. * @covers OAuth\OAuth2\Service\Dropbox::__construct 
  186. * @covers OAuth\OAuth2\Service\Dropbox::parseAccessTokenResponse 
  187. */ 
  188. public function testParseAccessTokenResponseValidWithRefreshToken() 
  189. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  190. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo", "expires_in":"bar", "refresh_token":"baz"}')); 
  191.  
  192. $service = new Dropbox( 
  193. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  194. $client,  
  195. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  196. ); 
  197.  
  198. $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo'));