OAuthTestUnitOAuth1ServiceAbstractServiceTest

The Gravity Forms Salesforce Add-On OAuthTest Unit OAuth1 Service AbstractServiceTest class.

Defined (1)

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

/lib/PHPoAuthLib/tests/Unit/OAuth1/Service/AbstractServiceTest.php  
  1. class AbstractServiceTest extends \PHPUnit_Framework_TestCase 
  2. /** 
  3. * @covers OAuth\OAuth1\Service\AbstractService::__construct 
  4. */ 
  5. public function testConstructCorrectInterface() 
  6. $service = $this->getMockForAbstractClass( 
  7. '\\OAuth\\OAuth1\\Service\\AbstractService',  
  8. array( 
  9. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  10. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  11. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  12. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'),  
  13. $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'),  
  14. ); 
  15.  
  16. $this->assertInstanceOf('\\OAuth\\OAuth1\\Service\\ServiceInterface', $service); 
  17.  
  18. /** 
  19. * @covers OAuth\OAuth1\Service\AbstractService::__construct 
  20. */ 
  21. public function testConstructCorrectParent() 
  22. $service = $this->getMockForAbstractClass( 
  23. '\\OAuth\\OAuth1\\Service\\AbstractService',  
  24. array( 
  25. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  26. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  27. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  28. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'),  
  29. $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface'),  
  30. ); 
  31.  
  32. $this->assertInstanceOf('\\OAuth\\Common\\Service\\AbstractService', $service); 
  33.  
  34. /** 
  35. * @covers OAuth\OAuth1\Service\AbstractService::requestRequestToken 
  36. * @covers OAuth\OAuth1\Service\AbstractService::buildAuthorizationHeaderForTokenRequest 
  37. * @covers OAuth\OAuth1\Service\AbstractService::getBasicAuthorizationHeaderInfo 
  38. * @covers OAuth\OAuth1\Service\AbstractService::generateNonce 
  39. * @covers OAuth\OAuth1\Service\AbstractService::getSignatureMethod 
  40. * @covers OAuth\OAuth1\Service\AbstractService::getVersion 
  41. * @covers OAuth\OAuth1\Service\AbstractService::getExtraOAuthHeaders 
  42. * @covers OAuth\OAuth1\Service\AbstractService::parseRequestTokenResponse 
  43. */ 
  44. public function testRequestRequestTokenBuildAuthHeaderTokenRequestWithoutParams() 
  45. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  46. $client->expects($this->once())->method('retrieveResponse')->will($this->returnCallback(function($endpoint, $array, $headers) { 
  47. \PHPUnit_Framework_Assert::assertSame('http://pieterhordijk.com/token', $endpoint->getAbsoluteUri()); 
  48. })); 
  49.  
  50. $service = new Mock( 
  51. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  52. $client,  
  53. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  54. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'),  
  55. $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') 
  56. ); 
  57.  
  58. $this->assertInstanceOf('\\OAuth\\OAuth1\\Token\\StdOAuth1Token', $service->requestRequestToken()); 
  59.  
  60. /** 
  61. * @covers OAuth\OAuth1\Service\AbstractService::getAuthorizationUri 
  62. * @covers OAuth\OAuth1\Service\AbstractService::getAuthorizationEndpoint 
  63. */ 
  64. public function testGetAuthorizationUriWithoutParameters() 
  65. $service = new Mock( 
  66. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  67. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  68. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  69. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'),  
  70. $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') 
  71. ); 
  72.  
  73. $this->assertSame('http://pieterhordijk.com/auth', $service->getAuthorizationUri()->getAbsoluteUri()); 
  74.  
  75. /** 
  76. * @covers OAuth\OAuth1\Service\AbstractService::getAuthorizationUri 
  77. * @covers OAuth\OAuth1\Service\AbstractService::getAuthorizationEndpoint 
  78. */ 
  79. public function testGetAuthorizationUriWithParameters() 
  80. $service = new Mock( 
  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. $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') 
  86. ); 
  87.  
  88. $this->assertSame('http://pieterhordijk.com/auth?foo=bar&baz=beer', $service->getAuthorizationUri(array( 
  89. 'foo' => 'bar',  
  90. 'baz' => 'beer',  
  91. ))->getAbsoluteUri()); 
  92.  
  93. /** 
  94. * @covers OAuth\OAuth1\Service\AbstractService::requestAccessToken 
  95. * @covers OAuth\OAuth1\Service\AbstractService::service 
  96. * @covers OAuth\OAuth1\Service\AbstractService::buildAuthorizationHeaderForAPIRequest 
  97. * @covers OAuth\OAuth1\Service\AbstractService::getBasicAuthorizationHeaderInfo 
  98. * @covers OAuth\OAuth1\Service\AbstractService::generateNonce 
  99. * @covers OAuth\OAuth1\Service\AbstractService::getSignatureMethod 
  100. * @covers OAuth\OAuth1\Service\AbstractService::getVersion 
  101. * @covers OAuth\OAuth1\Service\AbstractService::getAccessTokenEndpoint 
  102. * @covers OAuth\OAuth1\Service\AbstractService::getExtraOAuthHeaders 
  103. * @covers OAuth\OAuth1\Service\AbstractService::parseAccessTokenResponse 
  104. */ 
  105. public function testRequestAccessTokenWithoutSecret() 
  106. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  107. $client->expects($this->once())->method('retrieveResponse')->will($this->returnCallback(function($endpoint, $array, $headers) { 
  108. \PHPUnit_Framework_Assert::assertSame('http://pieterhordijk.com/access', $endpoint->getAbsoluteUri()); 
  109. })); 
  110.  
  111. $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface'); 
  112. $token->expects($this->once())->method('getRequestTokenSecret')->will($this->returnValue('baz')); 
  113.  
  114. $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); 
  115. $storage->expects($this->any())->method('retrieveAccessToken')->will($this->returnValue($token)); 
  116.  
  117. $service = new Mock( 
  118. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  119. $client,  
  120. $storage,  
  121. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'),  
  122. $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') 
  123. ); 
  124.  
  125. $this->assertInstanceOf('\\OAuth\\OAuth1\\Token\\StdOAuth1Token', $service->requestAccessToken('foo', 'bar')); 
  126.  
  127. /** 
  128. * @covers OAuth\OAuth1\Service\AbstractService::requestAccessToken 
  129. * @covers OAuth\OAuth1\Service\AbstractService::service 
  130. * @covers OAuth\OAuth1\Service\AbstractService::buildAuthorizationHeaderForAPIRequest 
  131. * @covers OAuth\OAuth1\Service\AbstractService::getBasicAuthorizationHeaderInfo 
  132. * @covers OAuth\OAuth1\Service\AbstractService::generateNonce 
  133. * @covers OAuth\OAuth1\Service\AbstractService::getSignatureMethod 
  134. * @covers OAuth\OAuth1\Service\AbstractService::getVersion 
  135. * @covers OAuth\OAuth1\Service\AbstractService::getAccessTokenEndpoint 
  136. * @covers OAuth\OAuth1\Service\AbstractService::getExtraOAuthHeaders 
  137. * @covers OAuth\OAuth1\Service\AbstractService::parseAccessTokenResponse 
  138. */ 
  139. public function testRequestAccessTokenWithSecret() 
  140. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  141. $client->expects($this->once())->method('retrieveResponse')->will($this->returnCallback(function($endpoint, $array, $headers) { 
  142. \PHPUnit_Framework_Assert::assertSame('http://pieterhordijk.com/access', $endpoint->getAbsoluteUri()); 
  143. })); 
  144.  
  145. $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface'); 
  146.  
  147. $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); 
  148. $storage->expects($this->any())->method('retrieveAccessToken')->will($this->returnValue($token)); 
  149.  
  150. $service = new Mock( 
  151. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  152. $client,  
  153. $storage,  
  154. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'),  
  155. $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') 
  156. ); 
  157.  
  158. $this->assertInstanceOf('\\OAuth\\OAuth1\\Token\\StdOAuth1Token', $service->requestAccessToken('foo', 'bar', $token)); 
  159.  
  160. /** 
  161. * @covers OAuth\OAuth1\Service\AbstractService::request 
  162. * @covers OAuth\OAuth1\Service\AbstractService::determineRequestUriFromPath 
  163. * @covers OAuth\OAuth1\Service\AbstractService::service 
  164. * @covers OAuth\OAuth1\Service\AbstractService::getExtraApiHeaders 
  165. * @covers OAuth\OAuth1\Service\AbstractService::buildAuthorizationHeaderForAPIRequest 
  166. * @covers OAuth\OAuth1\Service\AbstractService::getBasicAuthorizationHeaderInfo 
  167. * @covers OAuth\OAuth1\Service\AbstractService::generateNonce 
  168. * @covers OAuth\OAuth1\Service\AbstractService::getSignatureMethod 
  169. * @covers OAuth\OAuth1\Service\AbstractService::getVersion 
  170. */ 
  171. public function testRequest() 
  172. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  173. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('response!')); 
  174.  
  175. $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface'); 
  176. //$token->expects($this->once())->method('getRequestTokenSecret')->will($this->returnValue('baz')); 
  177.  
  178. $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); 
  179. $storage->expects($this->any())->method('retrieveAccessToken')->will($this->returnValue($token)); 
  180.  
  181. $service = new Mock( 
  182. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  183. $client,  
  184. $storage,  
  185. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'),  
  186. $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') 
  187. ); 
  188.  
  189. $this->assertSame('response!', $service->request('/my/awesome/path'));