OAuthUnitServiceFactoryTest

The Gravity Forms Salesforce Add-On OAuth Unit ServiceFactoryTest class.

Defined (1)

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

/lib/PHPoAuthLib/tests/Unit/ServiceFactoryTest.php  
  1. class ServiceFactoryTest extends \PHPUnit_Framework_TestCase 
  2. /** 
  3. * @covers OAuth\ServiceFactory::setHttpClient 
  4. */ 
  5. public function testSetHttpClient() 
  6. $factory = new ServiceFactory(); 
  7.  
  8. $this->assertInstanceOf( 
  9. '\\OAuth\\ServiceFactory',  
  10. $factory->setHttpClient($this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface')) 
  11. ); 
  12.  
  13. /** 
  14. * @covers OAuth\ServiceFactory::registerService 
  15. */ 
  16. public function testRegisterServiceThrowsExceptionNonExistentClass() 
  17. $this->setExpectedException('\\OAuth\Common\Exception\Exception'); 
  18.  
  19. $factory = new ServiceFactory(); 
  20. $factory->registerService('foo', 'bar'); 
  21.  
  22. /** 
  23. * @covers OAuth\ServiceFactory::registerService 
  24. */ 
  25. public function testRegisterServiceThrowsExceptionWithClassIncorrectImplementation() 
  26. $this->setExpectedException('\\OAuth\Common\Exception\Exception'); 
  27.  
  28. $factory = new ServiceFactory(); 
  29. $factory->registerService('foo', 'OAuth\\ServiceFactory'); 
  30.  
  31. /** 
  32. * @covers OAuth\ServiceFactory::registerService 
  33. */ 
  34. public function testRegisterServiceSuccessOAuth1() 
  35. $factory = new ServiceFactory(); 
  36.  
  37. $this->assertInstanceOf( 
  38. '\\OAuth\\ServiceFactory',  
  39. $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth1\\Service\\Fake') 
  40. ); 
  41.  
  42. /** 
  43. * @covers OAuth\ServiceFactory::registerService 
  44. */ 
  45. public function testRegisterServiceSuccessOAuth2() 
  46. $factory = new ServiceFactory(); 
  47.  
  48. $this->assertInstanceOf( 
  49. '\\OAuth\\ServiceFactory',  
  50. $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake') 
  51. ); 
  52.  
  53. /** 
  54. * @covers OAuth\ServiceFactory::createService 
  55. * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName 
  56. * @covers OAuth\ServiceFactory::buildV1Service 
  57. */ 
  58. public function testCreateServiceOAuth1NonRegistered() 
  59. $factory = new ServiceFactory(); 
  60.  
  61. $service = $factory->createService( 
  62. 'twitter',  
  63. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  64. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  65. ); 
  66.  
  67. $this->assertInstanceOf('\\OAuth\\OAuth1\\Service\\Twitter', $service); 
  68.  
  69. /** 
  70. * @covers OAuth\ServiceFactory::registerService 
  71. * @covers OAuth\ServiceFactory::createService 
  72. * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName 
  73. * @covers OAuth\ServiceFactory::buildV1Service 
  74. */ 
  75. public function testCreateServiceOAuth1Registered() 
  76. $factory = new ServiceFactory(); 
  77.  
  78. $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth1\\Service\\Fake'); 
  79.  
  80. $service = $factory->createService( 
  81. 'foo',  
  82. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  83. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  84. ); 
  85.  
  86. $this->assertInstanceOf('\\OAuth\OAuth1\Service\\ServiceInterface', $service); 
  87. $this->assertInstanceOf('\\OAuthTest\\Mocks\\OAuth1\\Service\\Fake', $service); 
  88.  
  89. /** 
  90. * @covers OAuth\ServiceFactory::registerService 
  91. * @covers OAuth\ServiceFactory::createService 
  92. * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName 
  93. * @covers OAuth\ServiceFactory::buildV1Service 
  94. */ 
  95. public function testCreateServiceOAuth1RegisteredAndNonRegisteredSameName() 
  96. $factory = new ServiceFactory(); 
  97.  
  98. $factory->registerService('twitter', '\\OAuthTest\\Mocks\\OAuth1\\Service\\Fake'); 
  99.  
  100. $service = $factory->createService( 
  101. 'twitter',  
  102. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  103. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  104. ); 
  105.  
  106. $this->assertInstanceOf('\\OAuth\OAuth1\Service\\ServiceInterface', $service); 
  107. $this->assertInstanceOf('\\OAuthTest\\Mocks\\OAuth1\\Service\\Fake', $service); 
  108.  
  109. /** 
  110. * @covers OAuth\ServiceFactory::createService 
  111. * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName 
  112. * @covers OAuth\ServiceFactory::buildV2Service 
  113. * @covers OAuth\ServiceFactory::resolveScopes 
  114. */ 
  115. public function testCreateServiceOAuth2NonRegistered() 
  116. $factory = new ServiceFactory(); 
  117.  
  118. $service = $factory->createService( 
  119. 'facebook',  
  120. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  121. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  122. ); 
  123.  
  124. $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\Facebook', $service); 
  125.  
  126. /** 
  127. * @covers OAuth\ServiceFactory::createService 
  128. * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName 
  129. * @covers OAuth\ServiceFactory::buildV2Service 
  130. * @covers OAuth\ServiceFactory::resolveScopes 
  131. */ 
  132. public function testCreateServiceOAuth2Registered() 
  133. $factory = new ServiceFactory(); 
  134.  
  135. $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake'); 
  136.  
  137. $service = $factory->createService( 
  138. 'foo',  
  139. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  140. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  141. ); 
  142.  
  143. $this->assertInstanceOf('\\OAuth\OAuth2\Service\\ServiceInterface', $service); 
  144. $this->assertInstanceOf('\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake', $service); 
  145.  
  146. /** 
  147. * @covers OAuth\ServiceFactory::createService 
  148. * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName 
  149. * @covers OAuth\ServiceFactory::buildV2Service 
  150. * @covers OAuth\ServiceFactory::resolveScopes 
  151. */ 
  152. public function testCreateServiceOAuth2RegisteredAndNonRegisteredSameName() 
  153. $factory = new ServiceFactory(); 
  154.  
  155. $factory->registerService('facebook', '\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake'); 
  156.  
  157. $service = $factory->createService( 
  158. 'facebook',  
  159. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  160. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  161. ); 
  162.  
  163. $this->assertInstanceOf('\\OAuth\OAuth2\Service\\ServiceInterface', $service); 
  164. $this->assertInstanceOf('\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake', $service); 
  165.  
  166. /** 
  167. * @covers OAuth\ServiceFactory::registerService 
  168. * @covers OAuth\ServiceFactory::createService 
  169. * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName 
  170. * @covers OAuth\ServiceFactory::buildV1Service 
  171. */ 
  172. public function testCreateServiceThrowsExceptionOnPassingScopesToV1Service() 
  173. $this->setExpectedException('\\OAuth\Common\Exception\Exception'); 
  174.  
  175. $factory = new ServiceFactory(); 
  176.  
  177. $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth1\\Service\\Fake'); 
  178.  
  179. $service = $factory->createService( 
  180. 'foo',  
  181. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  182. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  183. array('bar') 
  184. ); 
  185.  
  186. /** 
  187. * @covers OAuth\ServiceFactory::createService 
  188. * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName 
  189. */ 
  190. public function testCreateServiceNonExistentService() 
  191. $factory = new ServiceFactory(); 
  192.  
  193. $service = $factory->createService( 
  194. 'foo',  
  195. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  196. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  197. ); 
  198.  
  199. $this->assertNull($service); 
  200.  
  201. /** 
  202. * @covers OAuth\ServiceFactory::registerService 
  203. * @covers OAuth\ServiceFactory::createService 
  204. * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName 
  205. * @covers OAuth\ServiceFactory::buildV2Service 
  206. * @covers OAuth\ServiceFactory::resolveScopes 
  207. */ 
  208. public function testCreateServicePrefersOauth2() 
  209. $factory = new ServiceFactory(); 
  210.  
  211. $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth1\\Service\\Fake'); 
  212. $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake'); 
  213.  
  214. $service = $factory->createService( 
  215. 'foo',  
  216. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  217. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') 
  218. ); 
  219.  
  220. $this->assertInstanceOf('\\OAuth\OAuth2\Service\\ServiceInterface', $service); 
  221. $this->assertInstanceOf('\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake', $service); 
  222.  
  223. /** 
  224. * @covers OAuth\ServiceFactory::createService 
  225. * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName 
  226. * @covers OAuth\ServiceFactory::buildV2Service 
  227. * @covers OAuth\ServiceFactory::resolveScopes 
  228. */ 
  229. public function testCreateServiceOAuth2RegisteredWithClassConstantsAsScope() 
  230. $factory = new ServiceFactory(); 
  231.  
  232. $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake'); 
  233.  
  234. $service = $factory->createService( 
  235. 'foo',  
  236. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  237. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  238. array('FOO') 
  239. ); 
  240.  
  241. $this->assertInstanceOf('\\OAuth\OAuth2\Service\\ServiceInterface', $service); 
  242. $this->assertInstanceOf('\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake', $service); 
  243.  
  244. /** 
  245. * @covers OAuth\ServiceFactory::createService 
  246. * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName 
  247. * @covers OAuth\ServiceFactory::buildV2Service 
  248. * @covers OAuth\ServiceFactory::resolveScopes 
  249. */ 
  250. public function testCreateServiceOAuth2RegisteredWithCustomScope() 
  251. $factory = new ServiceFactory(); 
  252.  
  253. $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake'); 
  254.  
  255. $service = $factory->createService( 
  256. 'foo',  
  257. $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'),  
  258. $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'),  
  259. array('custom') 
  260. ); 
  261.  
  262. $this->assertInstanceOf('\\OAuth\OAuth2\Service\\ServiceInterface', $service); 
  263. $this->assertInstanceOf('\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake', $service);