OAuthTestUnitOAuth2ServiceGoogleTest

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

Defined (1)

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

/lib/PHPoAuthLib/tests/Unit/OAuth2/Service/GoogleTest.php  
  1. class GoogleTest extends \PHPUnit_Framework_TestCase 
  2. /** 
  3. * @covers OAuth\OAuth2\Service\Google::__construct 
  4. */ 
  5. public function testConstructCorrectInterfaceWithoutCustomUri() 
  6. $service = new Google( 
  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\Google::__construct 
  16. */ 
  17. public function testConstructCorrectInstanceWithoutCustomUri() 
  18. $service = new Google( 
  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\Google::__construct 
  28. */ 
  29. public function testConstructCorrectInstanceWithCustomUri() 
  30. $service = new Google( 
  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\Google::__construct 
  42. * @covers OAuth\OAuth2\Service\Google::getAuthorizationEndpoint 
  43. */ 
  44. public function testGetAuthorizationEndpoint() 
  45. $service = new Google( 
  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://accounts.google.com/o/oauth2/auth?access_type=online',  
  53. $service->getAuthorizationEndpoint()->getAbsoluteUri() 
  54. ); 
  55.  
  56. // Verify that 'offine' works 
  57. $service->setAccessType('offline'); 
  58. $this->assertSame( 
  59. 'https://accounts.google.com/o/oauth2/auth?access_type=offline',  
  60. $service->getAuthorizationEndpoint()->getAbsoluteUri() 
  61. ); 
  62.  
  63.  
  64. /** 
  65. * @covers OAuth\OAuth2\Service\Google::__construct 
  66. * @covers OAuth\OAuth2\Service\Google::getAuthorizationEndpoint 
  67. */ 
  68. public function testGetAuthorizationEndpointException() 
  69. $service = new Google( 
  70. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  71. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  72. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  73. ); 
  74.  
  75. $this->setExpectedException('OAuth\OAuth2\Service\Exception\InvalidAccessTypeException'); 
  76.  
  77. try { 
  78. $service->setAccessType('invalid'); 
  79. } catch (InvalidAccessTypeException $e) { 
  80. return; 
  81. $this->fail('Expected InvalidAccessTypeException not thrown'); 
  82.  
  83. /** 
  84. * @covers OAuth\OAuth2\Service\Google::__construct 
  85. * @covers OAuth\OAuth2\Service\Google::getAccessTokenEndpoint 
  86. */ 
  87. public function testGetAccessTokenEndpoint() 
  88. $service = new Google( 
  89. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  90. $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'),  
  91. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  92. ); 
  93.  
  94. $this->assertSame( 
  95. 'https://accounts.google.com/o/oauth2/token',  
  96. $service->getAccessTokenEndpoint()->getAbsoluteUri() 
  97. ); 
  98.  
  99. /** 
  100. * @covers OAuth\OAuth2\Service\Google::__construct 
  101. * @covers OAuth\OAuth2\Service\Google::parseAccessTokenResponse 
  102. */ 
  103. public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() 
  104. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  105. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); 
  106.  
  107. $service = new Google( 
  108. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  109. $client,  
  110. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  111. ); 
  112.  
  113. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  114.  
  115. $service->requestAccessToken('foo'); 
  116.  
  117. /** 
  118. * @covers OAuth\OAuth2\Service\Google::__construct 
  119. * @covers OAuth\OAuth2\Service\Google::parseAccessTokenResponse 
  120. */ 
  121. public function testParseAccessTokenResponseThrowsExceptionOnError() 
  122. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  123. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); 
  124.  
  125. $service = new Google( 
  126. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  127. $client,  
  128. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  129. ); 
  130.  
  131. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  132.  
  133. $service->requestAccessToken('foo'); 
  134.  
  135. /** 
  136. * @covers OAuth\OAuth2\Service\Google::__construct 
  137. * @covers OAuth\OAuth2\Service\Google::parseAccessTokenResponse 
  138. */ 
  139. public function testParseAccessTokenResponseValidWithoutRefreshToken() 
  140. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  141. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo", "expires_in":"bar"}')); 
  142.  
  143. $service = new Google( 
  144. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  145. $client,  
  146. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  147. ); 
  148.  
  149. $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); 
  150.  
  151. /** 
  152. * @covers OAuth\OAuth2\Service\Google::__construct 
  153. * @covers OAuth\OAuth2\Service\Google::parseAccessTokenResponse 
  154. */ 
  155. public function testParseAccessTokenResponseValidWithRefreshToken() 
  156. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  157. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo", "expires_in":"bar", "refresh_token":"baz"}')); 
  158.  
  159. $service = new Google( 
  160. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  161. $client,  
  162. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  163. ); 
  164.  
  165. $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo'));