OAuthTestUnitOAuth2ServiceMailchimpTest

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

Defined (1)

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

/lib/PHPoAuthLib/tests/Unit/OAuth2/Service/MailchimpTest.php  
  1. class MailchimpTest extends \PHPUnit_Framework_TestCase 
  2. /** 
  3. * @covers OAuth\OAuth2\Service\Mailchimp::__construct 
  4. */ 
  5. public function testConstructCorrectInterfaceWithoutCustomUri() 
  6. $service = new Mailchimp( 
  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\Mailchimp::__construct 
  16. */ 
  17. public function testConstructCorrectInstanceWithoutCustomUri() 
  18. $service = new Mailchimp( 
  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\Mailchimp::__construct 
  28. */ 
  29. public function testConstructCorrectInstanceWithCustomUri() 
  30. $service = new Mailchimp( 
  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\Mailchimp::__construct 
  42. * @covers OAuth\OAuth2\Service\Mailchimp::getAuthorizationEndpoint 
  43. */ 
  44. public function testGetAuthorizationEndpoint() 
  45. $service = new Mailchimp( 
  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://login.mailchimp.com/oauth2/authorize',  
  53. $service->getAuthorizationEndpoint()->getAbsoluteUri() 
  54. ); 
  55.  
  56. /** 
  57. * @covers OAuth\OAuth2\Service\Mailchimp::__construct 
  58. * @covers OAuth\OAuth2\Service\Mailchimp::getAccessTokenEndpoint 
  59. */ 
  60. public function testGetAccessTokenEndpoint() 
  61. $service = new Mailchimp( 
  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://login.mailchimp.com/oauth2/token',  
  69. $service->getAccessTokenEndpoint()->getAbsoluteUri() 
  70. ); 
  71.  
  72. /** 
  73. * @covers OAuth\OAuth2\Service\Mailchimp::__construct 
  74. * @covers OAuth\OAuth2\Service\Mailchimp::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\\StdOAuth2Token'); 
  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 Mailchimp( 
  88. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  89. $client,  
  90. $storage,  
  91. array(),  
  92. new Uri('https://us1.api.mailchimp.com/2.0/') 
  93. ); 
  94.  
  95. $uri = $service->request('https://pieterhordijk.com/my/awesome/path'); 
  96. $absoluteUri = parse_url($uri->getAbsoluteUri()); 
  97.  
  98. $this->assertSame('apikey=foo', $absoluteUri['query']); 
  99.  
  100. /** 
  101. * @covers OAuth\OAuth2\Service\Mailchimp::__construct 
  102. * @covers OAuth\OAuth2\Service\Mailchimp::parseAccessTokenResponse 
  103. */ 
  104. public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() 
  105. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  106. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); 
  107.  
  108. $service = new Mailchimp( 
  109. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  110. $client,  
  111. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  112. ); 
  113.  
  114. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  115.  
  116. $service->requestAccessToken('foo'); 
  117.  
  118. /** 
  119. * @covers OAuth\OAuth2\Service\Mailchimp::__construct 
  120. * @covers OAuth\OAuth2\Service\Mailchimp::parseAccessTokenResponse 
  121. */ 
  122. public function testParseAccessTokenResponseThrowsExceptionOnError() 
  123. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  124. $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); 
  125.  
  126. $service = new Mailchimp( 
  127. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  128. $client,  
  129. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  130. ); 
  131.  
  132. $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); 
  133.  
  134. $service->requestAccessToken('foo'); 
  135.  
  136. /** 
  137. * @covers OAuth\OAuth2\Service\Mailchimp::__construct 
  138. * @covers OAuth\OAuth2\Service\Mailchimp::parseAccessTokenResponse 
  139. */ 
  140. public function testParseAccessTokenResponseValid() 
  141. $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); 
  142. $client->expects($this->at(0))->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo", "expires_in":"bar"}')); 
  143. $client->expects($this->at(1))->method('retrieveResponse')->will($this->returnValue('{"dc": "us7"}')); 
  144.  
  145. $service = new Mailchimp( 
  146. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  147. $client,  
  148. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  149. ); 
  150.  
  151. $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo'));