OAuthTestUnitOAuth1ServiceYahooTest

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

Defined (1)

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

/lib/PHPoAuthLib/tests/Unit/OAuth1/Service/YahooTest.php  
  1. class YahooTest extends \PHPUnit_Framework_TestCase 
  2. /** 
  3. * @covers OAuth\OAuth1\Service\Yahoo::__construct 
  4. */ 
  5. public function testConstructCorrectInterfaceWithoutCustomUri() 
  6. $service = new Yahoo( 
  7. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  8. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  9. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  10. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface') 
  11. ); 
  12.  
  13. $this->assertInstanceOf('\\OAuth\\OAuth1\\Service\\ServiceInterface', $service); 
  14.  
  15. /** 
  16. * @covers OAuth\OAuth1\Service\Yahoo::__construct 
  17. */ 
  18. public function testConstructCorrectInstanceWithoutCustomUri() 
  19. $service = new Yahoo( 
  20. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  21. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  22. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  23. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface') 
  24. ); 
  25.  
  26. $this->assertInstanceOf('\\OAuth\\OAuth1\\Service\\AbstractService', $service); 
  27.  
  28. /** 
  29. * @covers OAuth\OAuth1\Service\Yahoo::__construct 
  30. */ 
  31. public function testConstructCorrectInstanceWithCustomUri() 
  32. $service = new Yahoo( 
  33. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  34. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  35. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  36. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'),  
  37. $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') 
  38. ); 
  39.  
  40. $this->assertInstanceOf('\\OAuth\\OAuth1\\Service\\AbstractService', $service); 
  41.  
  42. /** 
  43. * @covers OAuth\OAuth1\Service\Yahoo::__construct 
  44. * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint 
  45. */ 
  46. public function testGetRequestTokenEndpoint() 
  47. $service = new Yahoo( 
  48. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  49. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  50. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  51. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface') 
  52. ); 
  53.  
  54. $this->assertSame( 
  55. 'https://api.login.yahoo.com/oauth/v2/get_request_token',  
  56. $service->getRequestTokenEndpoint()->getAbsoluteUri() 
  57. ); 
  58.  
  59. /** 
  60. * @covers OAuth\OAuth1\Service\Yahoo::__construct 
  61. * @covers OAuth\OAuth1\Service\Yahoo::getAuthorizationEndpoint 
  62. */ 
  63. public function testGetAuthorizationEndpoint() 
  64. $service = new Yahoo( 
  65. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  66. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  67. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  68. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface') 
  69. ); 
  70.  
  71. $this->assertSame( 
  72. 'https://api.login.yahoo.com/oauth/v2/request_auth',  
  73. $service->getAuthorizationEndpoint()->getAbsoluteUri() 
  74. ); 
  75.  
  76. /** 
  77. * @covers OAuth\OAuth1\Service\Yahoo::__construct 
  78. * @covers OAuth\OAuth1\Service\Yahoo::getAccessTokenEndpoint 
  79. */ 
  80. public function testGetAccessTokenEndpoint() 
  81. $service = new Yahoo( 
  82. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  83. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  84. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  85. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface') 
  86. ); 
  87.  
  88. $this->assertSame( 
  89. 'https://api.login.yahoo.com/oauth/v2/get_token',  
  90. $service->getAccessTokenEndpoint()->getAbsoluteUri() 
  91. ); 
  92.  
  93. /** 
  94. * @covers OAuth\OAuth1\Service\Yahoo::__construct 
  95. * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint 
  96. * @covers OAuth\OAuth1\Service\Yahoo::parseRequestTokenResponse 
  97. */ 
  98. public function testParseRequestTokenResponseThrowsExceptionOnNulledResponse() 
  99. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  100. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); 
  101.  
  102. $service = new Yahoo( 
  103. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  104. $client,  
  105. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  106. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface') 
  107. ); 
  108.  
  109. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  110.  
  111. $service->requestRequestToken(); 
  112.  
  113. /** 
  114. * @covers OAuth\OAuth1\Service\Yahoo::__construct 
  115. * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint 
  116. * @covers OAuth\OAuth1\Service\Yahoo::parseRequestTokenResponse 
  117. */ 
  118. public function testParseRequestTokenResponseThrowsExceptionOnResponseNotAnArray() 
  119. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  120. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('notanarray')); 
  121.  
  122. $service = new Yahoo( 
  123. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  124. $client,  
  125. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  126. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface') 
  127. ); 
  128.  
  129. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  130.  
  131. $service->requestRequestToken(); 
  132.  
  133. /** 
  134. * @covers OAuth\OAuth1\Service\Yahoo::__construct 
  135. * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint 
  136. * @covers OAuth\OAuth1\Service\Yahoo::parseRequestTokenResponse 
  137. */ 
  138. public function testParseRequestTokenResponseThrowsExceptionOnResponseCallbackNotSet() 
  139. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  140. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('foo=bar')); 
  141.  
  142. $service = new Yahoo( 
  143. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  144. $client,  
  145. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  146. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface') 
  147. ); 
  148.  
  149. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  150.  
  151. $service->requestRequestToken(); 
  152.  
  153. /** 
  154. * @covers OAuth\OAuth1\Service\Yahoo::__construct 
  155. * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint 
  156. * @covers OAuth\OAuth1\Service\Yahoo::parseRequestTokenResponse 
  157. */ 
  158. public function testParseRequestTokenResponseThrowsExceptionOnResponseCallbackNotTrue() 
  159. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  160. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue( 
  161. 'oauth_callback_confirmed=false' 
  162. )); 
  163.  
  164. $service = new Yahoo( 
  165. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  166. $client,  
  167. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  168. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface') 
  169. ); 
  170.  
  171. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  172.  
  173. $service->requestRequestToken(); 
  174.  
  175. /** 
  176. * @covers OAuth\OAuth1\Service\Yahoo::__construct 
  177. * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint 
  178. * @covers OAuth\OAuth1\Service\Yahoo::parseRequestTokenResponse 
  179. * @covers OAuth\OAuth1\Service\Yahoo::parseAccessTokenResponse 
  180. */ 
  181. public function testParseRequestTokenResponseValid() 
  182. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  183. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue( 
  184. 'oauth_callback_confirmed=true&oauth_token=foo&oauth_token_secret=bar' 
  185. )); 
  186.  
  187. $service = new Yahoo( 
  188. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  189. $client,  
  190. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  191. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface') 
  192. ); 
  193.  
  194. $this->assertInstanceOf('\\OAuth\\OAuth1\\Token\\StdOAuth1Token', $service->requestRequestToken()); 
  195.  
  196. /** 
  197. * @covers OAuth\OAuth1\Service\Yahoo::__construct 
  198. * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint 
  199. * @covers OAuth\OAuth1\Service\Yahoo::parseAccessTokenResponse 
  200. */ 
  201. public function testParseAccessTokenResponseThrowsExceptionOnError() 
  202. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  203. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=bar')); 
  204.  
  205. $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface'); 
  206.  
  207. $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); 
  208. $storage->expects($this->any())->method('retrieveAccessToken')->will($this->returnValue($token)); 
  209.  
  210. $service = new Yahoo( 
  211. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  212. $client,  
  213. $storage,  
  214. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface') 
  215. ); 
  216.  
  217. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  218.  
  219. $service->requestAccessToken('foo', 'bar', $token); 
  220.  
  221. /** 
  222. * @covers OAuth\OAuth1\Service\Yahoo::__construct 
  223. * @covers OAuth\OAuth1\Service\Yahoo::getRequestTokenEndpoint 
  224. * @covers OAuth\OAuth1\Service\Yahoo::parseAccessTokenResponse 
  225. */ 
  226. public function testParseAccessTokenResponseValid() 
  227. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  228. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue( 
  229. 'oauth_token=foo&oauth_token_secret=bar' 
  230. )); 
  231.  
  232. $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface'); 
  233.  
  234. $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); 
  235. $storage->expects($this->any())->method('retrieveAccessToken')->will($this->returnValue($token)); 
  236.  
  237. $service = new Yahoo( 
  238. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  239. $client,  
  240. $storage,  
  241. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface') 
  242. ); 
  243.  
  244. $this->assertInstanceOf('\\OAuth\\OAuth1\\Token\\StdOAuth1Token', $service->requestAccessToken('foo', 'bar', $token)); 
  245.  
  246. /** 
  247. * @covers OAuth\OAuth1\Service\Yahoo::request 
  248. */ 
  249. public function testRequest() 
  250. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  251. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('response!')); 
  252.  
  253. $token = $this->getMock('\\OAuth\\OAuth1\\Token\\TokenInterface'); 
  254.  
  255. $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); 
  256. $storage->expects($this->any())->method('retrieveAccessToken')->will($this->returnValue($token)); 
  257.  
  258. $service = new Yahoo( 
  259. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  260. $client,  
  261. $storage,  
  262. $this->getMock('\\OAuth\\OAuth1\\Signature\\SignatureInterface'),  
  263. $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') 
  264. ); 
  265.  
  266. $this->assertSame('response!', $service->request('/my/awesome/path'));