OAuthTestUnitOAuth2ServiceBitlyTest

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

Defined (1)

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

/lib/PHPoAuthLib/tests/Unit/OAuth2/Service/BitlyTest.php  
  1. class BitlyTest extends \PHPUnit_Framework_TestCase 
  2. /** 
  3. * @covers OAuth\OAuth2\Service\Bitly::__construct 
  4. */ 
  5. public function testConstructCorrectInterfaceWithoutCustomUri() 
  6. $service = new Bitly( 
  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\Bitly::__construct 
  16. */ 
  17. public function testConstructCorrectInstanceWithoutCustomUri() 
  18. $service = new Bitly( 
  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\Bitly::__construct 
  28. */ 
  29. public function testConstructCorrectInstanceWithCustomUri() 
  30. $service = new Bitly( 
  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\Bitly::__construct 
  42. * @covers OAuth\OAuth2\Service\Bitly::getAuthorizationEndpoint 
  43. */ 
  44. public function testGetAuthorizationEndpoint() 
  45. $service = new Bitly( 
  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://bitly.com/oauth/authorize', $service->getAuthorizationEndpoint()->getAbsoluteUri()); 
  52.  
  53. /** 
  54. * @covers OAuth\OAuth2\Service\Bitly::__construct 
  55. * @covers OAuth\OAuth2\Service\Bitly::getAccessTokenEndpoint 
  56. */ 
  57. public function testGetAccessTokenEndpoint() 
  58. $service = new Bitly( 
  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://api-ssl.bitly.com/oauth/access_token', $service->getAccessTokenEndpoint()->getAbsoluteUri()); 
  65.  
  66. /** 
  67. * @covers OAuth\OAuth2\Service\Bitly::__construct 
  68. * @covers OAuth\OAuth2\Service\Bitly::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(0)); 
  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 Bitly( 
  82. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  83. $client,  
  84. $storage 
  85. ); 
  86.  
  87. $uri = $service->request('https://pieterhordijk.com/my/awesome/path'); 
  88. $absoluteUri = parse_url($uri->getAbsoluteUri()); 
  89.  
  90. $this->assertSame('access_token=foo', $absoluteUri['query']); 
  91.  
  92. /** 
  93. * @covers OAuth\OAuth2\Service\Bitly::__construct 
  94. * @covers OAuth\OAuth2\Service\Bitly::parseAccessTokenResponse 
  95. */ 
  96. public function testParseAccessTokenResponseThrowsExceptionOnError() 
  97. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  98. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); 
  99.  
  100. $service = new Bitly( 
  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\Bitly::__construct 
  112. * @covers OAuth\OAuth2\Service\Bitly::parseAccessTokenResponse 
  113. * @covers OAuth\OAuth2\Service\Bitly::requestAccessToken 
  114. */ 
  115. public function testParseAccessTokenResponseValid() 
  116. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  117. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('access_token=foo')); 
  118.  
  119. $service = new Bitly( 
  120. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  121. $client,  
  122. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  123. ); 
  124.  
  125. $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo'));