OAuthTestUnitOAuth1ServiceXingTest

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

Defined (1)

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

/lib/PHPoAuthLib/tests/Unit/OAuth1/Service/XingTest.php  
  1. class XingTest extends \PHPUnit_Framework_TestCase 
  2. private $client; 
  3. private $storage; 
  4. private $xing; 
  5.  
  6.  
  7. protected function setUp() 
  8. parent::setUp(); 
  9.  
  10. $this->client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  11. $this->storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); 
  12.  
  13. $this->xing = new Xing( 
  14. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  15. $this->client,  
  16. $this->storage,  
  17. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface') 
  18. ); 
  19.  
  20. /** 
  21. * @covers OAuth\OAuth1\Service\Xing::__construct 
  22. */ 
  23. public function testConstructCorrectInterfaceWithoutCustomUri() 
  24. $this->assertInstanceOf( 
  25. '\\OAuth\\OAuth1\\Service\\ServiceInterface', $this->xing 
  26. ); 
  27.  
  28. /** 
  29. * @covers OAuth\OAuth1\Service\Xing::__construct 
  30. */ 
  31. public function testConstructCorrectInstanceWithoutCustomUri() 
  32. $this->assertInstanceOf( 
  33. '\\OAuth\\OAuth1\\Service\\AbstractService', $this->xing 
  34. ); 
  35.  
  36. /** 
  37. * @covers OAuth\OAuth1\Service\Xing::__construct 
  38. */ 
  39. public function testConstructCorrectInstanceWithCustomUri() 
  40. $service = new Xing( 
  41. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  42. $this->client,  
  43. $this->storage,  
  44. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'),  
  45. $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') 
  46. ); 
  47.  
  48. $this->assertInstanceOf('\\OAuth\\OAuth1\\Service\\AbstractService', $service); 
  49.  
  50. /** 
  51. * @covers OAuth\OAuth1\Service\Xing::__construct 
  52. * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint 
  53. */ 
  54. public function testGetRequestTokenEndpoint() 
  55. $this->assertSame( 
  56. 'https://api.xing.com/v1/request_token',  
  57. $this->xing->getRequestTokenEndpoint()->getAbsoluteUri() 
  58. ); 
  59.  
  60. /** 
  61. * @covers OAuth\OAuth1\Service\Xing::__construct 
  62. * @covers OAuth\OAuth1\Service\Xing::getAuthorizationEndpoint 
  63. */ 
  64. public function testGetAuthorizationEndpoint() 
  65. $this->assertSame( 
  66. 'https://api.xing.com/v1/authorize',  
  67. $this->xing->getAuthorizationEndpoint()->getAbsoluteUri() 
  68. ); 
  69.  
  70. /** 
  71. * @covers OAuth\OAuth1\Service\Xing::__construct 
  72. * @covers OAuth\OAuth1\Service\Xing::getAccessTokenEndpoint 
  73. */ 
  74. public function testGetAccessTokenEndpoint() 
  75. $this->assertSame( 
  76. 'https://api.xing.com/v1/access_token',  
  77. $this->xing->getAccessTokenEndpoint()->getAbsoluteUri() 
  78. ); 
  79.  
  80. /** 
  81. * @covers OAuth\OAuth1\Service\Xing::__construct 
  82. * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint 
  83. * @covers OAuth\OAuth1\Service\Xing::parseRequestTokenResponse 
  84. */ 
  85. public function testParseRequestTokenResponseThrowsExceptionOnNulledResponse() 
  86. $this->client 
  87. ->expects($this->once()) 
  88. ->method('retrieveResponse') 
  89. ->will($this->returnValue(null)); 
  90.  
  91. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  92.  
  93. $this->xing->requestRequestToken(); 
  94.  
  95. /** 
  96. * @covers OAuth\OAuth1\Service\Xing::__construct 
  97. * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint 
  98. * @covers OAuth\OAuth1\Service\Xing::parseRequestTokenResponse 
  99. */ 
  100. public function testParseRequestTokenResponseThrowsExceptionOnResponseNotAnArray() 
  101. $this->client 
  102. ->expects($this->once()) 
  103. ->method('retrieveResponse') 
  104. ->will($this->returnValue('notanarray')); 
  105.  
  106. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  107.  
  108. $this->xing->requestRequestToken(); 
  109.  
  110. /** 
  111. * @covers OAuth\OAuth1\Service\Xing::__construct 
  112. * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint 
  113. * @covers OAuth\OAuth1\Service\Xing::parseRequestTokenResponse 
  114. */ 
  115. public function testParseRequestTokenResponseThrowsExceptionOnResponseCallbackNotSet() 
  116. $this->client 
  117. ->expects($this->once()) 
  118. ->method('retrieveResponse') 
  119. ->will($this->returnValue('foo=bar')); 
  120.  
  121. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  122.  
  123. $this->xing->requestRequestToken(); 
  124.  
  125. /** 
  126. * @covers OAuth\OAuth1\Service\Xing::__construct 
  127. * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint 
  128. * @covers OAuth\OAuth1\Service\Xing::parseRequestTokenResponse 
  129. */ 
  130. public function testParseRequestTokenResponseThrowsExceptionOnResponseCallbackNotTrue() 
  131. $this->client 
  132. ->expects($this->once()) 
  133. ->method('retrieveResponse') 
  134. ->will($this->returnValue('oauth_callback_confirmed=false')); 
  135.  
  136. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  137.  
  138. $this->xing->requestRequestToken(); 
  139.  
  140. /** 
  141. * @covers OAuth\OAuth1\Service\Xing::__construct 
  142. * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint 
  143. * @covers OAuth\OAuth1\Service\Xing::parseRequestTokenResponse 
  144. * @covers OAuth\OAuth1\Service\Xing::parseAccessTokenResponse 
  145. */ 
  146. public function testParseRequestTokenResponseValid() 
  147. $this->client 
  148. ->expects($this->once()) 
  149. ->method('retrieveResponse') 
  150. ->will($this->returnValue( 
  151. 'oauth_callback_confirmed=true&oauth_token=foo&oauth_token_secret=bar' 
  152. )); 
  153.  
  154. $this->assertInstanceOf( 
  155. '\\OAuth\\OAuth1\\Token\\StdOAuth1Token',  
  156. $this->xing->requestRequestToken() 
  157. ); 
  158.  
  159. /** 
  160. * @covers OAuth\OAuth1\Service\Xing::__construct 
  161. * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint 
  162. * @covers OAuth\OAuth1\Service\Xing::parseAccessTokenResponse 
  163. */ 
  164. public function testParseAccessTokenResponseThrowsExceptionOnError() 
  165. $this->client 
  166. ->expects($this->once()) 
  167. ->method('retrieveResponse') 
  168. ->will($this->returnValue('error=bar')); 
  169.  
  170. $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface'); 
  171.  
  172. $this->storage 
  173. ->expects($this->any()) 
  174. ->method('retrieveAccessToken') 
  175. ->will($this->returnValue($token)); 
  176.  
  177. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  178.  
  179. $this->xing->requestAccessToken('foo', 'bar', $token); 
  180.  
  181. /** 
  182. * @covers OAuth\OAuth1\Service\Xing::__construct 
  183. * @covers OAuth\OAuth1\Service\Xing::getRequestTokenEndpoint 
  184. * @covers OAuth\OAuth1\Service\Xing::parseAccessTokenResponse 
  185. */ 
  186. public function testParseAccessTokenResponseValid() 
  187. $this->client 
  188. ->expects($this->once()) 
  189. ->method('retrieveResponse') 
  190. ->will($this->returnValue('oauth_token=foo&oauth_token_secret=bar')); 
  191.  
  192. $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface'); 
  193.  
  194. $this->storage 
  195. ->expects($this->any()) 
  196. ->method('retrieveAccessToken') 
  197. ->will($this->returnValue($token)); 
  198.  
  199.  
  200. $this->assertInstanceOf( 
  201. '\\OAuth\\OAuth1\\Token\\StdOAuth1Token',  
  202. $this->xing->requestAccessToken('foo', 'bar', $token) 
  203. );