OAuthTestUnitOAuth2ServiceYammerTest

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

Defined (1)

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

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