OAuthTestUnitCommonHttpUriUriFactoryTest

The Gravity Forms Salesforce Add-On OAuthTest Unit Common Http Uri UriFactoryTest class.

Defined (1)

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

/lib/PHPoAuthLib/tests/Unit/Common/Http/Uri/UriFactoryTest.php  
  1. class UriFactoryTest extends \PHPUnit_Framework_TestCase 
  2. /** 
  3. */ 
  4. public function testConstructCorrectInterface() 
  5. $factory = new UriFactory(); 
  6.  
  7. $this->assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriFactoryInterface', $factory); 
  8.  
  9. /** 
  10. * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray 
  11. * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse 
  12. */ 
  13. public function testCreateFromSuperGlobalArrayUsingProxyStyle() 
  14. $factory = new UriFactory(); 
  15.  
  16. $uri = $factory->createFromSuperGlobalArray(array('REQUEST_URI' => 'http://example.com')); 
  17.  
  18. $this->assertInstanceOf( 
  19. '\\OAuth\\Common\\Http\\Uri\\UriInterface',  
  20. $uri 
  21. ); 
  22.  
  23. $this->assertSame('http://example.com', $uri->getAbsoluteUri()); 
  24.  
  25. /** 
  26. * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray 
  27. * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse 
  28. * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme 
  29. * @covers OAuth\Common\Http\Uri\UriFactory::detectHost 
  30. * @covers OAuth\Common\Http\Uri\UriFactory::detectPort 
  31. * @covers OAuth\Common\Http\Uri\UriFactory::detectPath 
  32. * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery 
  33. * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts 
  34. */ 
  35. public function testCreateFromSuperGlobalArrayHttp() 
  36. $factory = new UriFactory(); 
  37.  
  38. $uri = $factory->createFromSuperGlobalArray(array( 
  39. 'HTTPS' => 'off',  
  40. 'HTTP_HOST' => 'example.com',  
  41. 'REQUEST_URI' => '/foo',  
  42. 'QUERY_STRING' => 'param1=value1',  
  43. )); 
  44.  
  45. $this->assertInstanceOf( 
  46. '\\OAuth\\Common\\Http\\Uri\\UriInterface',  
  47. $uri 
  48. ); 
  49.  
  50. $this->assertSame('http://example.com/foo?param1=value1', $uri->getAbsoluteUri()); 
  51.  
  52. /** 
  53. * This looks wonky David. Should the port really fallback to 80 even when supplying https as scheme? 
  54. * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray 
  55. * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse 
  56. * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme 
  57. * @covers OAuth\Common\Http\Uri\UriFactory::detectHost 
  58. * @covers OAuth\Common\Http\Uri\UriFactory::detectPort 
  59. * @covers OAuth\Common\Http\Uri\UriFactory::detectPath 
  60. * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery 
  61. * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts 
  62. */ 
  63. public function testCreateFromSuperGlobalArrayHttps() 
  64. $factory = new UriFactory(); 
  65.  
  66. $uri = $factory->createFromSuperGlobalArray(array( 
  67. 'HTTPS' => 'on',  
  68. 'HTTP_HOST' => 'example.com',  
  69. 'REQUEST_URI' => '/foo',  
  70. 'QUERY_STRING' => 'param1=value1',  
  71. )); 
  72.  
  73. $this->assertInstanceOf( 
  74. '\\OAuth\\Common\\Http\\Uri\\UriInterface',  
  75. $uri 
  76. ); 
  77.  
  78. $this->assertSame('https://example.com:80/foo?param1=value1', $uri->getAbsoluteUri()); 
  79.  
  80. /** 
  81. * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray 
  82. * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse 
  83. * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme 
  84. * @covers OAuth\Common\Http\Uri\UriFactory::detectHost 
  85. * @covers OAuth\Common\Http\Uri\UriFactory::detectPort 
  86. * @covers OAuth\Common\Http\Uri\UriFactory::detectPath 
  87. * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery 
  88. * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts 
  89. */ 
  90. public function testCreateFromSuperGlobalArrayPortSupplied() 
  91. $factory = new UriFactory(); 
  92.  
  93. $uri = $factory->createFromSuperGlobalArray(array( 
  94. 'HTTP_HOST' => 'example.com',  
  95. 'SERVER_PORT' => 21,  
  96. 'REQUEST_URI' => '/foo',  
  97. 'QUERY_STRING' => 'param1=value1',  
  98. )); 
  99.  
  100. $this->assertInstanceOf( 
  101. '\\OAuth\\Common\\Http\\Uri\\UriInterface',  
  102. $uri 
  103. ); 
  104.  
  105. $this->assertSame('http://example.com:21/foo?param1=value1', $uri->getAbsoluteUri()); 
  106.  
  107. /** 
  108. * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray 
  109. * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse 
  110. * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme 
  111. * @covers OAuth\Common\Http\Uri\UriFactory::detectHost 
  112. * @covers OAuth\Common\Http\Uri\UriFactory::detectPort 
  113. * @covers OAuth\Common\Http\Uri\UriFactory::detectPath 
  114. * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery 
  115. * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts 
  116. */ 
  117. public function testCreateFromSuperGlobalArrayPortNotSet() 
  118. $factory = new UriFactory(); 
  119.  
  120. $uri = $factory->createFromSuperGlobalArray(array( 
  121. 'HTTP_HOST' => 'example.com',  
  122. 'REQUEST_URI' => '/foo',  
  123. 'QUERY_STRING' => 'param1=value1',  
  124. )); 
  125.  
  126. $this->assertInstanceOf( 
  127. '\\OAuth\\Common\\Http\\Uri\\UriInterface',  
  128. $uri 
  129. ); 
  130.  
  131. $this->assertSame('http://example.com/foo?param1=value1', $uri->getAbsoluteUri()); 
  132.  
  133. /** 
  134. * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray 
  135. * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse 
  136. * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme 
  137. * @covers OAuth\Common\Http\Uri\UriFactory::detectHost 
  138. * @covers OAuth\Common\Http\Uri\UriFactory::detectPort 
  139. * @covers OAuth\Common\Http\Uri\UriFactory::detectPath 
  140. * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery 
  141. * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts 
  142. */ 
  143. public function testCreateFromSuperGlobalArrayRequestUriSet() 
  144. $factory = new UriFactory(); 
  145.  
  146. $uri = $factory->createFromSuperGlobalArray(array( 
  147. 'HTTP_HOST' => 'example.com',  
  148. 'REQUEST_URI' => '/foo',  
  149. 'QUERY_STRING' => 'param1=value1',  
  150. )); 
  151.  
  152. $this->assertInstanceOf( 
  153. '\\OAuth\\Common\\Http\\Uri\\UriInterface',  
  154. $uri 
  155. ); 
  156.  
  157. $this->assertSame('http://example.com/foo?param1=value1', $uri->getAbsoluteUri()); 
  158.  
  159. /** 
  160. * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray 
  161. * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse 
  162. * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme 
  163. * @covers OAuth\Common\Http\Uri\UriFactory::detectHost 
  164. * @covers OAuth\Common\Http\Uri\UriFactory::detectPort 
  165. * @covers OAuth\Common\Http\Uri\UriFactory::detectPath 
  166. * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery 
  167. * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts 
  168. */ 
  169. public function testCreateFromSuperGlobalArrayRedirectUrlSet() 
  170. $factory = new UriFactory(); 
  171.  
  172. $uri = $factory->createFromSuperGlobalArray(array( 
  173. 'HTTP_HOST' => 'example.com',  
  174. 'REDIRECT_URL' => '/foo',  
  175. 'QUERY_STRING' => 'param1=value1',  
  176. )); 
  177.  
  178. $this->assertInstanceOf( 
  179. '\\OAuth\\Common\\Http\\Uri\\UriInterface',  
  180. $uri 
  181. ); 
  182.  
  183. $this->assertSame('http://example.com/foo?param1=value1', $uri->getAbsoluteUri()); 
  184.  
  185. /** 
  186. * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray 
  187. * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse 
  188. * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme 
  189. * @covers OAuth\Common\Http\Uri\UriFactory::detectHost 
  190. * @covers OAuth\Common\Http\Uri\UriFactory::detectPort 
  191. * @covers OAuth\Common\Http\Uri\UriFactory::detectPath 
  192. * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery 
  193. * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts 
  194. */ 
  195. public function testCreateFromSuperGlobalArrayThrowsExceptionOnDetectingPathMissingIndices() 
  196. $factory = new UriFactory(); 
  197.  
  198. $this->setExpectedException('\\RuntimeException'); 
  199.  
  200. $uri = $factory->createFromSuperGlobalArray(array( 
  201. 'HTTP_HOST' => 'example.com',  
  202. 'QUERY_STRING' => 'param1=value1',  
  203. )); 
  204.  
  205. /** 
  206. * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray 
  207. * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse 
  208. * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme 
  209. * @covers OAuth\Common\Http\Uri\UriFactory::detectHost 
  210. * @covers OAuth\Common\Http\Uri\UriFactory::detectPort 
  211. * @covers OAuth\Common\Http\Uri\UriFactory::detectPath 
  212. * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery 
  213. * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts 
  214. */ 
  215. public function testCreateFromSuperGlobalArrayWithQueryString() 
  216. $factory = new UriFactory(); 
  217.  
  218. $uri = $factory->createFromSuperGlobalArray(array( 
  219. 'HTTP_HOST' => 'example.com',  
  220. 'REQUEST_URI' => '/foo?param1=value1',  
  221. 'QUERY_STRING' => 'param1=value1',  
  222. )); 
  223.  
  224. $this->assertInstanceOf( 
  225. '\\OAuth\\Common\\Http\\Uri\\UriInterface',  
  226. $uri 
  227. ); 
  228.  
  229. $this->assertSame('http://example.com/foo?param1=value1', $uri->getAbsoluteUri()); 
  230.  
  231. /** 
  232. * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray 
  233. * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse 
  234. * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme 
  235. * @covers OAuth\Common\Http\Uri\UriFactory::detectHost 
  236. * @covers OAuth\Common\Http\Uri\UriFactory::detectPort 
  237. * @covers OAuth\Common\Http\Uri\UriFactory::detectPath 
  238. * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery 
  239. * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts 
  240. */ 
  241. public function testCreateFromSuperGlobalArrayWithoutQueryString() 
  242. $factory = new UriFactory(); 
  243.  
  244. $uri = $factory->createFromSuperGlobalArray(array( 
  245. 'HTTP_HOST' => 'example.com',  
  246. 'REQUEST_URI' => '/foo',  
  247. )); 
  248.  
  249. $this->assertInstanceOf( 
  250. '\\OAuth\\Common\\Http\\Uri\\UriInterface',  
  251. $uri 
  252. ); 
  253.  
  254. $this->assertSame('http://example.com/foo', $uri->getAbsoluteUri()); 
  255.  
  256. /** 
  257. * @covers OAuth\Common\Http\Uri\UriFactory::createFromSuperGlobalArray 
  258. * @covers OAuth\Common\Http\Uri\UriFactory::attemptProxyStyleParse 
  259. * @covers OAuth\Common\Http\Uri\UriFactory::detectScheme 
  260. * @covers OAuth\Common\Http\Uri\UriFactory::detectHost 
  261. * @covers OAuth\Common\Http\Uri\UriFactory::detectPort 
  262. * @covers OAuth\Common\Http\Uri\UriFactory::detectPath 
  263. * @covers OAuth\Common\Http\Uri\UriFactory::detectQuery 
  264. * @covers OAuth\Common\Http\Uri\UriFactory::createFromParts 
  265. */ 
  266. public function testCreateFromSuperGlobalArrayHostWithColon() 
  267. $factory = new UriFactory(); 
  268.  
  269. $uri = $factory->createFromSuperGlobalArray(array( 
  270. 'HTTP_HOST' => 'example.com:80',  
  271. 'REQUEST_URI' => '/foo',  
  272. )); 
  273.  
  274. $this->assertInstanceOf( 
  275. '\\OAuth\\Common\\Http\\Uri\\UriInterface',  
  276. $uri 
  277. ); 
  278.  
  279. $this->assertSame('http://example.com/foo', $uri->getAbsoluteUri()); 
  280.  
  281. /** 
  282. * @covers OAuth\Common\Http\Uri\UriFactory::createFromAbsolute 
  283. */ 
  284. public function testCreateFromAbsolute() 
  285. $factory = new UriFactory(); 
  286.  
  287. $uri = $factory->createFromAbsolute('http://example.com'); 
  288.  
  289. $this->assertInstanceOf( 
  290. '\\OAuth\\Common\\Http\\Uri\\UriInterface',  
  291. $uri 
  292. ); 
  293.  
  294. $this->assertSame('http://example.com', $uri->getAbsoluteUri());