OAuthTestUnitOAuth2ServiceVkontakteTest

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

Defined (1)

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

/lib/PHPoAuthLib/tests/Unit/OAuth2/Service/VkontakteTest.php  
  1. class VkontakteTest extends \PHPUnit_Framework_TestCase 
  2. /** 
  3. * @covers OAuth\OAuth2\Service\Vkontakte::__construct 
  4. */ 
  5. public function testConstructCorrectInterfaceWithoutCustomUri() 
  6. $service = new Vkontakte( 
  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\Vkontakte::__construct 
  16. */ 
  17. public function testConstructCorrectInstanceWithoutCustomUri() 
  18. $service = new Vkontakte( 
  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\Vkontakte::__construct 
  28. */ 
  29. public function testConstructCorrectInstanceWithCustomUri() 
  30. $service = new Vkontakte( 
  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\Vkontakte::__construct 
  42. * @covers OAuth\OAuth2\Service\Vkontakte::getAuthorizationEndpoint 
  43. */ 
  44. public function testGetAuthorizationEndpoint() 
  45. $service = new Vkontakte( 
  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://oauth.vk.com/authorize', $service->getAuthorizationEndpoint()->getAbsoluteUri()); 
  52.  
  53. /** 
  54. * @covers OAuth\OAuth2\Service\Vkontakte::__construct 
  55. * @covers OAuth\OAuth2\Service\Vkontakte::getAccessTokenEndpoint 
  56. */ 
  57. public function testGetAccessTokenEndpoint() 
  58. $service = new Vkontakte( 
  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://oauth.vk.com/access_token', $service->getAccessTokenEndpoint()->getAbsoluteUri()); 
  65.  
  66. /** 
  67. * @covers OAuth\OAuth2\Service\Vkontakte::__construct 
  68. * @covers OAuth\OAuth2\Service\Vkontakte::parseAccessTokenResponse 
  69. */ 
  70. public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() 
  71. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  72. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); 
  73.  
  74. $service = new Vkontakte( 
  75. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  76. $client,  
  77. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  78. ); 
  79.  
  80. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  81.  
  82. $service->requestAccessToken('foo'); 
  83.  
  84. /** 
  85. * @covers OAuth\OAuth2\Service\Vkontakte::__construct 
  86. * @covers OAuth\OAuth2\Service\Vkontakte::parseAccessTokenResponse 
  87. */ 
  88. public function testParseAccessTokenResponseThrowsExceptionOnError() 
  89. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  90. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); 
  91.  
  92. $service = new Vkontakte( 
  93. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  94. $client,  
  95. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  96. ); 
  97.  
  98. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  99.  
  100. $service->requestAccessToken('foo'); 
  101.  
  102. /** 
  103. * @covers OAuth\OAuth2\Service\Vkontakte::__construct 
  104. * @covers OAuth\OAuth2\Service\Vkontakte::parseAccessTokenResponse 
  105. */ 
  106. public function testParseAccessTokenResponseValidWithoutRefreshToken() 
  107. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  108. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo", "expires_in":"bar"}')); 
  109.  
  110. $service = new Vkontakte( 
  111. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  112. $client,  
  113. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  114. ); 
  115.  
  116. $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); 
  117.  
  118. /** 
  119. * @covers OAuth\OAuth2\Service\Vkontakte::__construct 
  120. * @covers OAuth\OAuth2\Service\Vkontakte::parseAccessTokenResponse 
  121. */ 
  122. public function testParseAccessTokenResponseValidWithRefreshToken() 
  123. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  124. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo", "expires_in":"bar", "refresh_token":"baz"}')); 
  125.  
  126. $service = new Vkontakte( 
  127. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  128. $client,  
  129. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  130. ); 
  131.  
  132. $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo'));