OAuthTestUnitOAuth2ServiceLinkedinTest

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

Defined (1)

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

/lib/PHPoAuthLib/tests/Unit/OAuth2/Service/LinkedinTest.php  
  1. class LinkedinTest extends \PHPUnit_Framework_TestCase 
  2. /** 
  3. * @covers OAuth\OAuth2\Service\Linkedin::__construct 
  4. */ 
  5. public function testConstructCorrectInterfaceWithoutCustomUri() 
  6. $service = new Linkedin( 
  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\Linkedin::__construct 
  16. */ 
  17. public function testConstructCorrectInstanceWithoutCustomUri() 
  18. $service = new Linkedin( 
  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\Linkedin::__construct 
  28. */ 
  29. public function testConstructCorrectInstanceWithCustomUri() 
  30. $service = new Linkedin( 
  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\Linkedin::__construct 
  42. * @covers OAuth\OAuth2\Service\Linkedin::getAuthorizationEndpoint 
  43. */ 
  44. public function testGetAuthorizationEndpoint() 
  45. $service = new Linkedin( 
  46. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  47. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  48. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  49. ); 
  50.  
  51. $this->assertSame( 
  52. 'https://www.linkedin.com/uas/oauth2/authorization',  
  53. $service->getAuthorizationEndpoint()->getAbsoluteUri() 
  54. ); 
  55.  
  56. /** 
  57. * @covers OAuth\OAuth2\Service\Linkedin::__construct 
  58. * @covers OAuth\OAuth2\Service\Linkedin::getAccessTokenEndpoint 
  59. */ 
  60. public function testGetAccessTokenEndpoint() 
  61. $service = new Linkedin( 
  62. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  63. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  64. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  65. ); 
  66.  
  67. $this->assertSame( 
  68. 'https://www.linkedin.com/uas/oauth2/accessToken',  
  69. $service->getAccessTokenEndpoint()->getAbsoluteUri() 
  70. ); 
  71.  
  72. /** 
  73. * @covers OAuth\OAuth2\Service\Linkedin::__construct 
  74. * @covers OAuth\OAuth2\Service\Linkedin::getAuthorizationMethod 
  75. */ 
  76. public function testGetAuthorizationMethod() 
  77. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  78. $client->expects($this->once())->method('retrieveResponse')->will($this->returnArgument(0)); 
  79.  
  80. $token = $this->getMock('\\OAuth\\OAuth2\\Token\\TokenInterface'); 
  81. $token->expects($this->once())->method('getEndOfLife')->will($this->returnValue(TokenInterface::EOL_NEVER_EXPIRES)); 
  82. $token->expects($this->once())->method('getAccessToken')->will($this->returnValue('foo')); 
  83.  
  84. $storage = $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'); 
  85. $storage->expects($this->once())->method('retrieveAccessToken')->will($this->returnValue($token)); 
  86.  
  87. $service = new Linkedin( 
  88. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  89. $client,  
  90. $storage 
  91. ); 
  92.  
  93. $uri = $service->request('https://pieterhordijk.com/my/awesome/path'); 
  94. $absoluteUri = parse_url($uri->getAbsoluteUri()); 
  95.  
  96. $this->assertSame('oauth2_access_token=foo', $absoluteUri['query']); 
  97.  
  98. /** 
  99. * @covers OAuth\OAuth2\Service\Linkedin::__construct 
  100. * @covers OAuth\OAuth2\Service\Linkedin::parseAccessTokenResponse 
  101. */ 
  102. public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() 
  103. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  104. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); 
  105.  
  106. $service = new Linkedin( 
  107. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  108. $client,  
  109. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  110. ); 
  111.  
  112. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  113.  
  114. $service->requestAccessToken('foo'); 
  115.  
  116. /** 
  117. * @covers OAuth\OAuth2\Service\Linkedin::__construct 
  118. * @covers OAuth\OAuth2\Service\Linkedin::parseAccessTokenResponse 
  119. */ 
  120. public function testParseAccessTokenResponseThrowsExceptionOnErrorDescription() 
  121. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  122. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error_description=some_error')); 
  123.  
  124. $service = new Linkedin( 
  125. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  126. $client,  
  127. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  128. ); 
  129.  
  130. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  131.  
  132. $service->requestAccessToken('foo'); 
  133.  
  134. /** 
  135. * @covers OAuth\OAuth2\Service\Linkedin::__construct 
  136. * @covers OAuth\OAuth2\Service\Linkedin::parseAccessTokenResponse 
  137. */ 
  138. public function testParseAccessTokenResponseThrowsExceptionOnError() 
  139. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  140. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); 
  141.  
  142. $service = new Linkedin( 
  143. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  144. $client,  
  145. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  146. ); 
  147.  
  148. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  149.  
  150. $service->requestAccessToken('foo'); 
  151.  
  152. /** 
  153. * @covers OAuth\OAuth2\Service\Linkedin::__construct 
  154. * @covers OAuth\OAuth2\Service\Linkedin::parseAccessTokenResponse 
  155. */ 
  156. public function testParseAccessTokenResponseValidWithoutRefreshToken() 
  157. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  158. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo", "expires_in":"bar"}')); 
  159.  
  160. $service = new Linkedin( 
  161. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  162. $client,  
  163. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  164. ); 
  165.  
  166. $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); 
  167.  
  168. /** 
  169. * @covers OAuth\OAuth2\Service\Linkedin::__construct 
  170. * @covers OAuth\OAuth2\Service\Linkedin::parseAccessTokenResponse 
  171. */ 
  172. public function testParseAccessTokenResponseValidWithRefreshToken() 
  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", "refresh_token":"baz"}')); 
  175.  
  176. $service = new Linkedin( 
  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'));